summaryrefslogtreecommitdiffstats
path: root/src/views/PlaceContent.vue
blob: 01826a32306ea8e778f1d907635b0cdfa6518a87 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!--
  - SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
	<div>
		<CollectionContent ref="collectionContent"
			:collection="place"
			:collection-file-ids="placeFileIds"
			:allow-selection="false"
			:loading="loadingCollection || loadingCollectionFiles"
			:error="errorFetchingCollection || errorFetchingCollectionFiles">
			<!-- Header -->
			<HeaderNavigation v-if="place !== null"
				key="navigation"
				slot="header"
				:loading="loadingCollection || loadingCollectionFiles"
				:params="{ placeName }"
				:path="'/' + placeName"
				:title="place.basename"
				@refresh="fetchPlaceFiles" />

			<!-- No content -->
			<NcEmptyContent slot="empty-content"
				:name="t('photos', 'This place does not have any photos or videos yet!')"
				class="place__empty">
				<ImagePlus slot="icon" />

				<NcButton slot="action"
					type="primary"
					:aria-label="t('photos', 'Add photos to this place')"
					@click="showAddPhotosModal = true">
					<Plus slot="icon" />
					{{ t('photos', "Add") }}
				</NcButton>
			</NcEmptyContent>
		</CollectionContent>
	</div>
</template>

<script>
import Plus from 'vue-material-design-icons/Plus.vue'
import ImagePlus from 'vue-material-design-icons/ImagePlus.vue'

import { NcButton, NcEmptyContent, isMobile } from '@nextcloud/vue'
import { translate } from '@nextcloud/l10n'

import FetchCollectionContentMixin from '../mixins/FetchCollectionContentMixin.js'
import CollectionContent from '../components/Collection/CollectionContent.vue'
import HeaderNavigation from '../components/HeaderNavigation.vue'
import { getCurrentUser } from '@nextcloud/auth'

export default {
	name: 'PlaceContent',
	components: {
		Plus,
		ImagePlus,
		NcEmptyContent,
		NcButton,
		CollectionContent,
		HeaderNavigation,
	},

	mixins: [
		FetchCollectionContentMixin,
		isMobile,
	],

	props: {
		placeName: {
			type: String,
			default: '/',
		},
	},

	data() {
		return {
			showAddPhotosModal: false,
			loadingCollection: false,
			errorFetchingCollection: null,
			loadingCount: 0,
			loadingAddFilesToPlace: false,
		}
	},

	computed: {
		/**
		 * @return {import('../services/collectionFetcher.js').Collection} The place information for the current placeName.
		 */
		place() {
			return this.$store.getters.getPlace(this.placeName)
		},

		/**
		 * @return {string} The place's filename based on its name. Useful to fetch the place information and content.
		 */
		placeFileName() {
			return `/photos/${getCurrentUser()?.uid}/places/${this.placeName}`
		},

		/**
		 * @return {string[]} The list of files for the current placeName.
		 */
		placeFileIds() {
			return this.$store.getters.getPlaceFiles(this.placeName)
		},
	},

	async beforeMount() {
		await this.fetchPlace()
		await this.fetchPlaceFiles()
	},

	methods: {
		async fetchPlace() {
			this.fetchCollection(this.placeFileName)
		},

		async fetchPlaceFiles() {
			this.fetchCollectionFiles(this.placeFileName)
		},

		t: translate,
	},
}
</script>
<style lang="scss" scoped>
.place {
	display: flex;
	flex-direction: column;

	&__title {
		width: 100%;
	}

	&__name {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	&__place {
		margin-left: -4px;
		display: flex;
		color: var(--color-text-lighter);
	}
}
</style>