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 queryFn: ({ pageParam = 1 }) => {
28 return getGlobalFeed({
29 limit,
30 page: pageParam,
31 urlType: props?.urlType,
32 source: props?.source,
33 activityTypes: props?.activityTypes,
34 includeKnownBots: props?.includeKnownBots,
35 });
36 },
37 getNextPageParam: (lastPage) => {
38 if (lastPage.pagination.hasMore) {
39 return lastPage.pagination.currentPage + 1;
40 }
41 return undefined;
42 },
43 });
44
45 return query;
46}