-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathFilesSidebarTab.vue
More file actions
91 lines (80 loc) · 2.29 KB
/
Copy pathFilesSidebarTab.vue
File metadata and controls
91 lines (80 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<script setup lang="ts">
import type { ISidebarTab } from '@nextcloud/files'
import { NcIconSvgWrapper, NcLoadingIcon } from '@nextcloud/vue'
import { computed, ref, toRef, watch } from 'vue'
import NcAppSidebarTab from '@nextcloud/vue/components/NcAppSidebarTab'
import NcEmptyContent from '@nextcloud/vue/components/NcEmptyContent'
import logger from '../../logger.ts'
import { useSidebarStore } from '../../store/sidebar.ts'
const props = defineProps<{
/**
* If this is the currently active tab
*/
active: boolean
/**
* The sidebar tab definition.
*/
tab: ISidebarTab
}>()
const sidebar = useSidebarStore()
const context = computed(() => {
if (!sidebar.currentContext) {
return undefined
}
return {
folder: sidebar.currentContext.folder.clone(),
node: sidebar.currentContext.node.clone(),
view: sidebar.currentContext.view,
}
})
const loading = ref(true)
watch(toRef(props, 'active'), async (active) => {
if (!active) {
return
}
logger.debug('sidebar: activating files sidebar tab ' + props.tab.id, { tab: props.tab })
loading.value = true
try {
if (!initializedTabs.has(props.tab.tagName)) {
initializedTabs.add(props.tab.tagName)
logger.debug('sidebar: initializing ' + props.tab.id)
await props.tab.onInit?.()
}
logger.debug('sidebar: waiting for sidebar tab component becoming defined ' + props.tab.id)
await window.customElements.whenDefined(props.tab.tagName)
logger.debug('sidebar: tab component defined and loaded ' + props.tab.id)
loading.value = false
} catch (error) {
logger.error('Failed to get sidebar tab web component', { error })
}
}, { immediate: true })
</script>
<script lang="ts">
const initializedTabs = new Set<string>()
</script>
<template>
<NcAppSidebarTab
:id="tab.id"
:order="tab.order"
:name="tab.displayName">
<template #icon>
<NcIconSvgWrapper :svg="tab.iconSvgInline" />
</template>
<NcEmptyContent v-if="loading || !context">
<template #icon>
<NcLoadingIcon />
</template>
</NcEmptyContent>
<component
:is="tab.tagName"
v-else
:active.prop="active"
:node.prop="context.node"
:folder.prop="context.folder"
:view.prop="context.view" />
</NcAppSidebarTab>
</template>