This repository has no description
828 B
30 lines
1import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
2import { getMyNotifications } from '../dal';
3import { notificationKeys } from '../notificationKeys';
4
5interface Props {
6 limit?: number;
7 unreadOnly?: boolean;
8}
9
10export default function useMyNotifications(props?: Props) {
11 const limit = props?.limit ?? 15;
12 const unreadOnly = props?.unreadOnly ?? false;
13
14 const query = useSuspenseInfiniteQuery({
15 queryKey: notificationKeys.infinite(limit),
16 staleTime: 10000,
17 initialPageParam: 1,
18 queryFn: ({ pageParam = 1 }) => {
19 return getMyNotifications({ limit, page: pageParam, unreadOnly });
20 },
21 getNextPageParam: (lastPage) => {
22 if (lastPage.pagination.hasMore) {
23 return lastPage.pagination.currentPage + 1;
24 }
25 return undefined;
26 },
27 });
28
29 return query;
30}