diff --git a/src/components/app/GalleryPreview.svelte b/src/components/app/GalleryPreview.svelte index 752b3e3fd..91402b096 100644 --- a/src/components/app/GalleryPreview.svelte +++ b/src/components/app/GalleryPreview.svelte @@ -9,59 +9,78 @@ import getProjectLink from './getProjectLink'; import { browser } from '$app/environment'; import MarkupHtmlView from '../concepts/MarkupHTMLView.svelte'; + import { onMount } from 'svelte'; + import type Project from '@models/Project'; export let gallery: Gallery; - const Count = 5; + let index = 0; + let projectID = gallery.getProjects()[0]; + let project: Project | undefined = undefined; + let timeoutID: NodeJS.Timeout; - /** Projects in the gallery to highlight */ - $: highlights = gallery.getProjects().slice(0, Count); - $: hidden = Math.max(0, gallery.getProjects().length - Count); + async function loadNext() { + index = (index + 1) % gallery.getProjects().length; + projectID = gallery.getProjects()[index]; + if (projectID) project = await Projects.get(projectID); + timeoutID = setTimeout(loadNext, Math.random() * 3000 + 3000); + } + + onMount(() => { + loadNext(); + + return () => + timeoutID !== undefined ? clearTimeout(timeoutID) : undefined; + });