Skip to content

Commit

Permalink
fix: load more (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt authored Feb 14, 2025
1 parent dad8460 commit f07a403
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions packages/frontend/utils/dataHooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ export function useProjectInfiniteSWR(key: string, ...args: any[]) {
const { data, isLoading, isValidating, size, setSize, mutate } =
useSWRInfinite(getKey, ...(args as [any]));

const total = data?.[0]?.total;
const items = data?.map((d) => d?.data).flat();
const hasMore = items && items.length === PAGE_SIZE * size;

function loadMore() {
const hasMore = items && items?.length < total;

if (hasMore) {
setSize((size) => size + 1);
}
}

return {
data: items,
total,
isLoading,
isValidating,
loadMore,
Expand Down

0 comments on commit f07a403

Please sign in to comment.