diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2026-03-16 13:56:06 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2026-03-16 13:56:15 +0100 |
| commit | 8942cf3c705bbc78a6b3317599658e9bb86dd31b (patch) | |
| tree | c02c432dad7b31fa11160f16c221dfac45255920 /src/frontend/app/contexts/MapContext.tsx | |
| parent | 3ce586243a49f34b36d0fe4099bbfb2631610f11 (diff) | |
Add legal document shenanigans
Closes #147
Diffstat (limited to 'src/frontend/app/contexts/MapContext.tsx')
| -rw-r--r-- | src/frontend/app/contexts/MapContext.tsx | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/frontend/app/contexts/MapContext.tsx b/src/frontend/app/contexts/MapContext.tsx index 75851f4..d93fefc 100644 --- a/src/frontend/app/contexts/MapContext.tsx +++ b/src/frontend/app/contexts/MapContext.tsx @@ -25,15 +25,23 @@ interface MapContextProps { const MapContext = createContext<MapContextProps | undefined>(undefined); +const LOCATION_TTL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days + export const MapProvider = ({ children }: { children: ReactNode }) => { const [mapState, setMapState] = useState<MapState>(() => { const savedMapState = localStorage.getItem("mapState"); if (savedMapState) { try { const parsed = JSON.parse(savedMapState); + const locationAge = parsed.userLocationTimestamp + ? Date.now() - parsed.userLocationTimestamp + : Infinity; return { paths: parsed.paths || {}, - userLocation: parsed.userLocation || null, + userLocation: + locationAge < LOCATION_TTL_MS + ? (parsed.userLocation ?? null) + : null, hasLocationPermission: parsed.hasLocationPermission || false, }; } catch (e) { @@ -51,7 +59,11 @@ export const MapProvider = ({ children }: { children: ReactNode }) => { const setUserLocation = useCallback((userLocation: LngLatLike | null) => { setMapState((prev) => { - const newState = { ...prev, userLocation }; + const newState = { + ...prev, + userLocation, + userLocationTimestamp: userLocation ? Date.now() : null, + }; localStorage.setItem("mapState", JSON.stringify(newState)); return newState; }); |
