()
| 12 | } |
| 13 | |
| 14 | function useCollections(): StacCollectionsHook { |
| 15 | const { stacApi } = useStacApiContext(); |
| 16 | |
| 17 | const fetchCollections = async (): Promise<CollectionsResponse> => { |
| 18 | if (!stacApi) throw new Error('No STAC API configured'); |
| 19 | const response: Response = await stacApi.getCollections(); |
| 20 | return handleStacResponse<CollectionsResponse>(response); |
| 21 | }; |
| 22 | |
| 23 | const { |
| 24 | data: collections, |
| 25 | error, |
| 26 | isLoading, |
| 27 | isFetching, |
| 28 | refetch, |
| 29 | } = useQuery<CollectionsResponse, ApiError>({ |
| 30 | queryKey: generateCollectionsQueryKey(), |
| 31 | queryFn: fetchCollections, |
| 32 | enabled: !!stacApi, |
| 33 | retry: false, |
| 34 | }); |
| 35 | |
| 36 | return { |
| 37 | collections, |
| 38 | refetch, |
| 39 | isLoading, |
| 40 | isFetching, |
| 41 | error, |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | export default useCollections; |
no test coverage detected