feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s

This commit is contained in:
zv
2026-06-14 15:53:34 +02:00
parent d572c9cc53
commit 2182297adc
45 changed files with 739 additions and 212 deletions

View File

@@ -6,6 +6,8 @@ import type { SelectedLocation } from "@/types/location";
import type { Province } from "@/types/province";
import type { TemperatureUnit, WindSpeedUnit } from "@/types/units";
import { DEFAULT_TEMPERATURE_UNIT, DEFAULT_WIND_SPEED_UNIT } from "@/lib/weather-utils";
import type { WeatherRegion } from "@/types/weather-region";
import { getWeatherRegionForCountryCode } from "@/types/weather-region";
type NotificationProvinceMode = "selected" | "manual";
@@ -61,6 +63,30 @@ export const useWeatherStore = create<WeatherStore>()(
setTemperatureUnit: (unit) => set({ temperatureUnit: unit }),
setWindSpeedUnit: (unit) => set({ windSpeedUnit: unit }),
}),
{ name: "wtr:preferences" },
{
name: "wtr:preferences",
migrate: (persisted) => {
const state = persisted as Partial<WeatherStore> | undefined;
const location = state?.selectedLocation as (Partial<SelectedLocation> & { region?: WeatherRegion }) | null | undefined;
if (!state || !location) return persisted;
const countryCode = location.countryCode ?? (location.province ? "PL" : null);
const region = location.region ?? getWeatherRegionForCountryCode(countryCode);
return {
...state,
selectedLocation: {
...location,
country: location.country ?? (countryCode === "PL" ? "Polska" : null),
countryCode,
admin1: location.admin1 ?? location.province ?? null,
admin2: location.admin2 ?? location.district ?? null,
timezone: location.timezone ?? (countryCode === "PL" ? "Europe/Warsaw" : null),
region,
stationId: location.stationId ?? null,
stationName: location.stationName ?? null,
distanceKm: location.distanceKm ?? null,
},
};
},
},
),
);