mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-18 12:41:54 -04:00
add new shared observationsSort helper + option subset exports
This commit is contained in:
29
src/sharedHelpers/observationsSort.ts
Normal file
29
src/sharedHelpers/observationsSort.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { ObservationSortAPIParams } from "types/sorting";
|
||||
import { OBSERVATIONS_SORT } from "types/sorting";
|
||||
|
||||
const SORT_TO_API_PARAMS: Record<OBSERVATIONS_SORT, ObservationSortAPIParams> = {
|
||||
[OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST]: { order_by: "created_at", order: "desc" },
|
||||
[OBSERVATIONS_SORT.DATE_UPLOADED_OLDEST]: { order_by: "created_at", order: "asc" },
|
||||
[OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST]: { order_by: "observed_on", order: "desc" },
|
||||
[OBSERVATIONS_SORT.DATE_OBSERVED_OLDEST]: { order_by: "observed_on", order: "asc" },
|
||||
[OBSERVATIONS_SORT.MOST_FAVED]: { order_by: "votes", order: "desc" },
|
||||
};
|
||||
|
||||
export const EXPLORE_OBSERVATIONS_SORT_OPTIONS: OBSERVATIONS_SORT[] = [
|
||||
OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST,
|
||||
OBSERVATIONS_SORT.DATE_UPLOADED_OLDEST,
|
||||
OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST,
|
||||
OBSERVATIONS_SORT.DATE_OBSERVED_OLDEST,
|
||||
OBSERVATIONS_SORT.MOST_FAVED,
|
||||
];
|
||||
|
||||
export const MY_OBSERVATIONS_SORT_OPTIONS: OBSERVATIONS_SORT[] = [
|
||||
OBSERVATIONS_SORT.DATE_UPLOADED_NEWEST,
|
||||
OBSERVATIONS_SORT.DATE_UPLOADED_OLDEST,
|
||||
OBSERVATIONS_SORT.DATE_OBSERVED_NEWEST,
|
||||
OBSERVATIONS_SORT.DATE_OBSERVED_OLDEST,
|
||||
];
|
||||
|
||||
export function sortToApiParams( sort: OBSERVATIONS_SORT ): ObservationSortAPIParams {
|
||||
return SORT_TO_API_PARAMS[sort];
|
||||
}
|
||||
@@ -3,6 +3,12 @@ import type { RealmTaxon } from "realmModels/types";
|
||||
export type SortItemType = "observations" | "taxa";
|
||||
|
||||
export type SortDirection = "asc" | "desc";
|
||||
export type ObservationOrderBy = "created_at" | "observed_on" | "votes";
|
||||
|
||||
export interface ObservationSortAPIParams {
|
||||
order_by: ObservationOrderBy;
|
||||
order: SortDirection;
|
||||
}
|
||||
|
||||
export enum OBSERVATIONS_SORT {
|
||||
DATE_UPLOADED_NEWEST = "DATE_UPLOADED_NEWEST",
|
||||
@@ -15,13 +21,6 @@ export enum OBSERVATIONS_SORT {
|
||||
// eventually this will be a union type that accounts for different types of sorting, i.e. name
|
||||
export type SpeciesSortBy = "count"
|
||||
|
||||
export interface ObservationSort {
|
||||
by:
|
||||
| "created_at"
|
||||
| "observed_on";
|
||||
direction?: SortDirection;
|
||||
}
|
||||
|
||||
export interface SpeciesSort {
|
||||
by: SpeciesSortBy;
|
||||
direction?: SortDirection;
|
||||
|
||||
Reference in New Issue
Block a user