From 0a392063f5e6293e82d52983d8a1f80e25d2db29 Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Thu, 27 Mar 2025 14:40:32 +0100 Subject: [PATCH] go back with no loading --- app/src/routes/+page.svelte | 66 +++++-------------------------------- 1 file changed, 9 insertions(+), 57 deletions(-) diff --git a/app/src/routes/+page.svelte b/app/src/routes/+page.svelte index 2c85a06..70f73d8 100644 --- a/app/src/routes/+page.svelte +++ b/app/src/routes/+page.svelte @@ -20,15 +20,10 @@ hovered: boolean; }; - let wallpapers: Wallpaper[] = []; - let tags: string[] = []; - let selectedTags: string[] = []; - let search: string = ''; - let loading: boolean = false; - let isLoadingMore: boolean = false; // Etat pour savoir si de nouveaux wallpapers sont en train de charger - let allWallpapers: Wallpaper[] = []; - let currentPage: number = 0; - const wallpapersPerPage: number = 20; + let wallpapers: Wallpaper[] = $state([]); + let tags: string[] = $state([]); + let selectedTags: string[] = $state([]); + let search: string = $state(''); const owner = 'anotherhadi'; const repo = 'awesome-wallpapers'; @@ -64,9 +59,7 @@ const res = await fetch('/files.json'); const fileData: { filename: string; size: string; width: number; height: number }[] = await res.json(); - - // Map to Wallpaper objects - allWallpapers = fileData.map((file) => { + wallpapers = fileData.map((file) => { let { name, filename, tags: fileTags } = parseFilename(file.filename); return { @@ -79,51 +72,15 @@ hovered: false }; }); - - // Initially load the first set of wallpapers - loadMoreWallpapers(); } - function loadMoreWallpapers() { - if (loading || isLoadingMore || currentPage * wallpapersPerPage >= allWallpapers.length) return; - isLoadingMore = true; - - // Load next batch of wallpapers - const nextWallpapers = allWallpapers.slice( - currentPage * wallpapersPerPage, - (currentPage + 1) * wallpapersPerPage - ); - wallpapers = [...wallpapers, ...nextWallpapers]; - currentPage++; - isLoadingMore = false; - } - - // Handle scroll event - function onScroll() { - const scrollPosition = window.scrollY + window.innerHeight; - const bottomPosition = document.documentElement.scrollHeight; - - if (scrollPosition >= bottomPosition - 100) { - // Load more wallpapers when reaching the bottom - loadMoreWallpapers(); - } - } - - onMount(() => { - fetchWallpapers(); - window.addEventListener('scroll', onScroll); - - return () => { - window.removeEventListener('scroll', onScroll); - }; - }); + onMount(fetchWallpapers);
Tags:
- {#if wallpaper.tags.length === 0}
- No tags
- {:else}
+ {#if wallpaper.tags.length > 0}
{#each wallpaper.tags as tag}
@@ -246,9 +203,4 @@ image = pkgs.fetchurl { {/if} {/each} - {#if isLoadingMore} -