@@ -73,37 +73,31 @@ export const MapComponent = () => {
7373 const { isDarkMode } = useContext ( DarkModeContext ) ;
7474 const { userLat, userLng } = useUserLocation ( ) ;
7575
76- const [ roomIdToFocus , setRoomIdToFocus ] = useState < string | undefined > (
77- undefined
78- ) ;
76+ const [ roomIdToFocus , setRoomIdToFocus ] = useState < string > ( "" ) ;
77+
78+ const { room } = useRoom ( roomIdToFocus ) ;
7979
80- const [ initialUserCoordinate , setIntialUserCoordinate ] = useState < {
81- lat : number ;
82- lng : number ;
83- } | null > ( null ) ;
80+ // TODO check if I need to only call this once? this is currently getting called every user change
81+ const { geometry } = useMapboxNavigation ( userLat , userLng , room ) ;
8482
8583 useEffect ( ( ) => {
8684 // Run only on client side, no Suspense issues
8785 const params = new URLSearchParams ( window . location . search ) ;
88- setRoomIdToFocus ( params . get ( "roomId" ) ?? undefined ) ;
86+ setRoomIdToFocus ( params . get ( "roomId" ) ?? "" ) ;
8987 } , [ ] ) ;
9088
91- // TODO refactor hook usage here
9289 useEffect ( ( ) => {
9390 if ( ! userLat || ! userLng || ! roomIdToFocus ) return ;
94- const { room } = useRoom ( roomIdToFocus ) ;
95- if ( ! initialUserCoordinate ) {
96- if ( ! room ) return ;
97- const { geometry } = useMapboxNavigation ( userLat , userLng , room ) ;
98-
99- setRouteGeoJSON ( {
100- type : "Feature" ,
101- properties : { } ,
102- geometry,
103- } ) ;
104- setIntialUserCoordinate ( { lat : userLat , lng : userLng } ) ;
105- }
106- } , [ userLat , userLng , roomIdToFocus , initialUserCoordinate ] ) ;
91+ if ( ! room ) return ;
92+
93+ // -33.917347,151.2286926
94+
95+ setRouteGeoJSON ( {
96+ type : "Feature" ,
97+ properties : { } ,
98+ geometry,
99+ } ) ;
100+ } , [ userLat , userLng , roomIdToFocus ] ) ;
107101
108102 const mapRef = useRef < MapRef > ( null ) ;
109103
0 commit comments