@@ -4,17 +4,24 @@ import { ArrowLeftIcon, ArrowRightIcon } from '@heroicons/react/24/outline';
4
4
import clsx from 'clsx' ;
5
5
import Link from 'next/link' ;
6
6
import { generatePagination } from '@/app/lib/utils' ;
7
+ import { usePathname , useSearchParams } from 'next/navigation' ;
7
8
8
9
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 ;
10
13
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
+ } ;
12
21
13
22
return (
14
23
< >
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" >
18
25
< PaginationArrow
19
26
direction = "left"
20
27
href = { createPageURL ( currentPage - 1 ) }
@@ -47,7 +54,7 @@ export default function Pagination({ totalPages }: { totalPages: number }) {
47
54
href = { createPageURL ( currentPage + 1 ) }
48
55
isDisabled = { currentPage >= totalPages }
49
56
/>
50
- </div> */ }
57
+ </ div >
51
58
</ >
52
59
) ;
53
60
}
0 commit comments