aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/contexts/MapContext.tsx
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-24 19:33:49 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-24 19:33:49 +0100
commitcfbb1625e7873264e2ef435cc76fec2b59cf58d8 (patch)
tree092e04e7750064f5ed1bf6aa2ea625c87877e2e8 /src/frontend/app/contexts/MapContext.tsx
parent9ed46bea58dbb81ceada2a957fd1db653fb21e52 (diff)
Refactor map components and improve modal functionality
Diffstat (limited to 'src/frontend/app/contexts/MapContext.tsx')
-rw-r--r--src/frontend/app/contexts/MapContext.tsx41
1 files changed, 12 insertions, 29 deletions
diff --git a/src/frontend/app/contexts/MapContext.tsx b/src/frontend/app/contexts/MapContext.tsx
index db1392c..5fdf676 100644
--- a/src/frontend/app/contexts/MapContext.tsx
+++ b/src/frontend/app/contexts/MapContext.tsx
@@ -9,19 +9,16 @@ import {
import { APP_CONSTANTS } from "~/config/constants";
interface MapState {
- center: LngLatLike;
- zoom: number;
+ paths: Record<string, { center: LngLatLike; zoom: number }>;
userLocation: LngLatLike | null;
hasLocationPermission: boolean;
}
interface MapContextProps {
mapState: MapState;
- setMapCenter: (center: LngLatLike) => void;
- setMapZoom: (zoom: number) => void;
setUserLocation: (location: LngLatLike | null) => void;
setLocationPermission: (hasPermission: boolean) => void;
- updateMapState: (center: LngLatLike, zoom: number) => void;
+ updateMapState: (center: LngLatLike, zoom: number, path: string) => void;
}
const MapContext = createContext<MapContextProps | undefined>(undefined);
@@ -36,8 +33,7 @@ export const MapProvider = ({ children }: { children: ReactNode }) => {
// We might want to ensure we have a fallback if the region changed while the app was closed?
// But for now, let's stick to the existing logic.
return {
- center: parsed.center || APP_CONSTANTS.defaultCenter,
- zoom: parsed.zoom || APP_CONSTANTS.defaultZoom,
+ paths: parsed.paths || {},
userLocation: parsed.userLocation || null,
hasLocationPermission: parsed.hasLocationPermission || false,
};
@@ -46,29 +42,12 @@ export const MapProvider = ({ children }: { children: ReactNode }) => {
}
}
return {
- center: APP_CONSTANTS.defaultCenter,
- zoom: APP_CONSTANTS.defaultZoom,
+ paths: {},
userLocation: null,
hasLocationPermission: false,
};
});
- const setMapCenter = (center: LngLatLike) => {
- setMapState((prev) => {
- const newState = { ...prev, center };
- localStorage.setItem("mapState", JSON.stringify(newState));
- return newState;
- });
- };
-
- const setMapZoom = (zoom: number) => {
- setMapState((prev) => {
- const newState = { ...prev, zoom };
- localStorage.setItem("mapState", JSON.stringify(newState));
- return newState;
- });
- };
-
const setUserLocation = (userLocation: LngLatLike | null) => {
setMapState((prev) => {
const newState = { ...prev, userLocation };
@@ -85,9 +64,15 @@ export const MapProvider = ({ children }: { children: ReactNode }) => {
});
};
- const updateMapState = (center: LngLatLike, zoom: number) => {
+ const updateMapState = (center: LngLatLike, zoom: number, path: string) => {
setMapState((prev) => {
- const newState = { ...prev, center, zoom };
+ const newState = {
+ ...prev,
+ paths: {
+ ...prev.paths,
+ [path]: { center, zoom },
+ },
+ };
localStorage.setItem("mapState", JSON.stringify(newState));
return newState;
});
@@ -115,8 +100,6 @@ export const MapProvider = ({ children }: { children: ReactNode }) => {
<MapContext.Provider
value={{
mapState,
- setMapCenter,
- setMapZoom,
setUserLocation,
setLocationPermission,
updateMapState,