|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 |
|
6 | | -import type { App, Component, ComponentPublicInstance } from 'vue' |
7 | | -import type { ActivityTabType } from './views/ActivityTab.vue' |
8 | | - |
9 | 6 | import LightningBolt from '@mdi/svg/svg/lightning-bolt.svg?raw' |
10 | | -import { translate as t } from '@nextcloud/l10n' |
11 | | -import { createApp } from 'vue' |
| 7 | +import { registerSidebarTab } from '@nextcloud/files' |
| 8 | +import { t } from '@nextcloud/l10n' |
| 9 | +import { defineAsyncComponent, defineCustomElement } from 'vue' |
12 | 10 |
|
13 | | -// Init Activity tab component |
14 | | -let LazyActivityTab: Component | null = null |
15 | | -let activityTabApp: App<Element> | null = null |
16 | | -let activityTabInstance: ComponentPublicInstance<ActivityTabType> | null = null |
| 11 | +window.customElements.define( |
| 12 | + 'activity-files-sidebar-tab', |
| 13 | + defineCustomElement(defineAsyncComponent(() => import('./views/ActivityTab.vue'))), |
| 14 | +) |
17 | 15 |
|
18 | | -const activityTab = new OCA.Files.Sidebar.Tab({ |
| 16 | +registerSidebarTab({ |
19 | 17 | id: 'activity', |
20 | | - name: t('activity', 'Activity'), |
21 | | - iconSvg: LightningBolt, |
22 | | - |
23 | | - async mount(el, fileInfo) { |
24 | | - // only load if needed |
25 | | - if (LazyActivityTab === null) { |
26 | | - const { default: ActivityTab } = await import('./views/ActivityTab.vue') |
27 | | - LazyActivityTab = ActivityTab |
28 | | - } |
29 | | - // destroy previous instance if available |
30 | | - if (activityTabApp) { |
31 | | - activityTabApp.unmount() |
32 | | - } |
33 | | - activityTabApp = createApp(LazyActivityTab) |
34 | | - // No need to await this, we will show a loading indicator instead |
35 | | - activityTabInstance = activityTabApp.mount(el) |
36 | | - activityTabInstance.update(fileInfo) |
37 | | - }, |
38 | | - update(fileInfo) { |
39 | | - activityTabInstance!.update(fileInfo) |
| 18 | + order: 50, |
| 19 | + displayName: t('activity', 'Activity'), |
| 20 | + iconSvgInline: LightningBolt, |
| 21 | + tagName: 'activity-files-sidebar-tab', |
| 22 | + enabled() { |
| 23 | + return true |
40 | 24 | }, |
41 | | - destroy() { |
42 | | - activityTabApp?.unmount() |
43 | | - activityTabApp = null |
44 | | - }, |
45 | | -}) |
46 | | - |
47 | | -window.addEventListener('DOMContentLoaded', async function() { |
48 | | - if (OCA.Files && OCA.Files.Sidebar) { |
49 | | - OCA.Files.Sidebar.registerTab(activityTab) |
50 | | - const { default: ActivityTab } = await import('./views/ActivityTab.vue') |
51 | | - LazyActivityTab = ActivityTab |
52 | | - } |
53 | 25 | }) |
0 commit comments