add new shared observationsSort helper + option subset exports

This commit is contained in:
Abbey Campbell
2026-05-27 16:26:30 -07:00
parent 387beec577
commit e20c01dedb
2 changed files with 35 additions and 7 deletions

View 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];
}

View File

@@ -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;