From d025f2ba7aaba775e9eb8df29d7efbdeae5296d2 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 21 Jun 2021 10:54:31 -0700 Subject: [PATCH] Navigate item search by page number The page number is a dropdown now! Wowie! --- src/app/components/PaginationToolbar.js | 63 +++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 5 deletions(-) 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 (