MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / AppPagination

Function AppPagination

webapp/src/components/AppPagination.tsx:13–67  ·  view source on GitHub ↗
({totalCount}: Props)

Source from the content-addressed store, hash-verified

11
12const PAGE_SIZES = [2, 5, 10, 20];
13export default function AppPagination({totalCount}: Props) {
14 const router = useRouter();
15 const searchParams = useSearchParams();
16
17 const pageFromUrl = Number(searchParams.get('page') || 1);
18 const sizeFromUrl = Number(searchParams.get('pageSize') || 5);
19
20 const [currentPage, setCurrentPage] = useState(1);
21 const [pageSize, setPageSize] = useState(5);
22
23 useEffect(() => {
24 if (pageFromUrl === currentPage && sizeFromUrl === pageSize) return;
25
26 const params = new URLSearchParams(searchParams);
27 params.set('page', currentPage.toString());
28 params.set('pageSize', pageSize.toString());
29 router.replace(`?${params.toString()}`, {scroll: false});
30 }, [currentPage, pageSize]);
31
32 return (
33 <div className='flex justify-between items-center pt-3 pb-6 px-6'>
34 <div className='flex items-center gap-2'>
35 <span>Page size: </span>
36 <div className='flex items-center gap-1'>
37
38 {PAGE_SIZES.map((size, i) => (
39 <Button
40 key={i}
41 type='button'
42 variant={size === pageSize ? 'solid' : 'bordered'}
43 isIconOnly
44 size='sm'
45 color='secondary'
46 onPress={() => {
47 setCurrentPage(1);
48 setPageSize(size);
49 }}
50 >
51 {size}
52 </Button>
53 ))}
54
55 </div>
56 </div>
57
58 <Pagination
59 color='secondary'
60 page={currentPage}
61 total={Math.ceil(totalCount / pageSize)}
62 onChange={setCurrentPage}
63 className='cursor-pointer'
64 />
65 </div>
66 );
67}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…