Skip to content

Commit 451fcce

Browse files
committed
fix(notifications): pass cursor so infinite list advances past page 1
useNotificationsList ignored pageParam and re-fetched the first page on every fetchNextPage; thread the cursor through like useActivityFeed. Add a regression test asserting page 2 sends the prior nextCursor. Audit: F001
1 parent 97c5dca commit 451fcce

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

apps/ui/src/features/notifications/Notifications.list.queries.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,37 @@ describe("useNotificationsList", () => {
7070
});
7171
expect(result.current.data?.pages[0]?.items[0]?.id).toBe("n1");
7272
});
73+
74+
it("sends the previous page's cursor when fetching the next page", async () => {
75+
apiMock.GET.mockResolvedValueOnce({
76+
data: { items: [makeNotification({ id: "n1" })], nextCursor: "p1" },
77+
response: {}
78+
}).mockResolvedValueOnce({
79+
data: { items: [makeNotification({ id: "n2" })], nextCursor: null },
80+
response: {}
81+
});
82+
const { Wrapper } = makeWrapper();
83+
const { result } = renderHook(() => useNotificationsList(), {
84+
wrapper: Wrapper
85+
});
86+
87+
await waitFor(() => {
88+
expect(result.current.isSuccess).toBe(true);
89+
});
90+
91+
await result.current.fetchNextPage();
92+
93+
await waitFor(() => {
94+
expect(apiMock.GET).toHaveBeenCalledTimes(2);
95+
});
96+
expect(apiMock.GET).toHaveBeenNthCalledWith(
97+
2,
98+
"/api/v1/notifications/",
99+
expect.objectContaining({
100+
params: expect.objectContaining({
101+
query: expect.objectContaining({ cursor: "p1" })
102+
})
103+
})
104+
);
105+
});
73106
});

apps/ui/src/features/notifications/Notifications.list.queries.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ export function useNotificationsList(
2525
return useInfiniteQuery({
2626
queryKey: [...NOTIFICATIONS_QUERY_KEYS.list, status ?? "all"] as const,
2727
initialPageParam: INITIAL_LIST_CURSOR,
28-
queryFn: async () => {
28+
queryFn: async ({ pageParam }) => {
2929
const { data } = await apiClient.GET("/api/v1/notifications/", {
3030
params: {
3131
query: {
3232
status,
33-
limit: String(NOTIFICATIONS_LIST_PAGE_SIZE)
33+
limit: String(NOTIFICATIONS_LIST_PAGE_SIZE),
34+
cursor: pageParam
3435
}
3536
}
3637
});

0 commit comments

Comments
 (0)