add dynamic loading of paginated endpoints above page_limit

add request classes and fix collection typing for clients, tasks and tags
This commit is contained in:
Gregor Vostrak
2026-02-18 22:32:56 +01:00
parent eed638d0aa
commit 556bbedeca
23 changed files with 386 additions and 185 deletions

View File

@@ -0,0 +1,22 @@
/**
* Fetches all pages from a paginated Laravel API endpoint.
* Uses `meta.last_page` to determine the total number of pages,
* so only a single request is made when all data fits on one page.
*/
export async function fetchAllPages<T>(
fetchPage: (page: number) => Promise<{
data: T[];
meta: { per_page: number; last_page: number };
}>
): Promise<T[]> {
const firstResponse = await fetchPage(1);
const allItems: T[] = [...firstResponse.data];
const { last_page } = firstResponse.meta;
for (let page = 2; page <= last_page; page++) {
const response = await fetchPage(page);
allItems.push(...response.data);
}
return allItems;
}