Skip to content

Commit 0457cf2

Browse files
committed
Fix: app sidebar pagination loading items
1 parent 69c4b2e commit 0457cf2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

apps/web/src/app/(app)/@appSidebar/_components/app-sidebar-pages.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ export const AppSidebarPages = ({
3737
const queryOptions = trpc.pages.getPaginated.infiniteQueryOptions(
3838
infinitePagesQueryOptions,
3939
);
40-
const { status, data, fetchNextPage, hasNextPage } = useInfiniteQuery({
41-
...queryOptions,
42-
getNextPageParam: ({ nextCursor }) => {
43-
return nextCursor;
44-
},
45-
});
40+
const { status, data, fetchNextPage, hasNextPage, isFetchingNextPage } =
41+
useInfiniteQuery({
42+
...queryOptions,
43+
getNextPageParam: ({ nextCursor }) => {
44+
return nextCursor;
45+
},
46+
});
4647

4748
const pages = data?.pages?.flatMap((page) => page.items) ?? [];
4849

@@ -72,7 +73,7 @@ export const AppSidebarPages = ({
7273
tooltip="Pages"
7374
onClick={handlePagesClick}
7475
>
75-
{status === "pending" ? (
76+
{isFetchingNextPage ? (
7677
<Loader2 className="size-3 animate-spin" />
7778
) : (
7879
<BookOpen />
@@ -102,9 +103,21 @@ export const AppSidebarPages = ({
102103
fetchNextPage();
103104
}
104105
}}
106+
rangeChanged={(range) => {
107+
if (
108+
status === "success" &&
109+
hasNextPage &&
110+
isOpen &&
111+
range?.startIndex === 0 &&
112+
range?.endIndex >= pages.length - 1 &&
113+
pages.length > 0
114+
) {
115+
fetchNextPage();
116+
}
117+
}}
105118
components={{
106119
Footer: () =>
107-
status === "pending" ? (
120+
isFetchingNextPage ? (
108121
<AppSidebarPageItemSkeleton className="ml-3.5 border-sidebar-border border-l ps-2.5" />
109122
) : null,
110123
}}

0 commit comments

Comments
 (0)