From 0197a19973940d40a373b8aa68b2791391149cef Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Thu, 25 Dec 2025 02:37:21 +0100 Subject: Implement selecting stop layers to display --- src/frontend/app/contexts/SettingsContext.tsx | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/frontend/app/contexts') diff --git a/src/frontend/app/contexts/SettingsContext.tsx b/src/frontend/app/contexts/SettingsContext.tsx index 6a64b67..1833818 100644 --- a/src/frontend/app/contexts/SettingsContext.tsx +++ b/src/frontend/app/contexts/SettingsContext.tsx @@ -23,6 +23,13 @@ interface SettingsContextProps { setShowTraffic: (show: boolean) => void; showCameras: boolean; setShowCameras: (show: boolean) => void; + + showBusStops: boolean; + setShowBusStops: (show: boolean) => void; + showCoachStops: boolean; + setShowCoachStops: (show: boolean) => void; + showTrainStops: boolean; + setShowTrainStops: (show: boolean) => void; } const SettingsContext = createContext( @@ -141,6 +148,56 @@ export const SettingsProvider = ({ children }: { children: ReactNode }) => { useEffect(() => { localStorage.setItem("showCameras", showCameras.toString()); }, [showCameras]); + + const [showBusStops, setShowBusStops] = useState(() => { + const saved = localStorage.getItem("stopsLayers"); + if (saved) { + try { + const parsed = JSON.parse(saved); + return parsed.bus ?? true; + } catch { + return true; + } + } + return true; + }); + + const [showCoachStops, setShowCoachStops] = useState(() => { + const saved = localStorage.getItem("stopsLayers"); + if (saved) { + try { + const parsed = JSON.parse(saved); + return parsed.coach ?? true; + } catch { + return true; + } + } + return true; + }); + + const [showTrainStops, setShowTrainStops] = useState(() => { + const saved = localStorage.getItem("stopsLayers"); + if (saved) { + try { + const parsed = JSON.parse(saved); + return parsed.train ?? true; + } catch { + return true; + } + } + return true; + }); + + useEffect(() => { + localStorage.setItem( + "stopsLayers", + JSON.stringify({ + bus: showBusStops, + coach: showCoachStops, + train: showTrainStops, + }) + ); + }, [showBusStops, showCoachStops, showTrainStops]); //#endregion return ( @@ -156,6 +213,13 @@ export const SettingsProvider = ({ children }: { children: ReactNode }) => { setShowTraffic, showCameras, setShowCameras, + + showBusStops, + setShowBusStops, + showCoachStops, + setShowCoachStops, + showTrainStops, + setShowTrainStops, }} > {children} -- cgit v1.3