From 3ddda04e78d065314c68ec7851dd508c7020b455 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Thu, 10 Mar 2022 18:07:56 +0100 Subject: [PATCH] feat(ui) - pagination debounce the request --- .../BugFinder/SessionList/SessionList.js | 1 + .../components/ui/Pagination/Pagination.tsx | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/frontend/app/components/BugFinder/SessionList/SessionList.js b/frontend/app/components/BugFinder/SessionList/SessionList.js index a58d483ae..5a76dcffa 100644 --- a/frontend/app/components/BugFinder/SessionList/SessionList.js +++ b/frontend/app/components/BugFinder/SessionList/SessionList.js @@ -135,6 +135,7 @@ export default class SessionList extends React.PureComponent { page={currentPage} totalPages={Math.ceil(total / PER_PAGE)} onPageChange={(page) => this.props.updateCurrentPage(page)} + limit={PER_PAGE} /> {/* void - limit?: number + limit?: number } export default function Pagination(props: Props) { const { page, totalPages, onPageChange, limit = 5 } = props; - const [currentPage, setCurrentPage] = React.useState(page); React.useMemo( () => setCurrentPage(page), [page], ); + const debounceChange = React.useCallback(debounce(onPageChange, 1000), []); + const changePage = (page: number) => { if (page > 0 && page <= totalPages) { - onPageChange(page); setCurrentPage(page); + debounceChange(page); } } - + + const isFirstPage = currentPage === 1; + const isLastPage = currentPage === totalPages; return (
Page of {totalPages}
)