-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuseGetStudysets.tsx
More file actions
46 lines (43 loc) · 1.56 KB
/
useGetStudysets.tsx
File metadata and controls
46 lines (43 loc) · 1.56 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 { Source, SearchCriteria } from 'pages/Study/Study.types';
import { useQuery } from 'react-query';
import API from 'utils/api';
export const STUDYSET_QUERY_STRING = 'studysets';
const useGetStudysets = (
searchCriteria: Partial<Omit<SearchCriteria, 'dataType'>>,
enabled?: boolean
) => {
return useQuery(
[STUDYSET_QUERY_STRING, { ...searchCriteria }],
() => {
return API.NeurostoreServices.StudySetsService.studysetsGet(
undefined,
searchCriteria.sortBy,
searchCriteria.pageOfResults,
searchCriteria.descOrder,
searchCriteria.pageSize,
searchCriteria.isNested,
searchCriteria.genericSearchStr,
undefined,
undefined,
searchCriteria.showUnique,
searchCriteria.source === Source.ALL ? undefined : searchCriteria.source,
searchCriteria.authorSearch,
searchCriteria.userId
);
},
{
enabled,
select: (axiosResponse) => {
if (axiosResponse?.data?.results) {
axiosResponse.data.results.sort((a, b) => {
const firstStudysetId = a.id as string;
const secondStudysetId = b.id as string;
return firstStudysetId.localeCompare(secondStudysetId);
});
}
return axiosResponse.data;
},
}
);
};
export default useGetStudysets;