Clamp page to max pages (#1403)

This commit is contained in:
WithoutPants
2021-05-20 07:28:42 +10:00
committed by GitHub
parent 81058a7807
commit 0f579076b6

View File

@@ -175,6 +175,14 @@ const RenderList = <
const result = useData(filter); const result = useData(filter);
const totalCount = getCount(result); const totalCount = getCount(result);
const items = getData(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(() => { useEffect(() => {
Mousetrap.bind("right", () => { Mousetrap.bind("right", () => {
@@ -364,8 +372,6 @@ const RenderList = <
return; return;
} }
const pages = Math.ceil(totalCount / filter.itemsPerPage);
return ( return (
<> <>
{renderPagination()} {renderPagination()}