-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathuseGetChannelsList.ts
More file actions
46 lines (42 loc) · 1.47 KB
/
useGetChannelsList.ts
File metadata and controls
46 lines (42 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useInfiniteQuery } from '@tanstack/react-query';
import { allChannelsList } from '../../queryKeys';
import { getChannelsList } from '../../services';
import { ChannelsListModelledResponse, ChannelListParams } from '../../types';
import { useSelector } from 'react-redux';
import { UserStoreType } from 'types';
export type UseChannelSearchProps = {
order?: ChannelListParams['order'];
pageSize: ChannelListParams['pageSize'];
chain?: ChannelListParams['chain'];
tag?: ChannelListParams['tag'];
sort?: ChannelListParams['sort'];
subscribed: ChannelListParams['subscribed'];
};
// TODO make it a sdk call in future
export const useGetChannelslist = ({ order, pageSize, sort, chain, tag, subscribed }: UseChannelSearchProps) => {
const { userPushSDKInstance } = useSelector((state: UserStoreType) => {
return state.user;
});
const reactQuery = useInfiniteQuery<ChannelsListModelledResponse>({
queryKey: [allChannelsList, userPushSDKInstance?.account, chain, tag, subscribed],
initialPageParam: 1,
queryFn: ({ pageParam }) =>
getChannelsList({
userPushSDKInstance,
order,
sort,
pageSize,
page: pageParam as number,
chain,
tag,
subscribed,
}),
getNextPageParam: ({ itemcount }, allPages, lastPageParam) => {
if (pageSize * ((lastPageParam as number) + 1) >= itemcount) {
return null;
}
return (lastPageParam as number) + 1;
},
});
return reactQuery;
};