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