From 12ecc97b07093f3cac6567c70ff75d57b429c674 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Tue, 21 Oct 2025 17:38:01 +0200 Subject: Implement new Santiago region (WIP) --- src/frontend/app/AppContext.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/frontend/app/AppContext.tsx') diff --git a/src/frontend/app/AppContext.tsx b/src/frontend/app/AppContext.tsx index 9013463..1a9b511 100644 --- a/src/frontend/app/AppContext.tsx +++ b/src/frontend/app/AppContext.tsx @@ -7,6 +7,7 @@ import { type ReactNode, } from "react"; import { type LngLatLike } from "maplibre-gl"; +import { type RegionId, DEFAULT_REGION, getRegionConfig, isValidRegion } from "./data/RegionConfig"; export type Theme = "light" | "dark" | "system"; type TableStyle = "regular" | "grouped"; @@ -37,6 +38,9 @@ interface AppContextProps { mapPositionMode: MapPositionMode; setMapPositionMode: (mode: MapPositionMode) => void; + + region: RegionId; + setRegion: (region: RegionId) => void; } // Coordenadas por defecto centradas en Vigo @@ -153,6 +157,29 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { }, [mapPositionMode]); //#endregion + //#region Region + const [region, setRegionState] = useState(() => { + const savedRegion = localStorage.getItem("region"); + if (savedRegion && isValidRegion(savedRegion)) { + return savedRegion; + } + return DEFAULT_REGION; + }); + + const setRegion = (newRegion: RegionId) => { + setRegionState(newRegion); + localStorage.setItem("region", newRegion); + + // Update map to region's default center and zoom + const regionConfig = getRegionConfig(newRegion); + updateMapState(regionConfig.defaultCenter, regionConfig.defaultZoom); + }; + + useEffect(() => { + localStorage.setItem("region", region); + }, [region]); + //#endregion + //#region Map State const [mapState, setMapState] = useState(() => { const savedMapState = localStorage.getItem("mapState"); @@ -253,6 +280,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => { updateMapState, mapPositionMode, setMapPositionMode, + region, + setRegion, }} > {children} -- cgit v1.3