diff options
| author | copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> | 2026-03-13 11:15:36 +0000 |
|---|---|---|
| committer | copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> | 2026-03-13 11:15:36 +0000 |
| commit | e691b6c9a2182ede263dd355d0d31f0f65c62380 (patch) | |
| tree | 953089fa34e46fd63cf92c487a62b4c175d0252c /src/frontend/app/contexts | |
| parent | 8b4252dc937d6c937bd718515f03dd48948a1519 (diff) | |
fix: address code review - clarify [lat,lng] convention, add effect deps, use ref for initial permission"
Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com>
Diffstat (limited to 'src/frontend/app/contexts')
| -rw-r--r-- | src/frontend/app/contexts/MapContext.tsx | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/frontend/app/contexts/MapContext.tsx b/src/frontend/app/contexts/MapContext.tsx index 195c6e6..75851f4 100644 --- a/src/frontend/app/contexts/MapContext.tsx +++ b/src/frontend/app/contexts/MapContext.tsx @@ -117,6 +117,8 @@ export const MapProvider = ({ children }: { children: ReactNode }) => { ); }, [setUserLocation, setLocationPermission, startWatching]); + const hasPermissionRef = useRef(mapState.hasLocationPermission); + // On mount: subscribe to permission changes and auto-start watching if already granted useEffect(() => { if (typeof window === "undefined" || !("geolocation" in navigator)) return; @@ -149,11 +151,11 @@ export const MapProvider = ({ children }: { children: ReactNode }) => { setLocationPermission(false); } permissionStatus.addEventListener("change", onPermChange); - } else if (mapState.hasLocationPermission) { + } else if (hasPermissionRef.current) { startWatching(); } } catch { - if (mapState.hasLocationPermission) { + if (hasPermissionRef.current) { startWatching(); } } @@ -168,8 +170,7 @@ export const MapProvider = ({ children }: { children: ReactNode }) => { } permissionStatus?.removeEventListener("change", onPermChange); }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [startWatching, setLocationPermission]); return ( <MapContext.Provider |
