Add settings page for alert preferences

This commit is contained in:
zv
2026-06-11 18:39:01 +02:00
parent 68fd967f88
commit 531e678922
9 changed files with 344 additions and 10 deletions

View File

@@ -3,14 +3,23 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import type { SelectedLocation } from "@/types/location";
import type { Province } from "@/types/province";
type NotificationProvinceMode = "selected" | "manual";
interface WeatherStore {
favorites: string[];
selectedStationId: string | null;
selectedLocation: SelectedLocation | null;
warningNotificationsEnabled: boolean;
warningNotificationProvinceMode: NotificationProvinceMode;
warningNotificationProvince: Province | null;
toggleFavorite: (id: string) => void;
selectStation: (id: string) => void;
selectLocation: (location: SelectedLocation) => void;
setWarningNotificationsEnabled: (enabled: boolean) => void;
setWarningNotificationProvinceMode: (mode: NotificationProvinceMode) => void;
setWarningNotificationProvince: (province: Province | null) => void;
}
export const useWeatherStore = create<WeatherStore>()(
@@ -19,6 +28,9 @@ export const useWeatherStore = create<WeatherStore>()(
favorites: [],
selectedStationId: null,
selectedLocation: null,
warningNotificationsEnabled: false,
warningNotificationProvinceMode: "selected",
warningNotificationProvince: null,
toggleFavorite: (id) =>
set((state) => ({
favorites: state.favorites.includes(id)
@@ -27,6 +39,9 @@ export const useWeatherStore = create<WeatherStore>()(
})),
selectStation: (id) => set({ selectedStationId: id, selectedLocation: null }),
selectLocation: (location) => set({ selectedStationId: location.stationId, selectedLocation: location }),
setWarningNotificationsEnabled: (enabled) => set({ warningNotificationsEnabled: enabled }),
setWarningNotificationProvinceMode: (mode) => set({ warningNotificationProvinceMode: mode }),
setWarningNotificationProvince: (province) => set({ warningNotificationProvince: province }),
}),
{ name: "wtr:preferences" },
),