diff --git a/src/app/components/PaginationToolbar.js b/src/app/components/PaginationToolbar.js index 1744f9c..37a0f14 100644 --- a/src/app/components/PaginationToolbar.js +++ b/src/app/components/PaginationToolbar.js @@ -1,11 +1,12 @@ import React from "react"; -import { Box, Button, Flex } from "@chakra-ui/react"; -import { Link, useLocation } from "react-router-dom"; +import { Box, Button, Flex, Select } from "@chakra-ui/react"; +import { Link, useHistory, useLocation } from "react-router-dom"; const PER_PAGE = 30; function PaginationToolbar({ isLoading, totalCount, ...props }) { const { search } = useLocation(); + const history = useHistory(); const currentOffset = parseInt(new URLSearchParams(search).get("offset")) || 0; @@ -26,6 +27,18 @@ function PaginationToolbar({ isLoading, totalCount, ...props }) { const nextPageUrl = "?" + nextPageSearchParams.toString(); const nextPageIsDisabled = isLoading || nextPageOffset >= totalCount; + const goToPageNumber = React.useCallback( + (newPageNumber) => { + const newPageIndex = newPageNumber - 1; + const newPageOffset = newPageIndex * PER_PAGE; + + const newPageSearchParams = new URLSearchParams(search); + newPageSearchParams.set("offset", newPageOffset); + history.push({ search: newPageSearchParams.toString() }); + }, + [search, history] + ); + return (