diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-18 21:32:28 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-18 21:32:28 +0200 |
| commit | 992c36c6c7ce7e1e732866b3cd4fb8269a905875 (patch) | |
| tree | 15b7ae06b14341929e555ebc126f07d963213104 /web/frontend/ride-filters-logic.ts | |
| parent | 51613971c1e25dedbc808c66b79d15111d250160 (diff) | |
Diffstat (limited to 'web/frontend/ride-filters-logic.ts')
| -rw-r--r-- | web/frontend/ride-filters-logic.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/web/frontend/ride-filters-logic.ts b/web/frontend/ride-filters-logic.ts new file mode 100644 index 0000000..f3593c1 --- /dev/null +++ b/web/frontend/ride-filters-logic.ts @@ -0,0 +1,15 @@ +export type RideFilterRangeFormat = "distance" | "duration" | "cotacol"; +export type RideFilterRangeHandle = "min" | "max"; + +export const formatRideFilterValue = (format: RideFilterRangeFormat, value: number): string => { + if (format === "distance") return `${value} km`; + if (format === "cotacol") return `${value} points`; + const hours = Math.floor(value / 60); + const minutes = value % 60; + return `${hours}h ${String(minutes).padStart(2, "0")}m`; +}; + +export const normalizeRideFilterRange = (min: number, max: number, changed: RideFilterRangeHandle): { min: number; max: number } => { + if (min <= max) return { min, max }; + return changed === "min" ? { min: max, max } : { min, max: min }; +}; |