feat: add weather unit preferences
Some checks failed
CI / Lint, test, typecheck and build (push) Has been cancelled
Some checks failed
CI / Lint, test, typecheck and build (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ import { AlertTriangle, Droplets, Gauge, MapPin, Navigation, Umbrella, Wind } fr
|
||||
import {
|
||||
calculateFeelsLike,
|
||||
formatDateTime,
|
||||
formatDistance,
|
||||
formatHumidity,
|
||||
formatPressure,
|
||||
formatRainfall,
|
||||
@@ -49,6 +50,9 @@ export function WeatherHero({
|
||||
const { language, t } = useI18n();
|
||||
const temperatureUnit = useWeatherStore((state) => state.temperatureUnit);
|
||||
const windSpeedUnit = useWeatherStore((state) => state.windSpeedUnit);
|
||||
const precipitationUnit = useWeatherStore((state) => state.precipitationUnit);
|
||||
const pressureUnit = useWeatherStore((state) => state.pressureUnit);
|
||||
const distanceUnit = useWeatherStore((state) => state.distanceUnit);
|
||||
const [devEffectOverride, setDevEffectOverride] = useState<DevWeatherEffectOverride | null>(null);
|
||||
const displayedLocationName = locationName ?? station.name;
|
||||
const hasGlobalModel = currentWeather?.coverage === "global-model";
|
||||
@@ -61,6 +65,7 @@ export function WeatherHero({
|
||||
distanceKm !== undefined &&
|
||||
distanceKm !== null &&
|
||||
distanceKm >= 30;
|
||||
const formattedDistance = formatDistance(distanceKm ?? null, language, distanceUnit);
|
||||
const displayedStation = currentWeather
|
||||
? {
|
||||
...station,
|
||||
@@ -91,9 +96,13 @@ export function WeatherHero({
|
||||
: currentWeather?.precipitation10m !== null && currentWeather?.precipitation10m !== undefined
|
||||
? t("weather.rainfall10m")
|
||||
: t("weather.rainfallTotal"),
|
||||
value: formatRainfall(displayedStation.rainfall, language),
|
||||
value: formatRainfall(displayedStation.rainfall, language, precipitationUnit),
|
||||
},
|
||||
{
|
||||
icon: Gauge,
|
||||
label: t("weather.pressure"),
|
||||
value: formatPressure(displayedStation.pressure, language, pressureUnit),
|
||||
},
|
||||
{ icon: Gauge, label: t("weather.pressure"), value: formatPressure(displayedStation.pressure, language) },
|
||||
];
|
||||
const effectPrecipitation10m =
|
||||
devEffectOverride === "rain" || devEffectOverride === "thunderstorm"
|
||||
@@ -149,16 +158,16 @@ export function WeatherHero({
|
||||
: hasFullHybridAnalysis
|
||||
? t("location.heroHybridSource", { location: displayedLocationName })
|
||||
: hasPartialHybridAnalysis
|
||||
? t("location.heroHybridPartial", { station: station.name, distance: distanceKm ?? 0 })
|
||||
? t("location.heroHybridPartial", { station: station.name, distance: formattedDistance })
|
||||
: locationName
|
||||
? t("location.heroStationFallbackWithDistance", {
|
||||
station: station.name,
|
||||
distance: distanceKm ?? 0,
|
||||
distance: formattedDistance,
|
||||
})
|
||||
: t("location.heroStationFallback", { station: station.name })}
|
||||
</p>
|
||||
{hasFullHybridAnalysis && locationName && (
|
||||
<p>{t("location.heroNearestStation", { station: station.name, distance: distanceKm ?? 0 })}</p>
|
||||
<p>{t("location.heroNearestStation", { station: station.name, distance: formattedDistance })}</p>
|
||||
)}
|
||||
{hasDistantFallback && (
|
||||
<p className="flex items-start gap-1.5 text-warning">
|
||||
|
||||
Reference in New Issue
Block a user