Files
iNaturalistReactNative/src/api/taxa.js
Amanda Bullington d892d755a7 Use React Query to simplify API requests (#166)
* 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>
2022-09-01 18:43:52 -07:00

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;