Skip to content

Commit ea0c6a1

Browse files
committed
Add a constant for number of rows to show
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent 1a1e4a8 commit ea0c6a1

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

frontend/src/components/VMediaInfo/VMediaTags.vue

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ import VTag from "~/components/VTag/VTag.vue"
6666
import VButton from "~/components/VButton.vue"
6767
import VIcon from "~/components/VIcon/VIcon.vue"
6868
69+
// The number of rows to display before collapsing the tags
70+
const ROWS_TO_DISPLAY = 3
71+
6972
export default defineComponent({
7073
name: "VMediaTags",
7174
components: { VIcon, VButton, VMediaTag, VTag },
@@ -84,23 +87,24 @@ export default defineComponent({
8487
8588
const searchStore = useSearchStore()
8689
const featureFlagStore = useFeatureFlagStore()
90+
const { app } = useContext()
8791
8892
const additionalSearchViews = computed(() =>
8993
featureFlagStore.isOn("additional_search_views")
9094
)
9195
92-
const localizedTagPath = (tag: Tag) => {
96+
const localizedTagPath = (tag: string) => {
9397
return searchStore.getCollectionPath({
9498
type: props.mediaType,
95-
collectionParams: { collection: "tag", tag: tag.name },
99+
collectionParams: { collection: "tag", tag },
96100
})
97101
}
98102
99103
const normalizedTags = computed(() => {
100104
return Array.from(new Set(props.tags.map((tag) => tag.name)))
101105
})
102106
103-
const fourthRowStartsAt = ref<number>()
107+
const collapsibleRowsStartAt = ref<number>()
104108
const dir = computed(() => {
105109
return app.i18n.localeProperties.dir
106110
})
@@ -112,7 +116,7 @@ export default defineComponent({
112116
return previous.offsetLeft > current.offsetLeft
113117
}
114118
115-
function findFourthRowStartsAt(parent: HTMLElement) {
119+
function findRowStartsAt(parent: HTMLElement) {
116120
const children = Array.from(parent.children)
117121
if (!children.length) {
118122
return 0
@@ -126,23 +130,23 @@ export default defineComponent({
126130
} else if (isFurtherInline(previous, child)) {
127131
rowCount++
128132
}
129-
if (rowCount === 4) {
133+
if (rowCount === ROWS_TO_DISPLAY + 1) {
130134
return i
131135
}
132136
}
133137
return children.length
134138
}
135139
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)
139143
: normalizedTags.value
140144
})
141145
142146
const hasOverflow = computed(() => {
143147
return (
144-
fourthRowStartsAt.value &&
145-
fourthRowStartsAt.value < normalizedTags.value.length
148+
collapsibleRowsStartAt.value &&
149+
collapsibleRowsStartAt.value < normalizedTags.value.length
146150
)
147151
})
148152
@@ -152,7 +156,7 @@ export default defineComponent({
152156
* to determine which tags to hide.
153157
*/
154158
if (tagsContainerRef.value) {
155-
fourthRowStartsAt.value = findFourthRowStartsAt(tagsContainerRef.value)
159+
collapsibleRowsStartAt.value = findRowStartsAt(tagsContainerRef.value)
156160
}
157161
})
158162
@@ -163,13 +167,13 @@ export default defineComponent({
163167
*/
164168
const handleClick = () => {
165169
buttonStatus.value = buttonStatus.value === "show" ? "hide" : "show"
166-
if (buttonStatus.value === "hide" && fourthRowStartsAt.value) {
170+
if (buttonStatus.value === "hide" && collapsibleRowsStartAt.value) {
167171
nextTick(() => {
168-
if (!fourthRowStartsAt.value) {
172+
if (!collapsibleRowsStartAt.value) {
169173
return
170174
}
171175
const firstTagInFourthRow = tagsContainerRef.value?.children.item(
172-
fourthRowStartsAt.value
176+
collapsibleRowsStartAt.value
173177
) as HTMLElement
174178
focusElement(firstTagInFourthRow?.querySelector("a"))
175179
})
@@ -200,11 +204,11 @@ export default defineComponent({
200204
const isWidening = oldWidth && newWidth && newWidth > oldWidth
201205
202206
if (isWidening) {
203-
fourthRowStartsAt.value = normalizedTags.value.length
207+
collapsibleRowsStartAt.value = normalizedTags.value.length
204208
}
205209
nextTick(() => {
206210
if (tagsContainerRef.value) {
207-
fourthRowStartsAt.value = findFourthRowStartsAt(
211+
collapsibleRowsStartAt.value = findRowStartsAt(
208212
tagsContainerRef.value
209213
)
210214
}

0 commit comments

Comments
 (0)