Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 3: Port to @vueuse/head (and get rid of vue-meta) #8221

Merged
merged 6 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this comment needed for?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in a call: just for consistency, because the other blocks also have a comment.

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.