From 50d46be6174871f9ef8795fba0e8d0feda81394b Mon Sep 17 00:00:00 2001 From: zv Date: Sun, 14 Jun 2026 11:28:24 +0200 Subject: [PATCH] fix: use custom province dropdown --- components/settings/settings-page.tsx | 63 ++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/components/settings/settings-page.tsx b/components/settings/settings-page.tsx index e99eb4e..9b13fc0 100644 --- a/components/settings/settings-page.tsx +++ b/components/settings/settings-page.tsx @@ -16,7 +16,6 @@ import { decodeBase64UrlKey, deletePushSubscription, fetchVapidPublicKey, savePu import { formatProvinceName, getProvinceForSelection, PROVINCES } from "@/lib/provinces"; import { useWeatherStore } from "@/lib/store"; import { TEMPERATURE_UNITS, WIND_SPEED_UNITS } from "@/lib/weather-utils"; -import type { Province } from "@/types/province"; import type { TemperatureUnit, WindSpeedUnit } from "@/types/units"; type NotificationSupportStatus = "checking" | "unconfigured" | "unsupported" | "needs-install" | "default" | "denied" | "granted"; @@ -120,6 +119,7 @@ export function SettingsPage() { const [isSavingSubscription, setIsSavingSubscription] = useState(false); const [isSendingTestNotification, setIsSendingTestNotification] = useState(false); const [notificationMessage, setNotificationMessage] = useState(null); + const [provinceDropdownOpen, setProvinceDropdownOpen] = useState(false); const { data: stations } = useWeatherStations(); const { data: positions = [] } = useMeteoStationPositions(); const selectedStationId = useWeatherStore((state) => state.selectedStationId); @@ -153,6 +153,7 @@ export function SettingsPage() { const selectedProvince = getProvinceForSelection(selectedLocation?.province, selectedStationId ?? DEFAULT_STATION_ID); const effectiveProvince = provinceMode === "manual" ? manualProvince : selectedProvince; const effectiveProvinceLabel = effectiveProvince ? formatProvinceName(effectiveProvince, language) : t("settings.notifications.noProvince"); + const manualProvinceValue = manualProvince ?? selectedProvince ?? "mazowieckie"; useEffect(() => { const abortController = new AbortController(); @@ -198,6 +199,17 @@ export function SettingsPage() { }; }, [effectiveProvince, language, morningBriefEnabled, notificationCountyTeryt, notificationLatitude, notificationLocationName, notificationLongitude, notificationStatus, notificationsEnabled, temperatureUnit, tomorrowBriefEnabled, vapidPublicKey, windSpeedUnit]); + useEffect(() => { + if (!provinceDropdownOpen) return; + + function handleKeyDown(event: KeyboardEvent) { + if (event.key === "Escape") setProvinceDropdownOpen(false); + } + + window.addEventListener("keydown", handleKeyDown); + return () => window.removeEventListener("keydown", handleKeyDown); + }, [provinceDropdownOpen]); + const notificationStatusLabel = useMemo(() => { switch (notificationStatus) { case "unconfigured": @@ -456,18 +468,49 @@ export function SettingsPage() { {t("settings.notifications.regionManual")} - -