From 322f95e42e74b470a3c05c7733ef1a70c520942d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 2 Nov 2023 11:14:13 -0500 Subject: [PATCH] feat: rows per page --- src/app/tools/ratings/page.tsx | 48 ++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/app/tools/ratings/page.tsx b/src/app/tools/ratings/page.tsx index 0c1c4c01f..74b461107 100644 --- a/src/app/tools/ratings/page.tsx +++ b/src/app/tools/ratings/page.tsx @@ -1,6 +1,10 @@ 'use client'; -import { MagnifyingGlassIcon } from '@radix-ui/react-icons'; +import { + CaretLeftIcon, + CaretRightIcon, + MagnifyingGlassIcon, +} from '@radix-ui/react-icons'; import { Button, Flex, @@ -26,7 +30,7 @@ import { getArchivedRatingsLeaderboardAPI } from '../../../core/blitzkrieg/getAr import { numberFetcher } from '../../../core/blitzkrieg/numberFetcher'; import { noArrows } from './page.css'; -const ROWS_PER_PAGE = 64; +const ROWS_OPTIONS = [5, 10, 25, 50, 100]; const useUsernameCache = create>>(() => ({ asia: {}, @@ -42,6 +46,7 @@ const useClanCache = create>>( ); export default function Page() { + const [rowsPerPage, setRowsPerPage] = useState(ROWS_OPTIONS[2]); const usernameCache = useUsernameCache(); const clanCache = useClanCache(); const [region, setRegion] = useState('com'); @@ -70,8 +75,8 @@ export default function Page() { const [page, setPage] = useState(0); const pageInput = useRef(null); const playerSlice = players.data?.slice( - page * ROWS_PER_PAGE, - page * ROWS_PER_PAGE + ROWS_PER_PAGE, + page * rowsPerPage, + page * rowsPerPage + rowsPerPage, ); cachePage(page - 1); @@ -80,7 +85,7 @@ export default function Page() { function cachePage(page: number) { const ids = players.data - ?.slice(page * ROWS_PER_PAGE, page * ROWS_PER_PAGE + ROWS_PER_PAGE) + ?.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) .map(({ id }) => id) .filter((id) => !(id in usernameCache[region])); @@ -234,14 +239,29 @@ export default function Page() { + + setRowsPerPage(parseInt(value))} + defaultValue={`${rowsPerPage}`} + > + + + + {ROWS_OPTIONS.map((size) => ( + + {size} per page + + ))} + + + - Page - out of {Math.ceil((players.data?.length ?? 0) / ROWS_PER_PAGE)} + out of {Math.ceil((players.data?.length ?? 0) / rowsPerPage)} - @@ -291,9 +310,10 @@ export default function Page() { {playerSlice?.map((player, index) => (