2023-06-14 20:47:18 -05:00
|
|
|
<script lang="ts">
|
2024-02-14 08:09:49 -05:00
|
|
|
import { goto } from '$app/navigation';
|
2023-10-25 09:48:25 -04:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { AppRoute, QueryParameter } from '$lib/constants';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { memoryStore } from '$lib/stores/memory.store';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { getAssetThumbnailUrl } from '$lib/utils';
|
2024-03-03 16:42:17 -05:00
|
|
|
import { getAltText } from '$lib/utils/thumbnail-util';
|
2024-02-14 06:38:57 -08:00
|
|
|
import { ThumbnailFormat, getMemoryLane } from '@immich/sdk';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
|
2024-02-14 08:09:49 -05:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { fade } from 'svelte/transition';
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: shouldRender = $memoryStore?.length > 0;
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
onMount(async () => {
|
2023-10-04 18:11:11 -04:00
|
|
|
const localTime = new Date();
|
2024-02-14 08:09:49 -05:00
|
|
|
$memoryStore = await getMemoryLane({ month: localTime.getMonth() + 1, day: localTime.getDate() });
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let memoryLaneElement: HTMLElement;
|
|
|
|
|
let offsetWidth = 0;
|
|
|
|
|
let innerWidth = 0;
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
let scrollLeftPosition = 0;
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onScroll = () => (scrollLeftPosition = memoryLaneElement?.scrollLeft);
|
2023-06-16 17:06:38 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
$: canScrollLeft = scrollLeftPosition > 0;
|
|
|
|
|
$: canScrollRight = Math.ceil(scrollLeftPosition) < innerWidth - offsetWidth;
|
2023-06-16 17:06:38 +01:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const scrollBy = 400;
|
|
|
|
|
const scrollLeft = () => memoryLaneElement.scrollBy({ left: -scrollBy, behavior: 'smooth' });
|
|
|
|
|
const scrollRight = () => memoryLaneElement.scrollBy({ left: scrollBy, behavior: 'smooth' });
|
2023-06-14 20:47:18 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if shouldRender}
|
2023-07-01 00:50:47 -04:00
|
|
|
<section
|
|
|
|
|
id="memory-lane"
|
|
|
|
|
bind:this={memoryLaneElement}
|
2023-07-18 13:19:39 -05:00
|
|
|
class="relative mt-5 overflow-x-hidden whitespace-nowrap transition-all"
|
2023-07-01 00:50:47 -04:00
|
|
|
bind:offsetWidth
|
|
|
|
|
on:scroll={onScroll}
|
|
|
|
|
>
|
|
|
|
|
{#if canScrollLeft || canScrollRight}
|
|
|
|
|
<div class="sticky left-0 z-20">
|
|
|
|
|
{#if canScrollLeft}
|
|
|
|
|
<div class="absolute left-4 top-[6rem] z-20" transition:fade={{ duration: 200 }}>
|
|
|
|
|
<button
|
2023-07-18 13:19:39 -05:00
|
|
|
class="rounded-full border border-gray-500 bg-gray-100 p-2 text-gray-500 opacity-50 hover:opacity-100"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={scrollLeft}
|
|
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiChevronLeft} size="36" /></button
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if canScrollRight}
|
|
|
|
|
<div class="absolute right-4 top-[6rem] z-20" transition:fade={{ duration: 200 }}>
|
|
|
|
|
<button
|
2023-07-18 13:19:39 -05:00
|
|
|
class="rounded-full border border-gray-500 bg-gray-100 p-2 text-gray-500 opacity-50 hover:opacity-100"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={scrollRight}
|
|
|
|
|
>
|
2023-10-25 09:48:25 -04:00
|
|
|
<Icon path={mdiChevronRight} size="36" /></button
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<div class="inline-block" bind:offsetWidth={innerWidth}>
|
2024-02-02 04:18:00 +01:00
|
|
|
{#each $memoryStore as memory, index (memory.title)}
|
2023-07-01 00:50:47 -04:00
|
|
|
<button
|
2023-07-18 13:19:39 -05:00
|
|
|
class="memory-card relative mr-8 inline-block aspect-video h-[215px] rounded-xl"
|
2024-02-02 04:18:00 +01:00
|
|
|
on:click={() => goto(`${AppRoute.MEMORY}?${QueryParameter.MEMORY_INDEX}=${index}`)}
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
<img
|
2023-07-18 13:19:39 -05:00
|
|
|
class="h-full w-full rounded-xl object-cover"
|
2024-03-06 12:05:53 -05:00
|
|
|
src={getAssetThumbnailUrl(memory.assets[0].id, ThumbnailFormat.Webp)}
|
2024-03-03 16:42:17 -05:00
|
|
|
alt={`Memory Lane ${getAltText(memory.assets[0])}`}
|
2023-07-01 00:50:47 -04:00
|
|
|
draggable="false"
|
|
|
|
|
/>
|
2023-07-18 13:19:39 -05:00
|
|
|
<p class="absolute bottom-2 left-4 z-10 text-lg text-white">{memory.title}</p>
|
2023-07-01 00:50:47 -04:00
|
|
|
<div
|
2023-07-18 13:19:39 -05:00
|
|
|
class="absolute left-0 top-0 z-0 h-full w-full rounded-xl bg-gradient-to-t from-black/40 via-transparent to-transparent transition-all hover:bg-black/20"
|
2023-07-01 00:50:47 -04:00
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
2023-06-14 20:47:18 -05:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<style>
|
2023-07-01 00:50:47 -04:00
|
|
|
.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;
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
2023-06-14 20:47:18 -05:00
|
|
|
</style>
|