Files
iNaturalistReactNative/src/api/projects.js
Amanda Bullington 92fc62b5f8 Projects / ProjectDetails UI (#788)
* Start on project / details UI overhaul

* UI tweak

* Show HTML in ProjDetails; close search bar

* Add OverviewStats and relevant fetches to ProjectDetail

* Allow user to leave/join traditional projects

* Fix tests with mock react-native-paper
2023-09-20 13:09:31 -07:00

113 lines
2.3 KiB
JavaScript

// @flow
import inatjs from "inaturalistjs";
import handleError from "./error";
const FIELDS = {
title: true,
icon: true,
project_type: true
};
const PARAMS = {
fields: FIELDS
};
const DETAIL_FIELDS = {
...FIELDS,
icon_file_name: true,
header_image_url: true,
description: true,
place_id: true,
observation_count: true,
species_count: true
};
const DETAIL_PARAMS = {
fields: DETAIL_FIELDS
};
const fetchProjects = async (
id: number,
params: Object = {},
opts: Object = {}
): Promise<any> => {
try {
const { results } = await inatjs.projects.fetch( id, { ...DETAIL_PARAMS, ...params }, opts );
return results[0];
} catch ( e ) {
return handleError( e );
}
};
const fetchProjectMembers = async (
params: Object = {},
opts: Object = {}
): Promise<any> => {
try {
const response = await inatjs.projects.members( params, opts );
return response.total_results;
} catch ( e ) {
return handleError( e );
}
};
const fetchProjectPosts = async (
params: Object = {},
opts: Object = {}
): Promise<any> => {
try {
const response = await inatjs.projects.posts( params, opts );
return response.total_results;
} catch ( e ) {
return handleError( e );
}
};
const searchProjects = async ( params: Object = {}, opts: Object = {} ): Promise<any> => {
try {
const { results } = await inatjs.projects.search( { ...PARAMS, ...params }, opts );
return results;
} catch ( e ) {
return handleError( e );
}
};
const joinProject = async ( params: Object = {}, opts: Object = {} ): Promise<any> => {
try {
return await inatjs.projects.join( { ...PARAMS, ...params }, opts );
} catch ( e ) {
return handleError( e );
}
};
const leaveProject = async ( params: Object = {}, opts: Object = {} ): Promise<any> => {
try {
return await inatjs.projects.leave( { ...PARAMS, ...params }, opts );
} catch ( e ) {
return handleError( e );
}
};
const fetchMembership = async ( params: Object = {}, opts: Object = {} ): Promise<any> => {
try {
const response = await inatjs.projects.membership( { ...PARAMS, ...params }, opts );
return response.total_results;
} catch ( e ) {
return handleError( e );
}
};
export default searchProjects;
export {
fetchMembership,
fetchProjectMembers,
fetchProjectPosts,
fetchProjects,
joinProject,
leaveProject,
searchProjects
};