Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SidebarTab.vue « components « src « files « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad80f91d431591acd7a9ec36e90079fc7c6a77e1 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

<!--
  - @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
  -
  - @author John Molakvoæ <skjnldsv@protonmail.com>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
  -
  -->
<template>
	<AppSidebarTab :id="id"
		ref="tab"
		:name="name"
		:icon="icon"
		@bottomReached="onScrollBottomReached">
		<!-- Fallback loading -->
		<EmptyContent 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" />
	</AppSidebarTab>
</template>

<script>
import AppSidebarTab from '@nextcloud/vue/dist/Components/AppSidebarTab'
import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent'

export default {
	name: 'SidebarTab',

	components: {
		AppSidebarTab,
		EmptyContent,
	},

	props: {
		fileInfo: {
			type: Object,
			default: () => {},
			required: true,
		},
		id: {
			type: String,
			required: true,
		},
		name: {
			type: String,
			required: true,
		},
		icon: {
			type: String,
			required: true,
		},

		/**
		 * 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>