diff --git a/src/app/(public)/repos/_components/pagination.tsx b/src/app/(public)/repos/_components/pagination.tsx index 1329d7d..5d105a0 100644 --- a/src/app/(public)/repos/_components/pagination.tsx +++ b/src/app/(public)/repos/_components/pagination.tsx @@ -1,6 +1,9 @@ +'use client'; + import { Button } from '@/app/(public)/_components/button'; -import { ArrowLeft, ArrowRight } from 'lucide-react'; -import Link from 'next/link'; +import { ArrowLeft, ArrowRight, Loader2 } from 'lucide-react'; +import { useRouter } from 'next/navigation'; +import { useTransition } from 'react'; import type { SearchParams } from '@/types'; const MAX_PER_PAGE = 21; @@ -15,24 +18,60 @@ export function Pagination({ totalCount, searchParams }: PaginationProps) { + const router = useRouter(); + const [isPending, startTransition] = useTransition(); + + function changePage(delta: number) { + const params = new URLSearchParams( + Object.entries(searchParams).map(([k, v]) => [k, String(v)]) + ); + params.set('p', String(page + delta)); + + startTransition(() => { + router.push(`?${params.toString()}`); + }); + } + return (