Skip to content

Commit

Permalink
Vue 3: Port to @vueuse/head (and get rid of vue-meta) (#8221)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschmidt authored Jan 12, 2023
1 parent 213894e commit 6a054fc
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 73 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/change-update-vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ https://github.com/owncloud/web/pull/8202
https://github.com/owncloud/web/pull/8198
https://github.com/owncloud/web/pull/8213
https://github.com/owncloud/web/pull/8214
https://github.com/owncloud/web/pull/8221
2 changes: 1 addition & 1 deletion packages/web-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@uppy/tus": "^3.0.1",
"@uppy/utils": "^5.0.2",
"@uppy/xhr-upload": "^3.0.1",
"@vueuse/head": "1.0.22",
"axios": "^0.27.2",
"easygettext": "https://github.com/owncloud/easygettext/archive/refs/tags/v2.18.1-oc.tar.gz",
"filesize": "^9.0.11",
Expand Down Expand Up @@ -42,7 +43,6 @@
"vue-concurrency": "4.0.0",
"vue-gettext": "2.1.12",
"vue-inline-svg": "3.1.0",
"vue-meta": "^2.2.2",
"vue-router": "3.6.5",
"vue-select": "4.0.0-beta.6",
"vuex": "4.1.0",
Expand Down
25 changes: 6 additions & 19 deletions packages/web-runtime/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ import SkipTo from './components/SkipTo.vue'
import LayoutApplication from './layouts/Application.vue'
import LayoutLoading from './layouts/Loading.vue'
import LayoutPlain from './layouts/Plain.vue'
import { getBackendVersion, getWebVersion } from './container/versions'
import { defineComponent } from 'vue'
import { isPublicLinkContext, isUserContext } from './router'
import { additionalTranslations } from './helpers/additionalTranslations' // eslint-disable-line
import { eventBus } from 'web-pkg/src/services'
import { useHead } from './composables/head'
import { useStore } from 'web-pkg/src/composables'
export default defineComponent({
components: {
SkipTo
},
setup() {
const store = useStore()
useHead({ store })
},
data() {
return {
$_notificationsInterval: null,
Expand Down Expand Up @@ -89,9 +94,6 @@ export default defineComponent({
}
return LayoutApplication
},
favicon() {
return this.configuration.currentTheme.logo.favicon
},
selectedLanguage() {
return (
Expand Down Expand Up @@ -168,21 +170,6 @@ export default defineComponent({
}
},
metaInfo() {
const metaInfo: any = {}
if (this.favicon) {
metaInfo.link = [{ rel: 'icon', href: this.favicon }]
}
const metaGenerator = {
name: 'generator',
content: [getWebVersion(), getBackendVersion({ store: this.$store })]
.filter(Boolean)
.join(', ')
}
metaInfo.meta = [metaGenerator]
return metaInfo
},
methods: {
...mapActions(['fetchNotifications']),
Expand Down
1 change: 1 addition & 0 deletions packages/web-runtime/src/composables/head/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useHead'
21 changes: 21 additions & 0 deletions packages/web-runtime/src/composables/head/useHead.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { computed } from 'vue'
import { Store } from 'vuex'
import { useHead as _useHead } from '@vueuse/head'
import { getBackendVersion, getWebVersion } from 'web-runtime/src/container/versions'

export const useHead = ({ store }: { store: Store<any> }) => {
_useHead(
computed(() => {
const favicon = store.getters['configuration']?.currentTheme?.logo?.favicon
return {
meta: [
{
name: 'generator',
content: [getWebVersion(), getBackendVersion({ store })].filter(Boolean).join(', ')
}
],
...(favicon && { link: [{ rel: 'icon', href: favicon }] })
}
})
)
}
4 changes: 0 additions & 4 deletions packages/web-runtime/src/defaults/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import WebPlugin from '../plugins/web'
import Avatar from '../components/Avatar.vue'
import focusMixin from '../mixins/focusMixin'
import lifecycleMixin from '../mixins/lifecycleMixin'
import VueMeta from 'vue-meta'
import VueRouter from 'vue-router'
import Vuex from 'vuex'

Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(WebPlugin)
Vue.use(VueMeta, {
refreshOnceOnNavigation: true
})

Vue.component('AvatarImage', Avatar)

Expand Down
6 changes: 6 additions & 0 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

import { router } from './router'
import { configurationManager } from 'web-pkg/src/configuration'
import { createHead } from '@vueuse/head'

import {
announceConfiguration,
Expand Down Expand Up @@ -82,6 +83,9 @@ export const renderSuccess = (): void => {
wormhole: instance.config.globalProperties.$wormhole
})

// @vueuse/head
instance.use(createHead())

// mount App
instance.mount('#owncloud')
applications.forEach((application) => application.mounted(instance))
Expand Down Expand Up @@ -200,6 +204,8 @@ export const renderSuccess = (): void => {
}

export const renderFailure = async (err: Error): Promise<void> => {
Vue.prototype.$store = store

announceVersions({ store })
await announceTranslations({ vue: Vue, supportedLanguages, translations })
await announceTheme({ store, vue: Vue, designSystem })
Expand Down
25 changes: 4 additions & 21 deletions packages/web-runtime/src/pages/missingOrInvalidConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</template>

<script lang="ts">
import { getBackendVersion, getWebVersion } from '../container/versions'
import { computed, defineComponent } from 'vue'
import { useStore } from 'web-pkg'
import { useHead } from '../composables/head'
export default defineComponent({
name: 'MissingConfigPage',
Expand All @@ -36,30 +36,13 @@ export default defineComponent({
const footerSlogan = computed(() => {
return store.getters.configuration?.currentTheme?.general?.slogan
})
const favicon = computed(() => {
return store.getters.configuration?.currentTheme?.logo?.favicon
})
useHead({ store })
return {
logoImg,
footerSlogan,
favicon
}
},
metaInfo() {
const metaInfo: any = {}
if (this.favicon) {
metaInfo.link = [{ rel: 'icon', href: this.favicon }]
}
const metaGenerator = {
name: 'generator',
content: [getWebVersion(), getBackendVersion({ store: this.$store })]
.filter(Boolean)
.join(', ')
footerSlogan
}
metaInfo.meta = [metaGenerator]
return metaInfo
}
})
</script>
85 changes: 57 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a054fc

Please sign in to comment.