immich/web/src/lib/components/photos-page/memory-lane.svelte

114 lines
4.1 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { resizeObserver } from '$lib/actions/resize-observer';
import { AppRoute, QueryParameter } from '$lib/constants';
import { memoryStore } from '$lib/stores/memory.store.svelte';
import { getAssetThumbnailUrl, memoryLaneTitle } from '$lib/utils';
import { getAltText } from '$lib/utils/thumbnail-util';
import { toAsset } from '$lib/utils/timeline-util';
2025-09-16 21:40:43 +02:00
import { Icon } from '@immich/ui';
2023-10-25 09:48:25 -04:00
import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
import { onMount } from 'svelte';
import { t } from 'svelte-i18n';
import { fade } from 'svelte/transition';
let shouldRender = $derived(memoryStore.memories?.length > 0);
onMount(async () => {
await memoryStore.initialize();
});
let memoryLaneElement: HTMLElement | undefined = $state();
let offsetWidth = $state(0);
let innerWidth = $state(0);
let scrollLeftPosition = $state(0);
const onScroll = () => {
scrollLeftPosition = memoryLaneElement?.scrollLeft ?? 0;
};
let canScrollLeft = $derived(scrollLeftPosition > 0);
let canScrollRight = $derived(Math.ceil(scrollLeftPosition) < Math.floor(innerWidth - offsetWidth));
const scrollBy = 400;
const scrollLeft = () => memoryLaneElement?.scrollBy({ left: -scrollBy, behavior: 'smooth' });
const scrollRight = () => memoryLaneElement?.scrollBy({ left: scrollBy, behavior: 'smooth' });
</script>
{#if shouldRender}
<section
id="memory-lane"
bind:this={memoryLaneElement}
2025-06-19 22:33:12 -04:00
class="relative mt-3 overflow-x-scroll overflow-y-hidden whitespace-nowrap transition-all"
style="scrollbar-width:none"
use:resizeObserver={({ width }) => (offsetWidth = width)}
onscroll={onScroll}
>
{#if canScrollLeft || canScrollRight}
2025-05-22 15:17:14 -05:00
<div class="sticky start-0 z-1">
{#if canScrollLeft}
<div
class="absolute start-4 max-md:top-[75px] top-[108px] -translate-y-1/2"
transition:fade={{ duration: 200 }}
>
<button
2024-05-27 09:06:15 +02:00
type="button"
class="rounded-full border border-gray-500 bg-gray-100 p-2 text-gray-500 opacity-50 hover:opacity-100"
title={$t('previous')}
aria-label={$t('previous')}
onclick={scrollLeft}
>
2025-09-16 21:40:43 +02:00
<Icon icon={mdiChevronLeft} size="36" aria-label={$t('previous')} /></button
>
</div>
{/if}
{#if canScrollRight}
<div
class="absolute end-4 max-md:top-[75px] top-[108px] -translate-y-1/2 z-1"
transition:fade={{ duration: 200 }}
>
<button
2024-05-27 09:06:15 +02:00
type="button"
class="rounded-full border border-gray-500 bg-gray-100 p-2 text-gray-500 opacity-50 hover:opacity-100"
title={$t('next')}
aria-label={$t('next')}
onclick={scrollRight}
>
2025-09-16 21:40:43 +02:00
<Icon icon={mdiChevronRight} size="36" aria-label={$t('next')} /></button
>
</div>
{/if}
</div>
{/if}
<div class="inline-block" use:resizeObserver={({ width }) => (innerWidth = width)}>
{#each memoryStore.memories as memory (memory.id)}
<a
class="memory-card relative me-2 md:me-4 last:me-0 inline-block aspect-3/4 md:aspect-4/3 max-md:h-[150px] xl:aspect-video h-[216px] rounded-xl"
href="{AppRoute.MEMORY}?{QueryParameter.ID}={memory.assets[0].id}"
>
<img
class="h-full w-full rounded-xl object-cover"
src={getAssetThumbnailUrl(memory.assets[0].id)}
alt={$t('memory_lane_title', { values: { title: $getAltText(toAsset(memory.assets[0])) } })}
draggable="false"
/>
<div
2025-05-18 15:51:33 +02:00
class="absolute start-0 top-0 h-full w-full rounded-xl bg-linear-to-t from-black/40 via-transparent to-transparent transition-all hover:bg-black/20"
></div>
2025-05-13 23:52:56 +02:00
<p class="absolute bottom-2 start-4 text-lg text-white max-md:text-sm">
{$memoryLaneTitle(memory)}
</p>
</a>
{/each}
</div>
</section>
{/if}
<style>
.memory-card {
2023-11-27 11:42:04 -05:00
box-shadow:
rgba(60, 64, 67, 0.3) 0px 1px 2px 0px,
rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
}
</style>