|
41 | 41 | </header> |
42 | 42 | </template> |
43 | 43 |
|
44 | | -<script lang="ts"> |
| 44 | +<script setup lang="ts"> |
45 | 45 | import { storeToRefs } from 'pinia' |
46 | | -import { computed, unref, PropType, ref, onMounted } from 'vue' |
| 46 | +import { computed, unref, ref } from 'vue' |
47 | 47 | import ApplicationsMenu from './ApplicationsMenu.vue' |
48 | 48 | import UserMenu from './UserMenu.vue' |
49 | 49 | import Notifications from './Notifications.vue' |
50 | 50 | import FeedbackLink from './FeedbackLink.vue' |
51 | 51 | import SideBarToggle from './SideBarToggle.vue' |
52 | 52 | import { |
53 | | - ApplicationInformation, |
54 | | - AppMenuItemExtension, |
55 | 53 | CustomComponentTarget, |
56 | 54 | useAuthStore, |
57 | 55 | useCapabilityStore, |
58 | 56 | useConfigStore, |
59 | 57 | useEmbedMode, |
60 | 58 | useExtensionRegistry, |
61 | | - useOpenEmptyEditor, |
62 | 59 | useRouter, |
63 | 60 | useThemeStore |
64 | 61 | } from '@opencloud-eu/web-pkg' |
65 | 62 | import { routeNames } from '../../router/names' |
66 | 63 | import { appMenuExtensionPoint, topBarCenterExtensionPoint } from '../../extensionPoints' |
67 | 64 | import { RouteLocationNormalizedLoaded } from 'vue-router' |
| 65 | +import { useGettext } from 'vue3-gettext' |
68 | 66 |
|
69 | | -export default { |
70 | | - components: { |
71 | | - ApplicationsMenu, |
72 | | - CustomComponentTarget, |
73 | | - FeedbackLink, |
74 | | - Notifications, |
75 | | - SideBarToggle, |
76 | | - UserMenu |
77 | | - }, |
78 | | - props: { |
79 | | - applicationsList: { |
80 | | - type: Array as PropType<ApplicationInformation[]>, |
81 | | - required: false, |
82 | | - default: (): ApplicationInformation[] => [] |
83 | | - } |
84 | | - }, |
85 | | - setup(props) { |
86 | | - const capabilityStore = useCapabilityStore() |
87 | | - const themeStore = useThemeStore() |
88 | | - const { currentTheme } = storeToRefs(themeStore) |
89 | | - const configStore = useConfigStore() |
90 | | - const { options: configOptions } = storeToRefs(configStore) |
91 | | - const extensionRegistry = useExtensionRegistry() |
92 | | - const { openEmptyEditor } = useOpenEmptyEditor() |
93 | | -
|
94 | | - const authStore = useAuthStore() |
95 | | - const router = useRouter() |
96 | | - const { isEnabled: isEmbedModeEnabled } = useEmbedMode() |
| 67 | +const { $gettext } = useGettext() |
| 68 | +const capabilityStore = useCapabilityStore() |
| 69 | +const themeStore = useThemeStore() |
| 70 | +const { currentTheme } = storeToRefs(themeStore) |
| 71 | +const configStore = useConfigStore() |
| 72 | +const { options: configOptions } = storeToRefs(configStore) |
| 73 | +const extensionRegistry = useExtensionRegistry() |
97 | 74 |
|
98 | | - const appMenuExtensions = computed(() => { |
99 | | - return extensionRegistry.requestExtensions(appMenuExtensionPoint) |
100 | | - }) |
| 75 | +const authStore = useAuthStore() |
| 76 | +const router = useRouter() |
| 77 | +const { isEnabled: isEmbedModeEnabled } = useEmbedMode() |
101 | 78 |
|
102 | | - const logoWidth = ref('150px') |
103 | | - const hideLogo = computed(() => unref(configOptions).hideLogo) |
| 79 | +const appMenuExtensions = computed(() => { |
| 80 | + return extensionRegistry.requestExtensions(appMenuExtensionPoint) |
| 81 | +}) |
104 | 82 |
|
105 | | - const isNotificationBellEnabled = computed(() => { |
106 | | - return ( |
107 | | - authStore.userContextReady && capabilityStore.notificationsOcsEndpoints.includes('list') |
108 | | - ) |
109 | | - }) |
| 83 | +const hideLogo = computed(() => unref(configOptions).hideLogo) |
110 | 84 |
|
111 | | - const homeLink = computed(() => { |
112 | | - if (authStore.publicLinkContextReady && !authStore.userContextReady) { |
113 | | - return { |
114 | | - name: 'resolvePublicLink', |
115 | | - params: { token: authStore.publicLinkToken } |
116 | | - } |
117 | | - } |
| 85 | +const isNotificationBellEnabled = computed(() => { |
| 86 | + return authStore.userContextReady && capabilityStore.notificationsOcsEndpoints.includes('list') |
| 87 | +}) |
118 | 88 |
|
119 | | - return '/' |
120 | | - }) |
121 | | -
|
122 | | - const isRuntimeRoute = (route: RouteLocationNormalizedLoaded) => { |
123 | | - return Object.values(routeNames).includes(route.name.toString()) |
124 | | - } |
125 | | - const isSideBarToggleVisible = computed(() => { |
126 | | - return authStore.userContextReady || authStore.publicLinkContextReady |
127 | | - }) |
128 | | - const isSideBarToggleDisabled = computed(() => { |
129 | | - return isRuntimeRoute(unref(router.currentRoute)) |
130 | | - }) |
131 | | -
|
132 | | - const contentOnLeftPortal = ref(false) |
133 | | - const updateLeftPortal = (newContent: { hasContent: boolean; sources: string[] }) => { |
134 | | - contentOnLeftPortal.value = newContent.hasContent |
| 89 | +const homeLink = computed(() => { |
| 90 | + if (authStore.publicLinkContextReady && !authStore.userContextReady) { |
| 91 | + return { |
| 92 | + name: 'resolvePublicLink', |
| 93 | + params: { token: authStore.publicLinkToken } |
135 | 94 | } |
| 95 | + } |
136 | 96 |
|
137 | | - onMounted(() => { |
138 | | - // FIXME: backwards compatibility for the deprecated applicationMenu prop |
139 | | - const navExtensions = props.applicationsList |
140 | | - .filter((app) => app.applicationMenu?.enabled()) |
141 | | - .map((app) => ({ |
142 | | - id: app.id, |
143 | | - type: 'appMenuItem', |
144 | | - label: () => app.name, |
145 | | - path: `/${app.id}`, |
146 | | - icon: app.icon, |
147 | | - color: app.color, |
148 | | - extensionPointIds: [appMenuExtensionPoint.id], |
149 | | - priority: app.applicationMenu?.priority || 50, |
150 | | - ...((app as any).url && { url: (app as any).url, target: '_blank' }), |
151 | | - ...(app.applicationMenu?.openAsEditor && { |
152 | | - handler: () => openEmptyEditor(app.id, app.defaultExtension) |
153 | | - }) |
154 | | - })) as AppMenuItemExtension[] |
| 97 | + return '/' |
| 98 | +}) |
155 | 99 |
|
156 | | - extensionRegistry.registerExtensions(computed(() => navExtensions)) |
157 | | - }) |
| 100 | +const isRuntimeRoute = (route: RouteLocationNormalizedLoaded) => { |
| 101 | + return Object.values(routeNames).includes(route.name.toString()) |
| 102 | +} |
| 103 | +const isSideBarToggleVisible = computed(() => { |
| 104 | + return authStore.userContextReady || authStore.publicLinkContextReady |
| 105 | +}) |
| 106 | +const isSideBarToggleDisabled = computed(() => { |
| 107 | + return isRuntimeRoute(unref(router.currentRoute)) |
| 108 | +}) |
| 109 | +
|
| 110 | +const contentOnLeftPortal = ref(false) |
| 111 | +const updateLeftPortal = (newContent: { hasContent: boolean; sources: string[] }) => { |
| 112 | + contentOnLeftPortal.value = newContent.hasContent |
| 113 | +} |
158 | 114 |
|
159 | | - return { |
160 | | - configOptions, |
161 | | - contentOnLeftPortal, |
162 | | - currentTheme, |
163 | | - updateLeftPortal, |
164 | | - isNotificationBellEnabled, |
165 | | - hideLogo, |
166 | | - logoWidth, |
167 | | - isEmbedModeEnabled, |
168 | | - isSideBarToggleVisible, |
169 | | - isSideBarToggleDisabled, |
170 | | - homeLink, |
171 | | - topBarCenterExtensionPoint, |
172 | | - appMenuExtensions |
173 | | - } |
174 | | - }, |
175 | | - computed: { |
176 | | - sidebarLogoAlt() { |
177 | | - return this.$gettext('Navigate to personal files page') |
178 | | - }, |
| 115 | +const sidebarLogoAlt = computed(() => { |
| 116 | + return $gettext('Navigate to personal files page') |
| 117 | +}) |
179 | 118 |
|
180 | | - isFeedbackLinkEnabled() { |
181 | | - return !this.configOptions.disableFeedbackLink |
182 | | - }, |
| 119 | +const isFeedbackLinkEnabled = computed(() => { |
| 120 | + return !unref(configOptions).disableFeedbackLink |
| 121 | +}) |
183 | 122 |
|
184 | | - feedbackLinkOptions() { |
185 | | - const feedback = this.configOptions.feedbackLink |
186 | | - if (!this.isFeedbackLinkEnabled || !feedback) { |
187 | | - return {} |
188 | | - } |
| 123 | +const feedbackLinkOptions = computed(() => { |
| 124 | + const feedback = unref(configOptions).feedbackLink |
| 125 | + if (!unref(isFeedbackLinkEnabled) || !feedback) { |
| 126 | + return {} |
| 127 | + } |
189 | 128 |
|
190 | | - return { |
191 | | - ...(feedback.href && { href: feedback.href }), |
192 | | - ...(feedback.ariaLabel && { ariaLabel: feedback.ariaLabel }), |
193 | | - ...(feedback.description && { description: feedback.description }) |
194 | | - } |
195 | | - } |
196 | | - }, |
197 | | - async created() { |
198 | | - const image = new Image() |
199 | | - const imageDimensions = (await new Promise((resolve) => { |
200 | | - image.onload = () => { |
201 | | - resolve({ |
202 | | - height: image.height, |
203 | | - width: image.width |
204 | | - }) |
205 | | - } |
206 | | - image.src = this.currentTheme.logo |
207 | | - })) as { height: number; width: number } |
208 | | - // max-height of logo is 38px, so we calculate the width based on the ratio of the image |
209 | | - // and add 70px to account for the width of the left side of the topbar |
210 | | - this.logoWidth = `${imageDimensions.width / (imageDimensions.height / 38) + 70}px` |
| 129 | + return { |
| 130 | + ...(feedback.href && { href: feedback.href }), |
| 131 | + ...(feedback.ariaLabel && { ariaLabel: feedback.ariaLabel }), |
| 132 | + ...(feedback.description && { description: feedback.description }) |
211 | 133 | } |
212 | | -} |
| 134 | +}) |
213 | 135 | </script> |
214 | 136 | <style scoped> |
215 | 137 | @reference '@opencloud-eu/design-system/tailwind'; |
|
0 commit comments