@@ -66,6 +66,9 @@ import VTag from "~/components/VTag/VTag.vue"
66
66
import VButton from " ~/components/VButton.vue"
67
67
import VIcon from " ~/components/VIcon/VIcon.vue"
68
68
69
+ // The number of rows to display before collapsing the tags
70
+ const ROWS_TO_DISPLAY = 3
71
+
69
72
export default defineComponent ({
70
73
name: " VMediaTags" ,
71
74
components: { VIcon , VButton , VMediaTag , VTag },
@@ -84,23 +87,24 @@ export default defineComponent({
84
87
85
88
const searchStore = useSearchStore ()
86
89
const featureFlagStore = useFeatureFlagStore ()
90
+ const { app } = useContext ()
87
91
88
92
const additionalSearchViews = computed (() =>
89
93
featureFlagStore .isOn (" additional_search_views" )
90
94
)
91
95
92
- const localizedTagPath = (tag : Tag ) => {
96
+ const localizedTagPath = (tag : string ) => {
93
97
return searchStore .getCollectionPath ({
94
98
type: props .mediaType ,
95
- collectionParams: { collection: " tag" , tag: tag . name },
99
+ collectionParams: { collection: " tag" , tag },
96
100
})
97
101
}
98
102
99
103
const normalizedTags = computed (() => {
100
104
return Array .from (new Set (props .tags .map ((tag ) => tag .name )))
101
105
})
102
106
103
- const fourthRowStartsAt = ref <number >()
107
+ const collapsibleRowsStartAt = ref <number >()
104
108
const dir = computed (() => {
105
109
return app .i18n .localeProperties .dir
106
110
})
@@ -112,7 +116,7 @@ export default defineComponent({
112
116
return previous .offsetLeft > current .offsetLeft
113
117
}
114
118
115
- function findFourthRowStartsAt (parent : HTMLElement ) {
119
+ function findRowStartsAt (parent : HTMLElement ) {
116
120
const children = Array .from (parent .children )
117
121
if (! children .length ) {
118
122
return 0
@@ -126,23 +130,23 @@ export default defineComponent({
126
130
} else if (isFurtherInline (previous , child )) {
127
131
rowCount ++
128
132
}
129
- if (rowCount === 4 ) {
133
+ if (rowCount === ROWS_TO_DISPLAY + 1 ) {
130
134
return i
131
135
}
132
136
}
133
137
return children .length
134
138
}
135
139
136
- const visibleTags = computed (() => {
137
- return fourthRowStartsAt .value && buttonStatus .value === " show"
138
- ? normalizedTags .value .slice (0 , fourthRowStartsAt .value )
140
+ const visibleTags = computed < string []> (() => {
141
+ return collapsibleRowsStartAt .value && buttonStatus .value === " show"
142
+ ? normalizedTags .value .slice (0 , collapsibleRowsStartAt .value )
139
143
: normalizedTags .value
140
144
})
141
145
142
146
const hasOverflow = computed (() => {
143
147
return (
144
- fourthRowStartsAt .value &&
145
- fourthRowStartsAt .value < normalizedTags .value .length
148
+ collapsibleRowsStartAt .value &&
149
+ collapsibleRowsStartAt .value < normalizedTags .value .length
146
150
)
147
151
})
148
152
@@ -152,7 +156,7 @@ export default defineComponent({
152
156
* to determine which tags to hide.
153
157
*/
154
158
if (tagsContainerRef .value ) {
155
- fourthRowStartsAt .value = findFourthRowStartsAt (tagsContainerRef .value )
159
+ collapsibleRowsStartAt .value = findRowStartsAt (tagsContainerRef .value )
156
160
}
157
161
})
158
162
@@ -163,13 +167,13 @@ export default defineComponent({
163
167
*/
164
168
const handleClick = () => {
165
169
buttonStatus .value = buttonStatus .value === " show" ? " hide" : " show"
166
- if (buttonStatus .value === " hide" && fourthRowStartsAt .value ) {
170
+ if (buttonStatus .value === " hide" && collapsibleRowsStartAt .value ) {
167
171
nextTick (() => {
168
- if (! fourthRowStartsAt .value ) {
172
+ if (! collapsibleRowsStartAt .value ) {
169
173
return
170
174
}
171
175
const firstTagInFourthRow = tagsContainerRef .value ?.children .item (
172
- fourthRowStartsAt .value
176
+ collapsibleRowsStartAt .value
173
177
) as HTMLElement
174
178
focusElement (firstTagInFourthRow ?.querySelector (" a" ))
175
179
})
@@ -200,11 +204,11 @@ export default defineComponent({
200
204
const isWidening = oldWidth && newWidth && newWidth > oldWidth
201
205
202
206
if (isWidening ) {
203
- fourthRowStartsAt .value = normalizedTags .value .length
207
+ collapsibleRowsStartAt .value = normalizedTags .value .length
204
208
}
205
209
nextTick (() => {
206
210
if (tagsContainerRef .value ) {
207
- fourthRowStartsAt .value = findFourthRowStartsAt (
211
+ collapsibleRowsStartAt .value = findRowStartsAt (
208
212
tagsContainerRef .value
209
213
)
210
214
}
0 commit comments