aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/app')
-rw-r--r--src/frontend/app/contexts/MapContext.tsx9
-rw-r--r--src/frontend/app/hooks/useGeolocation.ts5
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) {