Skip to content

Commit b7f7190

Browse files
committed
refactor Map to use mapbox navigation hook
1 parent a9ee341 commit b7f7190

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

frontend/components/Map.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,33 @@ export const MapComponent = () => {
7777
undefined
7878
);
7979

80+
const [initialUserCoordinate, setIntialUserCoordinate] = useState<{
81+
lat: number;
82+
lng: number;
83+
} | null>(null);
84+
8085
useEffect(() => {
8186
// Run only on client side, no Suspense issues
8287
const params = new URLSearchParams(window.location.search);
8388
setRoomIdToFocus(params.get("roomId") ?? undefined);
89+
}, []);
8490

85-
if (roomIdToFocus) {
86-
const { room } = useRoom(roomIdToFocus);
87-
if (!userLat || !userLng) return;
91+
// TODO refactor hook usage here
92+
useEffect(() => {
93+
if (!userLat || !userLng || !roomIdToFocus) return;
94+
const { room } = useRoom(roomIdToFocus);
95+
if (!initialUserCoordinate) {
8896
if (!room) return;
89-
90-
console.log("TEST");
9197
const { geometry } = useMapboxNavigation(userLat, userLng, room);
9298

9399
setRouteGeoJSON({
94100
type: "Feature",
95101
properties: {},
96102
geometry,
97103
});
104+
setIntialUserCoordinate({ lat: userLat, lng: userLng });
98105
}
99-
}, []);
106+
}, [userLat, userLng, roomIdToFocus, initialUserCoordinate]);
100107

101108
const mapRef = useRef<MapRef>(null);
102109

0 commit comments

Comments
 (0)