From 94513bb0d9bed5e50691d0c6abdb7f5e4a4dd1f0 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 21 Apr 2024 22:49:23 -0400 Subject: [PATCH] Fixes Across the Board --- frontend-next/src/app/app/page.js | 4 +-- frontend-next/src/app/chat/page.js | 4 +-- frontend-next/src/app/dm/page.js | 2 +- frontend-next/src/app/user/page.js | 4 +-- frontend-next/src/components/app/map/geo.js | 36 +++++++++++-------- .../src/components/app/sidebar/dm.js | 2 +- .../src/components/app/sidebar/home.js | 34 +++++++++--------- 7 files changed, 47 insertions(+), 39 deletions(-) diff --git a/frontend-next/src/app/app/page.js b/frontend-next/src/app/app/page.js index b35b67d..1ac9d45 100644 --- a/frontend-next/src/app/app/page.js +++ b/frontend-next/src/app/app/page.js @@ -7,7 +7,7 @@ import Drawer from '@mui/material/Drawer'; // Firebase Imports import { auth, database } from "../../../firebase-config"; -import { ref, onValue, set } from "firebase/database"; +import { ref, get, set } from "firebase/database"; import { useAuthState } from "react-firebase-hooks/auth" // Component Imports @@ -43,7 +43,7 @@ function Home() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { if (authUser && authLoading === false) { - onValue(ref(database, `users/${authUser.uid}`), (userData) => { + get(ref(database, `users/${authUser.uid}`)).then((userData) => { userData = userData.val(); if (userData) { setUser({...userData}); diff --git a/frontend-next/src/app/chat/page.js b/frontend-next/src/app/chat/page.js index 37a37d6..1aa692b 100644 --- a/frontend-next/src/app/chat/page.js +++ b/frontend-next/src/app/chat/page.js @@ -38,8 +38,8 @@ function Chat() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { - if (authUser && authLoading === false) { - onValue(ref(database, `users/${authUser.uid}`), (userData) => { + if (authUser && authLoading === false && !user) { + get(ref(database, `users/${authUser.uid}`)).then((userData) => { userData = userData.val(); if (userData) { setUser(userData); diff --git a/frontend-next/src/app/dm/page.js b/frontend-next/src/app/dm/page.js index 815da34..f339609 100644 --- a/frontend-next/src/app/dm/page.js +++ b/frontend-next/src/app/dm/page.js @@ -40,7 +40,7 @@ function Chat() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { if (authUser && authLoading === false) { - onValue(ref(database, `users/${authUser.uid}`), (userData) => { + get(ref(database, `users/${authUser.uid}`)).then((userData) => { userData = userData.val(); if (userData) { setUser(userData); diff --git a/frontend-next/src/app/user/page.js b/frontend-next/src/app/user/page.js index eb84533..7e2b9b2 100644 --- a/frontend-next/src/app/user/page.js +++ b/frontend-next/src/app/user/page.js @@ -49,7 +49,7 @@ function UserProfile() { if (authUser && authLoading === false) { const searchParams = new URLSearchParams(document.location.search); var userUID = searchParams.get("uid") - onValue(ref(database, `users/${authUser.uid}`), (userData) => { + get(ref(database, `users/${authUser.uid}`)).then((userData) => { userData = userData.val(); if (userData) { if (userData.uid == userUID) { @@ -70,7 +70,7 @@ function UserProfile() { useEffect(() => { const searchParams = new URLSearchParams(document.location.search); var userUID = searchParams.get("uid") - onValue(ref(database, "/users/" + userUID), (snapshot) => { + get(ref(database, "/users/" + userUID)).then((snapshot) => { setProfileData(snapshot.val()); // Populates array with user's interests diff --git a/frontend-next/src/components/app/map/geo.js b/frontend-next/src/components/app/map/geo.js index 040c447..f230319 100644 --- a/frontend-next/src/components/app/map/geo.js +++ b/frontend-next/src/components/app/map/geo.js @@ -77,25 +77,31 @@ export function Geo({ loc, zoom, moveable, user }) { // Load Nearby Markers - var nearbyMarkers = NearbyMarkers(loc); - if (nearbyMarkers) { - var nearbyMarkers = Object.values(nearbyMarkers).map((roomObj) => { - return ( {window.location.href = "/chat?room=" + roomObj.path + "/" + roomObj.name + "-" + roomObj.timestamp;}} - style={{pointerEvents:'auto'} /* So stupid */} - onMouseOver={() => {setHoverText(roomObj.name);setHovering(true);setHoverAnchor([roomObj.latitude, roomObj.longitude])}} - onMouseOut={() => {setHovering(false)}} - > - - ) + var nearbyMarkers = null; + if (location) { + const path = String(loc.latitude.toFixed(2)).replace(".", "") +"/" +String(loc.longitude.toFixed(2)).replace(".", "") +"/"; + get(ref(database, `/rooms/${path}`)).then((snapshot) => { + if (snapshot.exists()) { + nearbyMarkers = snapshot.val(); + if (nearbyMarkers) { + var nearbyMarkers = Object.values(nearbyMarkers).map((roomObj) => { + return ( {window.location.href = "/chat?room=" + roomObj.path + "/" + roomObj.name + "-" + roomObj.timestamp;}} + style={{pointerEvents:'auto'} /* So stupid */} + onMouseOver={() => {setHoverText(roomObj.name);setHovering(true);setHoverAnchor([roomObj.latitude, roomObj.longitude])}} + onMouseOut={() => {setHovering(false)}} + > + + ) + }) + } + } }) } - } - if (!loc) { return
Getting Location...
; } else { diff --git a/frontend-next/src/components/app/sidebar/dm.js b/frontend-next/src/components/app/sidebar/dm.js index 09b98c6..c32e99c 100644 --- a/frontend-next/src/components/app/sidebar/dm.js +++ b/frontend-next/src/components/app/sidebar/dm.js @@ -11,7 +11,7 @@ export function Sidebar({user, chatRoomObj}) { var path = chatRoomObj.UIDs[0] < chatRoomObj.UIDs[1] ? chatRoomObj.UIDs[0] + "-" + chatRoomObj.UIDs[1] : chatRoomObj.UIDs[1] + "-" + chatRoomObj.UIDs[0]; var activeUsers = [] - onValue(ref(database, `/dms/${path}/users/online`), (snapshot) => { + get(ref(database, `/dms/${path}/users/online`)).then((snapshot) => { if (snapshot.exists()) { var activeUsersJSON = snapshot.val(); for (var activeUser in activeUsersJSON) diff --git a/frontend-next/src/components/app/sidebar/home.js b/frontend-next/src/components/app/sidebar/home.js index 611b3cf..5638e46 100644 --- a/frontend-next/src/components/app/sidebar/home.js +++ b/frontend-next/src/components/app/sidebar/home.js @@ -89,26 +89,28 @@ function classNames(...classes) { * @returns {Object} - App Page Sidebar Component */ export function Sidebar({user,location,loadingLoc}) { - const [friends, setFriends] = useState([]) + const [friends, setFriends] = useState(null) const [friendRequests, setFriendRequests] = useState(null) const [dms, setDMs] = useState((
No DMs
)) - const [myRoomArr, setMyRoomArr] = useState([]) + const [myRoomArr, setMyRoomArr] = useState(null) useEffect(() => { - var myRoomArr = []; - // Add myRooms to Sidebar - for (var room in user.rooms) { - get(ref(database, `/rooms/${user.rooms[room].path}/${user.rooms[room].name}-${user.rooms[room].timestamp}`)).then((snapshot) => { - var newRoom = ( - - ); - myRoomArr.push(newRoom); - }) + if (user && myRoomArr == null) { + var myRoomArr = []; + // Add myRooms to Sidebar + for (var room in user.rooms) { + get(ref(database, `/rooms/${user.rooms[room].path}/${user.rooms[room].name}-${user.rooms[room].timestamp}`)).then((snapshot) => { + var newRoom = ( + + ); + myRoomArr.push(newRoom); + }) + } + setMyRoomArr(myRoomArr) } - setMyRoomArr(myRoomArr) }, []) useEffect(() => { @@ -154,7 +156,7 @@ export function Sidebar({user,location,loadingLoc}) { } }) - }, [user]) + }, []) return (