templates.util.pebble Maven / Gradle / Ivy
import { PageableResult } from "@rocketbase/commons-core";
import { InfiniteData } from '{% if reactQueryVersion.name equals "v4" %}@tanstack/{% endif %}react-query';
export function createPaginationOptions>() {
return {
getPreviousPageParam: ({page } : T) => {
return page !== 0 ? page - 1 : 0;
},
getNextPageParam: ({page, totalPages}: T) => {
return page < totalPages - 1 ? page + 1 : undefined;
},
}
}
export function infiniteTotalElements(
data: InfiniteData>
): number {
if (data && Array.isArray(data?.pages) && data?.pages.length) {
return data.pages[0].totalElements;
}
return 0;
}