fetchAdditionalTaxaInfo() { const { taxaId } = this.state; const params = { locale: i18n.currentLocale() }; inatjs.taxa.fetch( taxaId, params ).then( ( response ) => { const taxa = response.results[0]; this.setState( { taxaName: capitalizeNames( taxa.preferred_common_name || taxa.name ), observation: { taxon: { default_photo: taxa.default_photo, id: Number( taxaId ), name: taxa.name, preferred_common_name: taxa.preferred_common_name, iconic_taxon_id: taxa.iconic_taxon_id } }, speciesSeenImage: taxa.taxon_photos[0] ? taxa.taxon_photos[0].photo.medium_url : null }, () => this.showMatch() ); } ).catch( () => { this.setError( "taxaInfo" ); } ); }
fetchAdditionalAncestorInfo( ancestor ) { inatjs.taxa.fetch( ancestor.taxon_id ).then( ( response ) => { const taxa = response.results[0]; const speciesSeenImage = taxa.taxon_photos[0] ? taxa.taxon_photos[0].photo.medium_url : null; this.setCommonAncestor( ancestor, speciesSeenImage ); } ).catch( () => { this.setError( "ancestorInfo" ); } ); }
return ( dispatch, getState ) => { const params = { id: getState( ).taxon.taxon.id, per_page: 12 }; inatjs.taxa.wanted( params ).then( response => dispatch( setWanted( response.results ) ), error => { console.log( "[DEBUG] error: ", error ); } ); };
fetchTaxonDetails() { const { id } = this.state; const params = { locale: i18n.currentLocale() }; inatjs.taxa.fetch( id, params ).then( ( response ) => { const taxa = response.results[0]; const commonName = capitalizeNames( taxa.preferred_common_name || taxa.name ); const scientificName = taxa.name; const conservationStatus = taxa.taxon_photos[0].taxon.conservation_status; const ancestors = []; const ranks = ["kingdom", "phylum", "class", "order", "family", "genus"]; taxa.ancestors.forEach( ( ancestor ) => { if ( ranks.includes( ancestor.rank ) ) { ancestors.push( ancestor ); } } ); ancestors.push( { rank: "species", name: scientificName || null, preferred_common_name: commonName || null } ); const photos = []; taxa.taxon_photos.forEach( ( photo ) => { if ( photo.photo.license_code && photos.length < 8 ) { photos.push( photo ); } } ); this.setState( { commonName, scientificName, photos, about: taxa.wikipedia_summary ? i18n.t( "species_detail.wikipedia", { about: taxa.wikipedia_summary.replace( /<[^>]+>/g, "" ) } ) : null, timesSeen: taxa.observations_count, taxaType: taxa.iconic_taxon_name, ancestors, stats: { endangered: conservationStatus ? conservationStatus.status_name : false } } ); } ).catch( () => { // console.log( err, "error fetching taxon details" ); } ); }
return ( dispatch, getState ) => { const s = getState( ); const t = taxon || s.taxon.taxon; const params = Object.assign( { }, options, { preferred_place_id: s.config.preferredPlace ? s.config.preferredPlace.id : null, locale: I18n.locale } ); return inatjs.taxa.fetch( t.id, params ).then( response => { // make sure the charts revert back to the "Seasonality" tab // in case the incoming results have no data for the current tab $( "a[href='#charts-seasonality']" ).tab( "show" ); dispatch( setTaxon( response.results[0] ) ); dispatch( fetchTerms( ) ); } ); };