From ce369e421a3e9bf81a7f8f7f985c59fe835926fe Mon Sep 17 00:00:00 2001 From: Reuben Tier Date: Sat, 14 Jun 2025 22:28:16 +0100 Subject: [PATCH] Theme pagination --- src/pages/themes/[page].astro | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pages/themes/[page].astro b/src/pages/themes/[page].astro index a0a970b652..b1cd87e63b 100644 --- a/src/pages/themes/[page].astro +++ b/src/pages/themes/[page].astro @@ -79,13 +79,16 @@ const priceFilter: FilterGroup = { })), }; -const allThemes: ThemeAndAuthor[] = await fetch( - `${THEMES_API_URL}/api/themes?${Astro.url.searchParams}`, +const params = new URLSearchParams(Astro.url.searchParams) +params.set('page', currentPage.toString()) + +const { themes, count }: { themes: ThemeAndAuthor[], count: number } = await fetch( + `${THEMES_API_URL}/api/themes?${params}`, ).then((res) => res.json()); // take all matching themes and create a paginated list of results const paginatedResults = paginate({ - data: allThemes.filter((theme) => !theme.Theme.featured), + data: [...new Array(count).keys()], pageSize: 18, currentPage, route: '/themes/[page]', @@ -98,8 +101,6 @@ const { page, allPages } = paginatedResults; if (allPages.length && !page) { return Astro.redirect(allPages[0]); } - -const themes = page.data; ---