Skip to content

Commit

Permalink
fix(handbook): allow any page size
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeff95 committed Oct 30, 2024
1 parent 6ce5415 commit 0f74d09
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/components/pages/handbook/common/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,30 @@ export const getHandbookEntries = async (
context: keyof typeof EXCLUSIONS = 'index'
) => {
try {
const res = await storyblok.get('cdn/stories', {
starts_with: 'handbook',
cv: Date.now(),
version,
excluding_fields: EXCLUSIONS[context].join(','),
page: 1,
per_page: 100 // FIXME: allow more than 100 entries.
});
let loop = true;
let page = 1;
const results: ISbStoryData<HandbookStoryblok>[] = [];

return res.data.stories as ISbStoryData<HandbookStoryblok>[];
do {
const res = await storyblok.get('cdn/stories', {
starts_with: 'handbook',
cv: Date.now(),
version,
excluding_fields: EXCLUSIONS[context].join(','),
page,
per_page: 100
});

results.push(...res.data.stories);

if (results.length >= res.total) {
loop = false;
}

page++;
} while (loop);

return results;
} catch (err) {
throw new Error('Failed to fetch Handbook entries', { cause: err });
}
Expand Down

0 comments on commit 0f74d09

Please sign in to comment.