Skip to content

Commit 5ffbe9d

Browse files
Add pagination functionality to invoices UI
1 parent fcb3897 commit 5ffbe9d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/ui/invoices/pagination.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,24 @@ import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline';
44
import clsx from 'clsx';
55
import Link from 'next/link';
66
import { generatePagination } from '@/app/lib/utils';
7+
import { usePathname, useSearchParams } from 'next/navigation';
78

89
export default function Pagination({ totalPages }: { totalPages: number }) {
9-
// NOTE: comment in this code when you get to this point in the course
10+
const pathname = usePathname();
11+
const searchParams = useSearchParams();
12+
const currentPage = Number(searchParams.get('page')) || 1;
1013

11-
// const allPages = generatePagination(currentPage, totalPages);
14+
const allPages = generatePagination(currentPage, totalPages);
15+
16+
const createPageURL = (pageNumber: number | string) => {
17+
const params = new URLSearchParams(searchParams);
18+
params.set('page', pageNumber.toString());
19+
return `${pathname}?${params.toString()}`
20+
};
1221

1322
return (
1423
<>
15-
{/* NOTE: comment in this code when you get to this point in the course */}
16-
17-
{/* <div className="inline-flex">
24+
<div className="inline-flex">
1825
<PaginationArrow
1926
direction="left"
2027
href={createPageURL(currentPage - 1)}
@@ -47,7 +54,7 @@ export default function Pagination({ totalPages }: { totalPages: number }) {
4754
href={createPageURL(currentPage + 1)}
4855
isDisabled={currentPage >= totalPages}
4956
/>
50-
</div> */}
57+
</div>
5158
</>
5259
);
5360
}

0 commit comments

Comments
 (0)