eletrotupi / tcc/ frontend/hooks/useNotifications.queries.ts639638a33f393a399e9112ea8bd95a1d9e34d75c
805 B | 21 lines Raw
1
import { useInfiniteQuery } from "@tanstack/react-query";
2

3
import { apiClient } from "@/lib/api";
4

5
export const notificationKeys = {
6
  all: () => ["notifications"] as const,
7
  lists: () => [...notificationKeys.all(), "list"] as const,
8
  infinite: () => [...notificationKeys.lists(), "infinite"] as const,
9
};
10

11
// The inbox reads newest-first and pages with a cursor: each response carries
12
// the next cursor, or null once the last page is reached
13
export const useNotificationsInfinite = (limit = 30) => {
14
  return useInfiniteQuery({
15
    queryKey: notificationKeys.infinite(),
16
    queryFn: ({ pageParam }) =>
17
      apiClient.getNotifications({ cursor: pageParam, limit }),
18
    getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
19
    initialPageParam: undefined as number | undefined,
20
  });
21
};