From aa884930bc0675a028f625c4f41ce4cb814e5d61 Mon Sep 17 00:00:00 2001 From: Lightling Date: Thu, 17 Oct 2024 02:46:40 -0400 Subject: [PATCH] update gallery-view with the data changes --- .../src/content/templates/gallery-list.d.ts | 6 ++--- .../src/views/gallery/gallery-view.vue | 26 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/types/src/content/templates/gallery-list.d.ts b/libs/types/src/content/templates/gallery-list.d.ts index c86f5ee..58d73eb 100644 --- a/libs/types/src/content/templates/gallery-list.d.ts +++ b/libs/types/src/content/templates/gallery-list.d.ts @@ -39,10 +39,10 @@ export type GalleryEntryWithoutVariants = { */ export type GalleryEntryWithVariants = { /** - * The id of the entry from the {@link GalleryEntry variants} collection to display when the page first loads. + * The index of the entry from the {@link GalleryEntry variants} collection to display when the page first loads. * If this is not defined, the first entry will be chosen instead. */ - defaultVariant?: string + defaultVariant?: number /** * Variants are a collection of alternate media to display for the entry. * This changes based on the {@link GalleryEntryFormat format} of the entry: @@ -51,7 +51,7 @@ export type GalleryEntryWithVariants = { * - For all other media, this is put into a carousel, * where the {@link GalleryEntry.defaultVariant default} or selected variant is displayed in the main viewer */ - variants: Record + variants: GalleryEntryWithoutVariants[] } & GalleryEntrySharedProperties /** diff --git a/projects/frontend/src/views/gallery/gallery-view.vue b/projects/frontend/src/views/gallery/gallery-view.vue index 2747694..c86e137 100644 --- a/projects/frontend/src/views/gallery/gallery-view.vue +++ b/projects/frontend/src/views/gallery/gallery-view.vue @@ -31,24 +31,25 @@ const routeSubConfig = routeStore._routes[currentRoute.path] const description = computed(() => marked.parse(resolved.value.description || '') as string) const title = computed(() => marked.parse(resolved.value.title || currentRoute.query.id!.toString()) as string) const url = computed(() => (resolved.value as GalleryEntryWithoutVariants).url) -const hasVariants = computed(() => !!(resolved.value as GalleryEntryWithVariants).variants) const fields = computed(() => { const toReturn = {} as Record if (!!resolved.value.date) { toReturn.date = resolved.value.date } if (!!resolved.value.warnings) { - toReturn.warning = resolved.value.warnings + toReturn.warnings = resolved.value.warnings } return toReturn }) const variants = computed(() => (resolved.value as GalleryEntryWithVariants).variants) const variantsCount = computed(() => Object.keys((resolved.value as GalleryEntryWithVariants).variants).length) -const currentSelection = defineModel('currentSelection', { type: String, default: '' }) -const currentUrl = computed(() => hasVariants ? (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].url : url) +const currentSelection = defineModel('currentSelection', { type: Number, default: 0 }) +const currentUrl = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].url) +const currentAlt = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].alternativeText) +const currentCaption = computed(() => (resolved.value as GalleryEntryWithVariants).variants[currentSelection.value].caption) const carousel = ref(null! as HTMLElement) -const onVariantSelected = (event: Event, id: string) => { +const onVariantSelected = (event: Event, id: number) => { currentSelection.value = id } @@ -78,11 +79,7 @@ onMounted(async () => { window.routeConfig = {...routeConfig} window.routeSubConfig = {...routeSubConfig} window.routeContentConfig = {...resolved.value} - - if (hasVariants) { - currentSelection.value = (resolved.value as GalleryEntryWithVariants).defaultVariant || Object.keys((resolved.value as GalleryEntryWithVariants).variants)[0] - } - + currentSelection.value = (resolved.value as GalleryEntryWithVariants).defaultVariant || 0 ready.value = true emits('loaded') }) @@ -97,10 +94,10 @@ onMounted(async () => { .view-outlet img( :src='currentUrl' + :title='currentCaption || currentAlt || description' + :alt='currentAlt || currentCaption || description' ) - .view-carousel( - v-if='hasVariants' - ) + .view-carousel button.left( @click='onButtonClicked($event, -1)' ) @@ -112,8 +109,9 @@ onMounted(async () => { img( v-for='(variant, id) in variants' :class='{ active: id === currentSelection }' + :alt='variant.alternativeText || variant.caption || description' :src='variant.thumbnailUrl || variant.url' - :title='variant.title || id' + :title='variant.caption || id' @click='onVariantSelected($event, id)' ) button.right(