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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcAppSidebarTab :id="id"
ref="tab"
:name="name"
:icon="icon"
@bottomReached="onScrollBottomReached">
<template #icon>
<slot name="icon" />
</template>
<!-- Fallback loading -->
<NcEmptyContent v-if="loading" icon="icon-loading" />
<!-- Using a dummy div as Vue mount replace the element directly
It does NOT append to the content -->
<div ref="mount" />
</NcAppSidebarTab>
</template>
<script>
import NcAppSidebarTab from '@nextcloud/vue/dist/Components/NcAppSidebarTab.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
export default {
name: 'SidebarTab',
components: {
NcAppSidebarTab,
NcEmptyContent,
},
props: {
fileInfo: {
type: Object,
default: () => {},
required: true,
},
id: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
icon: {
type: String,
required: false,
},
/**
* Lifecycle methods.
* They are prefixed with `on` to avoid conflict with Vue
* methods like this.destroy
*/
onMount: {
type: Function,
required: true,
},
onUpdate: {
type: Function,
required: true,
},
onDestroy: {
type: Function,
required: true,
},
onScrollBottomReached: {
type: Function,
default: () => {},
},
},
data() {
return {
loading: true,
}
},
computed: {
// TODO: implement a better way to force pass a prop from Sidebar
activeTab() {
return this.$parent.activeTab
},
},
watch: {
async fileInfo(newFile, oldFile) {
// Update fileInfo on change
if (newFile.id !== oldFile.id) {
this.loading = true
await this.onUpdate(this.fileInfo)
this.loading = false
}
},
},
async mounted() {
this.loading = true
// Mount the tab: mounting point, fileInfo, vue context
await this.onMount(this.$refs.mount, this.fileInfo, this.$refs.tab)
this.loading = false
},
async beforeDestroy() {
// unmount the tab
await this.onDestroy()
},
}
</script>
|