diff --git a/frontend/src/lib/components/AdventureCard.svelte b/frontend/src/lib/components/AdventureCard.svelte index 4ada38b6..e6952f03 100644 --- a/frontend/src/lib/components/AdventureCard.svelte +++ b/frontend/src/lib/components/AdventureCard.svelte @@ -18,7 +18,6 @@ import CollectionLink from './CollectionLink.svelte'; import DotsHorizontal from '~icons/mdi/dots-horizontal'; import DeleteWarning from './DeleteWarning.svelte'; - import ImageDisplayModal from './ImageDisplayModal.svelte'; import { isAdventureVisited, typeToString } from '$lib'; import CardCarousel from './CardCarousel.svelte'; diff --git a/frontend/src/lib/components/CardCarousel.svelte b/frontend/src/lib/components/CardCarousel.svelte index d7779338..ca9e6520 100644 --- a/frontend/src/lib/components/CardCarousel.svelte +++ b/frontend/src/lib/components/CardCarousel.svelte @@ -4,30 +4,34 @@ export let adventures: Adventure[] = []; - let adventure_images: string[] = []; - let currentSlide = 0; // Declare as a regular variable - - let adventure: Adventure | null = null; + let currentSlide = 0; let image_url: string | null = null; - adventures.forEach((adventure) => { - adventure_images = [...adventure_images, ...adventure.images.map((image) => image.image)]; - }); + $: adventure_images = adventures.flatMap((adventure) => + adventure.images.map((image) => ({ image: image.image, adventure: adventure })) + ); - // Reactive statement to log when currentSlide changes - $: console.log('Current slide:', currentSlide); + $: { + if (adventure_images.length > 0) { + currentSlide = 0; + } + } function changeSlide(direction: string) { if (direction === 'next' && currentSlide < adventure_images.length - 1) { - currentSlide = currentSlide + 1; // Use direct assignment + currentSlide = currentSlide + 1; } else if (direction === 'prev' && currentSlide > 0) { - currentSlide = currentSlide - 1; // Use direct assignment + currentSlide = currentSlide - 1; } } {#if image_url} - (image_url = null)} /> + (image_url = null)} + /> {/if}
@@ -39,13 +43,13 @@ (image_url = adventure_images[currentSlide])} + on:click|stopPropagation={() => (image_url = adventure_images[currentSlide].image)} class="cursor-pointer" > {adventure_images[currentSlide]} diff --git a/frontend/src/lib/components/CollectionCard.svelte b/frontend/src/lib/components/CollectionCard.svelte index e983aaf5..f34f00c8 100644 --- a/frontend/src/lib/components/CollectionCard.svelte +++ b/frontend/src/lib/components/CollectionCard.svelte @@ -17,7 +17,6 @@ import TrashCan from '~icons/mdi/trashcan'; import DeleteWarning from './DeleteWarning.svelte'; import ShareModal from './ShareModal.svelte'; - import ImageDisplayModal from './ImageDisplayModal.svelte'; import CardCarousel from './CardCarousel.svelte'; const dispatch = createEventDispatcher(); diff --git a/frontend/src/lib/components/ImageDisplayModal.svelte b/frontend/src/lib/components/ImageDisplayModal.svelte index 060ec92f..8ccd0294 100644 --- a/frontend/src/lib/components/ImageDisplayModal.svelte +++ b/frontend/src/lib/components/ImageDisplayModal.svelte @@ -6,6 +6,7 @@ import type { Adventure } from '$lib/types'; export let image: string; + export let adventure: Adventure | null = null; onMount(() => { modal = document.getElementById('my_modal_1') as HTMLDialogElement; @@ -41,34 +42,36 @@