2023-06-14 20:47:18 -05:00
|
|
|
<script lang="ts">
|
2023-07-01 00:50:47 -04:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import { api } from '@api';
|
2023-10-25 09:48:25 -04:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { memoryStore } from '$lib/stores/memory.store';
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { fade } from 'svelte/transition';
|
2023-10-25 09:48:25 -04:00
|
|
|
import { mdiChevronLeft, mdiChevronRight } from '@mdi/js';
|
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();
|
2023-07-01 00:50:47 -04:00
|
|
|
const { data } = await api.assetApi.getMemoryLane({
|
2023-10-04 18:11:11 -04:00
|
|
|
month: localTime.getMonth() + 1,
|
|
|
|
|
day: localTime.getDate(),
|
2023-07-01 00:50:47 -04:00
|
|
|
});
|
|
|
|
|
$memoryStore = data;
|
|
|
|
|
});
|
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}
|
2023-06-14 20:47:18 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
<div class="inline-block" bind:offsetWidth={innerWidth}>
|
|
|
|
|
{#each $memoryStore as memory, i (memory.title)}
|
|
|
|
|
<button
|
2023-07-18 13:19:39 -05:00
|
|
|
class="memory-card relative mr-8 inline-block aspect-video h-[215px] rounded-xl"
|
2023-07-01 00:50:47 -04:00
|
|
|
on:click={() => goto(`/memory?memory=${i}`)}
|
|
|
|
|
>
|
|
|
|
|
<img
|
2023-07-18 13:19:39 -05:00
|
|
|
class="h-full w-full rounded-xl object-cover"
|
2023-07-01 00:50:47 -04:00
|
|
|
src={api.getAssetThumbnailUrl(memory.assets[0].id, 'JPEG')}
|
|
|
|
|
alt={memory.title}
|
|
|
|
|
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 {
|
|
|
|
|
box-shadow: rgba(60, 64, 67, 0.3) 0px 1px 2px 0px, rgba(60, 64, 67, 0.15) 0px 1px 3px 1px;
|
|
|
|
|
}
|
2023-06-14 20:47:18 -05:00
|
|
|
</style>
|