Spaces:
Paused
Paused
Download src/lib/components/InfiniteScroll.svelte from maksym-work/chat_ui: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/maksym-work/chat_ui/resolve/main/src/lib/components/InfiniteScroll.svelte
- Command line
-
hf download hf://spaces/maksym-work/chat_ui/src/lib/components/InfiniteScroll.svelte
-
curl -L -o InfiniteScroll.svelte https://huggingface.co/spaces/maksym-work/chat_ui/resolve/main/src/lib/components/InfiniteScroll.svelte
1.3 kB
| <script lang="ts"> | |
| import { onMount, createEventDispatcher } from "svelte"; | |
| const dispatch = createEventDispatcher(); | |
| let loader: HTMLDivElement | undefined = $state(); | |
| let observer: IntersectionObserver; | |
| let intervalId: ReturnType<typeof setInterval> | undefined; | |
| onMount(() => { | |
| if (!loader) { | |
| return; | |
| } | |
| observer = new IntersectionObserver((entries) => { | |
| entries.forEach((entry) => { | |
| if (entry.isIntersecting) { | |
| // Clear any existing interval | |
| if (intervalId) { | |
| clearInterval(intervalId); | |
| } | |
| // Start new interval that dispatches every 250ms | |
| intervalId = setInterval(() => { | |
| dispatch("visible"); | |
| }, 250); | |
| } else { | |
| // Clear interval when not intersecting | |
| if (intervalId) { | |
| clearInterval(intervalId); | |
| intervalId = undefined; | |
| } | |
| } | |
| }); | |
| }); | |
| observer.observe(loader); | |
| return () => { | |
| observer.disconnect(); | |
| if (intervalId) { | |
| clearInterval(intervalId); | |
| } | |
| }; | |
| }); | |
| </script> | |
| <div bind:this={loader} class="flex animate-pulse flex-col gap-4"> | |
| <div class="w-5/5 ml-2 h-5 gap-5 rounded bg-gray-300 dark:bg-gray-700"></div> | |
| <div class="w-5/5 ml-2 h-5 gap-5 rounded bg-gray-300 dark:bg-gray-700"></div> | |
| <div class="w-5/5 ml-2 h-5 gap-5 rounded bg-gray-300 dark:bg-gray-700"></div> | |
| </div> | |