From 0f579076b67ba3bdcdebe79e9e4b559b3ee65af1 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 20 May 2021 07:28:42 +1000 Subject: [PATCH] Clamp page to max pages (#1403) --- ui/v2.5/src/hooks/ListHook.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/v2.5/src/hooks/ListHook.tsx b/ui/v2.5/src/hooks/ListHook.tsx index 6108c9acb..c1485b157 100644 --- a/ui/v2.5/src/hooks/ListHook.tsx +++ b/ui/v2.5/src/hooks/ListHook.tsx @@ -175,6 +175,14 @@ const RenderList = < const result = useData(filter); const totalCount = getCount(result); const items = getData(result); + const pages = Math.ceil(totalCount / filter.itemsPerPage); + + // handle case where page is more than there are pages + useEffect(() => { + if (pages > 0 && filter.currentPage > pages) { + onChangePage(pages); + } + }, [pages, filter.currentPage, onChangePage]); useEffect(() => { Mousetrap.bind("right", () => { @@ -364,8 +372,6 @@ const RenderList = < return; } - const pages = Math.ceil(totalCount / filter.itemsPerPage); - return ( <> {renderPagination()}