This repository has no description
1import { useSuspenseInfiniteQuery } from '@tanstack/react-query';
2import { getGemsActivityFeed } 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}
12
13export default function useGemsFeed(props?: Props) {
14 const limit = props?.limit ?? 15;
15
16 const query = useSuspenseInfiniteQuery({
17 queryKey: feedKeys.gemsInfinite(
18 limit,
19 props?.urlType,
20 props?.source,
21 props?.activityTypes,
22 ),
23 staleTime: 10000,
24 initialPageParam: 1,
25 queryFn: ({ pageParam = 1 }) => {
26 return getGemsActivityFeed({
27 limit,
28 page: pageParam,
29 urlType: props?.urlType,
30 source: props?.source,
31 activityTypes: props?.activityTypes,
32 });
33 },
34 getNextPageParam: (lastPage) => {
35 if (lastPage.pagination.hasMore) {
36 return lastPage.pagination.currentPage + 1;
37 }
38 return undefined;
39 },
40 });
41
42 return query;
43}