From 143e78cbae5fe78ca9cf43c564fc435e7f8c8d4f Mon Sep 17 00:00:00 2001 From: Craig Kaiser Date: Wed, 16 Oct 2024 10:42:44 -0400 Subject: [PATCH] Add pagination for events list --- src/components/eventsCards.svelte | 55 ++++++++++++++++--- src/routes/auth/+page.server.ts | 4 -- .../protected-routes/dashboard/+page.svelte | 10 ++-- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/components/eventsCards.svelte b/src/components/eventsCards.svelte index 5b4857c..701170e 100644 --- a/src/components/eventsCards.svelte +++ b/src/components/eventsCards.svelte @@ -2,13 +2,35 @@ import * as Card from '$components/ui/card/index.js'; import { getLocalTimeZone, parseDateTime } from '@internationalized/date'; - export let events: Partial[]; + // Input prop + let { events }: { events: Partial[] } = $props(); + + // Pagination states + let currentPage = $state(1); + let itemsPerPage = 4; // Adjust this to the number of events you want to show per page + + // Calculate total pages + let totalPages = $derived(Math.ceil(events?.length / itemsPerPage)); + + // Get events for the current page + let paginatedEvents = $derived( + events?.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage) + ); + + // Navigation handlers + const nextPage = () => { + if (currentPage < totalPages) currentPage++; + }; + + const prevPage = () => { + if (currentPage > 1) currentPage--; + };
- {#if events && events.length > 0} + {#if paginatedEvents && paginatedEvents.length > 0} + + +
+ + Page {currentPage} of {totalPages} + +
{/if}
diff --git a/src/routes/auth/+page.server.ts b/src/routes/auth/+page.server.ts index fe53435..8d267c1 100644 --- a/src/routes/auth/+page.server.ts +++ b/src/routes/auth/+page.server.ts @@ -1,4 +1,3 @@ -import { invalidate } from '$app/navigation'; import { signUpSchema, signInSchema, resetPasswordSchema } from './schemas'; import { setError, message, superValidate, fail } from 'sveltekit-superforms'; import { zod } from 'sveltekit-superforms/adapters'; @@ -30,10 +29,7 @@ export const actions = { return setError(form, 'email', error.message); } - invalidate('supabase:auth'); - // Instead of returning the form directly, redirect or trigger a session update - // Option 1: Redirect after signing in return { form, redirect: '/protected-routes/dashboard' }; }, diff --git a/src/routes/protected-routes/dashboard/+page.svelte b/src/routes/protected-routes/dashboard/+page.svelte index 17a204e..7243ec8 100644 --- a/src/routes/protected-routes/dashboard/+page.svelte +++ b/src/routes/protected-routes/dashboard/+page.svelte @@ -1,11 +1,10 @@ @@ -22,6 +21,9 @@ {/if}
- +