This repository has no description
1import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
2import { getGlobalFeed } from '../dal';
3import { feedKeys } from '../feedKeys';
4import { UrlType, ActivitySource, ActivityType } from '@semble/types';
5
6interface Props {
7 limit?: number;
8 urlType?: UrlType;
9 source?: ActivitySource;
10 activityTypes?: ActivityType[];
11 includeKnownBots?: boolean;
12}
13
14export default function useGlobalFeed(props?: Props) {
15 const limit = props?.limit ?? 15;
16
17 const query = useSuspenseInfiniteQuery({
18 queryKey: feedKeys.infinite(
19 limit,
20 props?.urlType,
21 props?.source,
22 props?.activityTypes,
23 props?.includeKnownBots,
24 ),
25 staleTime: 10000,
26 initialPageParam: 1,
27 refetchOnWindowFocus: false,
28 queryFn: ({ pageParam = 1 }) => {
29 return getGlobalFeed({
30 limit,
31 page: pageParam,
32 urlType: props?.urlType,
33 source: props?.source,
34 activityTypes: props?.activityTypes,
35 includeKnownBots: props?.includeKnownBots,
36 });
37 },
38 getNextPageParam: (lastPage) => {
39 if (lastPage.pagination.hasMore) {
40 return lastPage.pagination.currentPage + 1;
41 }
42 return undefined;
43 },
44 });
45
46 return query;
47}