-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathTagCover.vue
More file actions
188 lines (161 loc) · 3.73 KB
/
TagCover.vue
File metadata and controls
188 lines (161 loc) · 3.73 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!--
- @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
-
- @author John Molakvoæ <skjnldsv@protonmail.com>
- @author Corentin Mors <medias@pixelswap.fr>
- @author Marcel Klehr <mklehr@gmx.net>
-
- @license AGPL-3.0-or-later
-
- 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>
<router-link class="tag-cover" :to="`/tags/${tag.displayName}`">
<img v-if="tag.filesAssigned !== 0"
class="tag-cover__image"
:src="coverUrl">
<div v-else class="tag-cover__image tag-cover__image--placeholder">
<ImageMultipleIcon :size="128" />
</div>
<div class="tag-cover__details">
<div class="tag-cover__details__first-line">
<h3 class="tag-cover__details__name">
{{ t('recognize', tag.displayName) }}
</h3>
</div>
<div class="tag-cover__details__second-line">
{{ n('photos', '%n photo', '%n photos', count) }}
</div>
</div>
</router-link>
</template>
<script>
import { mapGetters } from 'vuex'
import ImageMultipleIcon from 'vue-material-design-icons/ImageMultiple.vue'
import { generateUrl } from '@nextcloud/router'
import AbortControllerMixin from '../mixins/AbortControllerMixin.js'
export default {
name: 'TagCover',
components: {
ImageMultipleIcon,
},
mixins: [
AbortControllerMixin,
],
props: {
tag: {
type: Object,
required: true,
},
},
data() {
return {
loadCover: false,
observer: null,
}
},
computed: {
// global lists
...mapGetters([
'files',
'tags',
]),
/**
* @return {string}
*/
coverUrl() {
if (!this.loadCover) {
return ''
}
return generateUrl(`/core/preview?fileId=${this.tag.referenceFileid}&x=${512}&y=${512}&forceIcon=0&a=1`)
},
count() {
return this.tag.filesAssigned
},
},
watch: {
loadCover() {
if (this.tag.filesAssigned) {
return
}
this.$store.dispatch('fetchTagFiles', { id: this.tag.id, signal: this.abortController.signal })
},
},
mounted() {
this.observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
this.loadCover = true
this.observer.disconnect()
}
})
this.observer.observe(this.$el)
},
}
</script>
<style scoped lang="scss">
.tag-cover {
display: flex;
flex-direction: column;
padding: 16px;
border-radius: 12px;
&:hover, &:focus {
background: var(--color-background-dark);
}
&__image {
width: 350px;
height: 350px;
object-fit: cover;
border-radius: 12px;
@media only screen and (max-width: 1200px) {
width: 250px;
height: 250px;
}
&--placeholder {
background: var(--color-primary-light);
:deep(.material-design-icon) {
width: 100%;
height: 100%;
.material-design-icon__svg {
fill: var(--color-primary);
}
}
}
}
&__details {
display: flex;
flex-direction: column;
margin-top: 16px;
width: 350px;
@media only screen and (max-width: 1200px) {
width: 250px;
}
&__first-line {
display: flex;
}
&__second-line {
display: flex;
color: var(--color-text-lighter);
}
&__name {
flex-grow: 1;
margin: 0;
font-weight: normal;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
</style>