From 0b1491717a9559bc2dc34a3e6defd310df472380 Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Thu, 2 Nov 2023 18:42:27 -0700 Subject: [PATCH] Fixed #258, more performant gallery previews. --- src/components/app/GalleryPreview.svelte | 100 +++++++++++++---------- src/components/app/ProjectPreview.svelte | 5 +- 2 files changed, 62 insertions(+), 43 deletions(-) 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; + }); diff --git a/src/components/app/ProjectPreview.svelte b/src/components/app/ProjectPreview.svelte index 0adb3a8ac..1e7d79c36 100644 --- a/src/components/app/ProjectPreview.svelte +++ b/src/components/app/ProjectPreview.svelte @@ -14,6 +14,7 @@ export let action: (() => void) | undefined = undefined; export let delay: number; export let name = true; + export let size = 4; // Clone the project and get its initial value, then stop the project's evaluator. let evaluator: Evaluator; @@ -42,6 +43,8 @@
action && event.button === 0 ? action() : undefined} @@ -119,8 +122,6 @@ .preview { cursor: pointer; - width: 4rem; - height: 4rem; overflow: hidden; border: var(--wordplay-border-color) solid var(--wordplay-border-width); border-radius: var(--wordplay-border-radius);