11import { useStore } from "@nanostores/react" ;
2- import { defaultUnit } from "@/lib/context" ;
2+ import { distance , point } from "@turf/turf" ;
3+
34import { LatitudeLongitude } from "@/components/LatLngPicker" ;
45import { Label } from "@/components/ui/label" ;
56import { ToggleGroup , ToggleGroupItem } from "@/components/ui/toggle-group" ;
7+ import { defaultUnit } from "@/lib/context" ;
68import {
79 hiderMode ,
810 isLoading ,
@@ -15,17 +17,6 @@ import type { ThermometerQuestion } from "@/maps/schema";
1517
1618import { QuestionCard } from "./base" ;
1719
18- /* ---- distance helpers (turf) ---- */
19- import distance from "@turf/distance" ;
20- import { point } from "@turf/helpers" ;
21- /* -------------------------------- */
22-
23- const VALID_UNITS = [ "miles" , "kilometers" , "meters" ] as const ;
24- type ValidUnit = ( typeof VALID_UNITS ) [ number ] ;
25-
26- const normalizeUnit = ( unit : string ) : ValidUnit =>
27- VALID_UNITS . includes ( unit as ValidUnit ) ? ( unit as ValidUnit ) : "miles" ;
28-
2920export const ThermometerQuestionComponent = ( {
3021 data,
3122 questionKey,
@@ -42,9 +33,8 @@ export const ThermometerQuestionComponent = ({
4233 const $questions = useStore ( questions ) ;
4334 const $isLoading = useStore ( isLoading ) ;
4435
45- // normalize external string into something turf accepts
4636 const $defaultUnit = useStore ( defaultUnit ) ;
47- const DISTANCE_UNIT = normalizeUnit ( $defaultUnit ?? "miles" ) ;
37+ const DISTANCE_UNIT = $defaultUnit ?? "miles" ;
4838
4939 const label = `Thermometer
5040 ${
@@ -64,16 +54,16 @@ export const ThermometerQuestionComponent = ({
6454 ? distance (
6555 point ( [ data . lngA ! , data . latA ! ] ) ,
6656 point ( [ data . lngB ! , data . latB ! ] ) ,
67- { units : DISTANCE_UNIT }
57+ { units : DISTANCE_UNIT } ,
6858 )
6959 : null ;
7060
7161 const unitLabel =
7262 DISTANCE_UNIT === "meters"
7363 ? "Meters"
7464 : DISTANCE_UNIT === "kilometers"
75- ? "KM"
76- : "Miles" ;
65+ ? "KM"
66+ : "Miles" ;
7767
7868 return (
7969 < QuestionCard
0 commit comments