refactor(web): convert memory observer to an attachment (#26646)

This commit is contained in:
Michel Heusschen
2026-03-02 15:20:13 +01:00
committed by GitHub
parent f06af2c600
commit ea668d6b22
2 changed files with 18 additions and 166 deletions

View File

@@ -1,7 +1,6 @@
<script lang="ts">
import { afterNavigate, goto } from '$app/navigation';
import { page } from '$app/state';
import { intersectionObserver } from '$lib/actions/intersection-observer';
import { resizeObserver } from '$lib/actions/resize-observer';
import { shortcuts } from '$lib/actions/shortcut';
import MemoryPhotoViewer from '$lib/components/memory-page/memory-photo-viewer.svelte';
@@ -55,6 +54,7 @@
import type { NavigationTarget, Page } from '@sveltejs/kit';
import { DateTime } from 'luxon';
import { t } from 'svelte-i18n';
import type { Attachment } from 'svelte/attachments';
import { Tween } from 'svelte/motion';
let memoryGallery: HTMLElement | undefined = $state();
@@ -236,6 +236,22 @@
galleryFirstLoad = false;
};
const galleryObserver: Attachment<HTMLElement> = (element) => {
const observer = new IntersectionObserver(
([entry]) => {
if (entry?.isIntersecting) {
handleGalleryScrollsIntoView();
} else {
handleGalleryScrollsOutOfView();
}
},
{ rootMargin: '0px 0px -200px 0px' },
);
observer.observe(element);
return () => observer.disconnect();
};
const loadFromParams = (page: Page | NavigationTarget | null) => {
const assetId = page?.params?.assetId ?? page?.url.searchParams.get(QueryParameter.ID) ?? undefined;
return memoryStore.getMemoryAsset(assetId);
@@ -644,15 +660,7 @@
/>
</div>
<div
id="gallery-memory"
use:intersectionObserver={{
onIntersect: handleGalleryScrollsIntoView,
onSeparate: handleGalleryScrollsOutOfView,
bottom: '-200px',
}}
bind:this={memoryGallery}
>
<div id="gallery-memory" {@attach galleryObserver} bind:this={memoryGallery}>
<GalleryViewer
assets={currentTimelineAssets}
{viewerAssets}