mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-30 19:52:56 -04:00
* Start using React Query to make remote data requests * Renaming, standardized error handling from API calls, moving code * Fixed messages test; changed useQuery mocking approach * React Query should only retry for network issues * Tried using useAuthenticatedRequest on TaxonDetail * Clear the React Query cache on sign out Co-authored-by: Ken-ichi Ueda <kenichi.ueda@gmail.com>
46 lines
804 B
JavaScript
46 lines
804 B
JavaScript
// @flow
|
|
|
|
import inatjs from "inaturalistjs";
|
|
|
|
import handleError from "./error";
|
|
|
|
const ANCESTOR_FIELDS = {
|
|
name: true,
|
|
preferred_common_name: true,
|
|
rank: true
|
|
};
|
|
|
|
const PHOTO_FIELDS = {
|
|
id: true,
|
|
attribution: true,
|
|
license_code: true,
|
|
url: true
|
|
};
|
|
|
|
const FIELDS = {
|
|
ancestors: ANCESTOR_FIELDS,
|
|
name: true,
|
|
preferred_common_name: true,
|
|
rank: true,
|
|
taxon_photos: {
|
|
photo: PHOTO_FIELDS
|
|
},
|
|
wikipedia_summary: true,
|
|
wikipedia_url: true
|
|
};
|
|
|
|
const PARAMS = {
|
|
fields: FIELDS
|
|
};
|
|
|
|
async function fetchTaxon( id: number, params: Object = {}, opts: Object = {} ): Promise<any> {
|
|
try {
|
|
const { results } = await inatjs.taxa.fetch( id, { ...PARAMS, ...params }, opts );
|
|
return results[0];
|
|
} catch ( e ) {
|
|
return handleError( e );
|
|
}
|
|
}
|
|
|
|
export default fetchTaxon;
|