2024-07-25 21:59:28 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import type { PersonResponseDto } from '@immich/sdk';
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
people: PersonResponseDto[];
|
|
|
|
|
hasNextPage?: boolean | undefined;
|
|
|
|
|
loadNextPage: () => void;
|
|
|
|
|
children?: import('svelte').Snippet<[{ person: PersonResponseDto; index: number }]>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let { people, hasNextPage = undefined, loadNextPage, children }: Props = $props();
|
2024-07-25 21:59:28 +02:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let lastPersonContainer: HTMLElement | undefined = $state();
|
2024-07-25 21:59:28 +02:00
|
|
|
|
|
|
|
|
const intersectionObserver = new IntersectionObserver((entries) => {
|
|
|
|
|
const entry = entries.find((entry) => entry.target === lastPersonContainer);
|
|
|
|
|
if (entry?.isIntersecting) {
|
|
|
|
|
loadNextPage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
$effect(() => {
|
|
|
|
|
if (lastPersonContainer) {
|
|
|
|
|
intersectionObserver.disconnect();
|
|
|
|
|
intersectionObserver.observe(lastPersonContainer);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-25 21:59:28 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="w-full grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-7 2xl:grid-cols-9 gap-1">
|
|
|
|
|
{#each people as person, index (person.id)}
|
|
|
|
|
{#if hasNextPage && index === people.length - 1}
|
2024-10-18 15:53:47 -05:00
|
|
|
<div bind:this={lastPersonContainer}>
|
2024-11-14 08:43:25 -06:00
|
|
|
{@render children?.({ person, index })}
|
2024-07-25 21:59:28 +02:00
|
|
|
</div>
|
|
|
|
|
{:else}
|
2024-11-14 08:43:25 -06:00
|
|
|
{@render children?.({ person, index })}
|
2024-07-25 21:59:28 +02:00
|
|
|
{/if}
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|