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