2024-10-13 23:23:32 -04:00
|
|
|
|
<script lang="ts">
|
|
|
|
|
import type { Adventure } from '$lib/types';
|
|
|
|
|
import ImageDisplayModal from './ImageDisplayModal.svelte';
|
2024-10-28 13:56:57 -04:00
|
|
|
|
import { t } from 'svelte-i18n';
|
2024-10-13 23:23:32 -04:00
|
|
|
|
|
|
|
|
|
export let adventures: Adventure[] = [];
|
|
|
|
|
|
2024-10-14 08:58:23 -04:00
|
|
|
|
let currentSlide = 0;
|
2024-10-13 23:23:32 -04:00
|
|
|
|
let image_url: string | null = null;
|
|
|
|
|
|
2024-10-14 08:58:23 -04:00
|
|
|
|
$: adventure_images = adventures.flatMap((adventure) =>
|
2025-01-02 23:25:58 -05:00
|
|
|
|
adventure.images.map((image) => ({
|
|
|
|
|
image: image.image,
|
|
|
|
|
adventure: adventure,
|
|
|
|
|
is_primary: image.is_primary
|
|
|
|
|
}))
|
2024-10-14 08:58:23 -04:00
|
|
|
|
);
|
2024-10-13 23:23:32 -04:00
|
|
|
|
|
2024-10-14 08:58:23 -04:00
|
|
|
|
$: {
|
|
|
|
|
if (adventure_images.length > 0) {
|
|
|
|
|
currentSlide = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-13 23:23:32 -04:00
|
|
|
|
|
2025-01-02 23:25:58 -05:00
|
|
|
|
$: {
|
|
|
|
|
// sort so that any image in adventure_images .is_primary is first
|
|
|
|
|
adventure_images.sort((a, b) => {
|
|
|
|
|
if (a.is_primary && !b.is_primary) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (!a.is_primary && b.is_primary) {
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-13 23:23:32 -04:00
|
|
|
|
function changeSlide(direction: string) {
|
|
|
|
|
if (direction === 'next' && currentSlide < adventure_images.length - 1) {
|
2024-10-14 08:58:23 -04:00
|
|
|
|
currentSlide = currentSlide + 1;
|
2024-10-13 23:23:32 -04:00
|
|
|
|
} else if (direction === 'prev' && currentSlide > 0) {
|
2024-10-14 08:58:23 -04:00
|
|
|
|
currentSlide = currentSlide - 1;
|
2024-10-13 23:23:32 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if image_url}
|
2024-10-14 08:58:23 -04:00
|
|
|
|
<ImageDisplayModal
|
|
|
|
|
adventure={adventure_images[currentSlide].adventure}
|
|
|
|
|
image={image_url}
|
|
|
|
|
on:close={() => (image_url = null)}
|
|
|
|
|
/>
|
2024-10-13 23:23:32 -04:00
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<figure>
|
|
|
|
|
{#if adventure_images && adventure_images.length > 0}
|
|
|
|
|
<div class="carousel w-full relative">
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
<div class="carousel-item w-full block">
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
|
|
|
<!-- svelte-ignore a11y-missing-attribute -->
|
|
|
|
|
<a
|
2024-10-14 08:58:23 -04:00
|
|
|
|
on:click|stopPropagation={() => (image_url = adventure_images[currentSlide].image)}
|
2024-10-13 23:23:32 -04:00
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
>
|
|
|
|
|
<img
|
2024-10-14 08:58:23 -04:00
|
|
|
|
src={adventure_images[currentSlide].image}
|
2024-10-13 23:23:32 -04:00
|
|
|
|
class="w-full h-48 object-cover"
|
2024-10-14 08:58:23 -04:00
|
|
|
|
alt={adventure_images[currentSlide].adventure.name}
|
2024-10-13 23:23:32 -04:00
|
|
|
|
/>
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
{#if adventure_images.length > 1}
|
|
|
|
|
<div class="absolute inset-0 flex items-center justify-between pointer-events-none">
|
|
|
|
|
{#if currentSlide > 0}
|
|
|
|
|
<button
|
|
|
|
|
on:click|stopPropagation={() => changeSlide('prev')}
|
|
|
|
|
class="btn btn-circle btn-sm ml-2 pointer-events-auto">❮</button
|
|
|
|
|
>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="w-12"></div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if currentSlide < adventure_images.length - 1}
|
|
|
|
|
<button
|
|
|
|
|
on:click|stopPropagation={() => changeSlide('next')}
|
|
|
|
|
class="btn btn-circle mr-2 btn-sm pointer-events-auto">❯</button
|
|
|
|
|
>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="w-12"></div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
2025-01-19 22:33:35 -05:00
|
|
|
|
<!-- add a figure with a gradient instead - -->
|
|
|
|
|
<div class="w-full h-48 bg-gradient-to-r from-success via-base to-primary relative">
|
|
|
|
|
<!-- subtle button bottom left text -->
|
|
|
|
|
<div
|
|
|
|
|
class="absolute bottom-0 left-0 px-2 py-1 text-md font-medium bg-neutral rounded-tr-lg shadow-md"
|
|
|
|
|
>
|
|
|
|
|
{$t('adventures.no_image_found')}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-10-13 23:23:32 -04:00
|
|
|
|
{/if}
|
|
|
|
|
</figure>
|