optimize code

Signed-off-by: Andreas Berger <andreas@berger-ecommerce.com>
This commit is contained in:
Andreas Berger
2025-01-17 16:21:44 +01:00
parent 572fa29995
commit cf02a9ce06
@@ -37,14 +37,14 @@ export function OffsetPaginatedCatalogTable(
);
useEffect(() => {
if (clientPagination) {
if (clientPagination || !setOffset) {
return;
}
if (totalItems && page * limit >= totalItems) {
setOffset?.(Math.max(0, totalItems - limit));
} else {
setOffset?.(Math.max(0, page * limit));
let newOffset = page * limit;
if (totalItems && newOffset >= totalItems) {
newOffset = totalItems - limit;
}
setOffset(Math.max(0, newOffset));
}, [setOffset, page, limit, totalItems, clientPagination]);
const showPagination = (totalItems ?? data.length) > limit;