From 58c20b00c6fe58fee291be4799cca93845575283 Mon Sep 17 00:00:00 2001 From: aiirvizionz Date: Fri, 10 Jul 2026 23:11:05 -0600 Subject: [PATCH] Paginate bounties listing --- src/app/bounties/page.tsx | 64 +++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/src/app/bounties/page.tsx b/src/app/bounties/page.tsx index 08d694a1..ade01759 100644 --- a/src/app/bounties/page.tsx +++ b/src/app/bounties/page.tsx @@ -31,22 +31,45 @@ interface BountyListItem { } | null; } -export default async function BountiesPage() { +interface BountiesPageProps { + searchParams?: Promise<{ + page?: string; + }>; +} + +function parsePageParam(value?: string) { + const page = Number(value); + return Number.isFinite(page) && page > 0 ? Math.floor(page) : 1; +} + +export default async function BountiesPage({ searchParams }: BountiesPageProps) { + const resolvedParams = await searchParams; + const page = parsePageParam(resolvedParams?.page); + const limit = 20; + const offset = (page - 1) * limit; const supabase = await createClient(); - const { data } = await supabase + const { data, count } = await supabase .from("bounties" as any) .select( ` id, title, description, payout_usd, payout_currency, payment_coin, max_submissions, status, created_at, creator:profiles!creator_id (id, username, full_name, avatar_url) - ` + `, + { count: "exact" } ) .eq("status", "open") .order("created_at", { ascending: false }) - .limit(100); + .range(offset, offset + limit - 1); const bounties = (data || []) as unknown as BountyListItem[]; + const totalPages = Math.ceil((count || 0) / limit); + + const buildPaginationUrl = (newPage: number) => { + const params = new URLSearchParams(); + params.set("page", String(newPage)); + return `/bounties?${params.toString()}`; + }; return ( <> @@ -62,8 +85,7 @@ export default async function BountiesPage() {

Bounties

- Complete short tasks for a fixed payout. Answer the form, get - approved, get paid. + Complete short tasks for a fixed payout. Answer the form, get approved, get paid.

@@ -78,9 +100,7 @@ export default async function BountiesPage() {

No open bounties yet

-

- Be the first to post one. -

+

Be the first to post one.

@@ -94,19 +114,14 @@ export default async function BountiesPage() { className="p-5 bg-card rounded-lg border border-border shadow-sm hover:shadow-md hover:border-primary/30 transition-all duration-200" >

{b.title}

-

- {b.description} -

+

{b.description}

{formatBountyPayout(b.payout_usd, b.payment_coin)} - by{" "} - {b.creator?.full_name || - b.creator?.username || - "Anonymous"} + by {b.creator?.full_name || b.creator?.username || "Anonymous"} {b.max_submissions && ( @@ -119,6 +134,23 @@ export default async function BountiesPage() { ))}
)} + {totalPages > 1 && ( +
+ {page > 1 && ( + + + + )} + + Page {page} of {totalPages} + + {page < totalPages && ( + + + + )} +
+ )}