This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / webapp / features / collections / lib / queries / useSembleCollectionts.tsx
1.1 kB 38 lines
1import { useSuspenseInfiniteQuery } from '@tanstack/react-query'; 2import { getCollectionsForUrl } from '../dal'; 3import { collectionKeys } from '../collectionKeys'; 4import { CollectionSortField } from '@semble/types'; 5import { getCollectionsSortParams } from '../utils'; 6 7interface Props { 8 url: string; 9 limit?: number; 10 sortBy?: CollectionSortField; 11} 12 13export default function useSembleCollections(props: Props) { 14 const limit = props?.limit ?? 16; 15 16 const collections = useSuspenseInfiniteQuery({ 17 queryKey: [...collectionKeys.bySembleUrl(props.url), props.sortBy], 18 initialPageParam: 1, 19 queryFn: ({ pageParam = 1 }) => { 20 return getCollectionsForUrl(props.url, { 21 page: pageParam, 22 limit, 23 collectionSortBy: props.sortBy, 24 sortOrder: props.sortBy 25 ? getCollectionsSortParams(props.sortBy).sortOrder 26 : undefined, 27 }); 28 }, 29 getNextPageParam: (lastPage) => { 30 if (lastPage.pagination.hasMore) { 31 return lastPage.pagination.currentPage + 1; 32 } 33 return undefined; 34 }, 35 }); 36 37 return collections; 38}