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 | |
| 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')
| -rw-r--r-- | src/frontend/app/contexts/MapContext.tsx | 9 | ||||
| -rw-r--r-- | src/frontend/app/hooks/useGeolocation.ts | 5 |
2 files changed, 9 insertions, 5 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 diff --git a/src/frontend/app/hooks/useGeolocation.ts b/src/frontend/app/hooks/useGeolocation.ts index 572a40c..878420b 100644 --- a/src/frontend/app/hooks/useGeolocation.ts +++ b/src/frontend/app/hooks/useGeolocation.ts @@ -12,7 +12,10 @@ function lngLatToCoords( loc: LngLatLike ): { latitude: number; longitude: number } { if (Array.isArray(loc)) { - // Stored as [lat, lng] per codebase convention + // This codebase stores location as [latitude, longitude] (not the standard + // MapLibre [lng, lat] GeoJSON order). See MapContext.tsx where arrays are + // set as [position.coords.latitude, position.coords.longitude], and AppMap.tsx + // where getLatitude(center) returns center[0]. return { latitude: loc[0], longitude: loc[1] }; } if ("lat" in loc) { |
