mirror of
https://github.com/immich-app/immich.git
synced 2026-03-23 01:38:58 +03:00
refactor(web): convert memory observer to an attachment (#26646)
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user