From 1de58de8dea8d474acbbc9e62d5bca2cef9e6b3c Mon Sep 17 00:00:00 2001 From: ClarkLach <102780236+ClarkLach@users.noreply.github.com> Date: Sat, 6 Apr 2024 01:46:32 -0400 Subject: [PATCH] Room/User Links on Map --- frontend-next/src/components/app/map/geo.js | 29 +++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend-next/src/components/app/map/geo.js b/frontend-next/src/components/app/map/geo.js index 4453ce6..24daf29 100644 --- a/frontend-next/src/components/app/map/geo.js +++ b/frontend-next/src/components/app/map/geo.js @@ -3,7 +3,6 @@ import { database } from "../../../../firebase-config"; import { ref, get } from "firebase/database"; import { useState, useEffect } from "react"; - // ONLY nearby markers function NearbyRoomMarkers({ loc, user }) { const [markerArr, setMarkerArr] = useState([]); @@ -16,10 +15,12 @@ function NearbyRoomMarkers({ loc, user }) { "/"; // Sorry for the href but doesn't work here - const handleMarkerClick = (name) => { - window.location.href = "/chat?room=" + path + name; + const handleRoomMarkerClick = (roomObj) => { + window.location.href = + "/chat?room=" + path + roomObj.name + "-" + roomObj.timestamp; }; + // Mostly copied Nick's code from before useEffect(() => { if (loc && user) { get(ref(database, `/rooms/${path}`)).then((snapshot) => { @@ -28,13 +29,15 @@ function NearbyRoomMarkers({ loc, user }) { const newMarkers = Object.values(rooms).map((roomObj, index) => { const markerKey = roomObj.path + "-" + index; + console.log("RoomObj", roomObj); return ( + // Want to change this to be something other than markers (or something extra) handleMarkerClick(roomObj.name)} + onClick={() => handleRoomMarkerClick(roomObj)} > ); }); @@ -52,21 +55,31 @@ function NearbyRoomMarkers({ loc, user }) { * @constructor * @prop {JSON} loc - Location Object {latitude, longitude} * @prop {Number} zoom - Zoom Level - * @prop {Boolean} locMarker - Show Location Marker + * @prop {Boolean} moveable - Moveable Map + * @prop {Boolean} markers - Enable Markers * @returns {Map} - Geo Component (As Map) */ export function Geo({ loc, zoom, moveable, markers, user }) { + const handleUserMarkerClick = () => { + window.location.href = "/user?uid=" + user.uid; + } + if (!loc) { return
Getting Location...
; } else { return ( <> - + {zoom && } + {markers && NearbyRoomMarkers({ loc, user })} {user && ( // Shows the user marker - + )} - {NearbyRoomMarkers({ loc, user })} );