From 0d4787ccfb8de26a5880c72d090dd741c1871ff1 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 7 Apr 2024 22:37:35 -0400 Subject: [PATCH 1/7] Bug Fix - Profile Loading --- frontend-next/src/app/user/page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend-next/src/app/user/page.js b/frontend-next/src/app/user/page.js index 142783d..07acab1 100644 --- a/frontend-next/src/app/user/page.js +++ b/frontend-next/src/app/user/page.js @@ -108,7 +108,7 @@ function UserProfile() { return (
- {isAuthenticated && ( + {(isAuthenticated && profileData) && (
{/* Left Side of Page */}
-- 2.52.0 From 5629dc88362d14dd60ab32a13e28056ef4a45910 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 7 Apr 2024 23:31:18 -0400 Subject: [PATCH 2/7] Bug Fix - Profile Editing --- frontend-next/src/components/app/profile/ProfileEdit.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend-next/src/components/app/profile/ProfileEdit.js b/frontend-next/src/components/app/profile/ProfileEdit.js index 5845302..6a3895c 100644 --- a/frontend-next/src/components/app/profile/ProfileEdit.js +++ b/frontend-next/src/components/app/profile/ProfileEdit.js @@ -45,12 +45,11 @@ export function ProfileEdit({ profileData, user, onSave }) { } ); } else { - for (var key in data) { - if (data[key] == "") { + for (var key in profileData) { + if (data[key] == "" || (key == "pfp" && data[key].length == 0)) { data[key] = profileData[key]; } } - data.pfp = profileData.pfp; handleEditState(false); update(ref(database, `users/${user.uid}`), data); } -- 2.52.0 From ce5add287922af71b4e5873f96b555ef6542d80b Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 7 Apr 2024 23:33:27 -0400 Subject: [PATCH 3/7] Bug Fix - Build Error --- frontend-next/.eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend-next/.eslintrc.json b/frontend-next/.eslintrc.json index b256ceb..1082ea1 100644 --- a/frontend-next/.eslintrc.json +++ b/frontend-next/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["next/babel","next/core-web-vitals" ], + "extends": ["next/core-web-vitals" ], "rules": { "no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }], "jsx-a11y/alt-text": "off", -- 2.52.0 From c3c76b66c91a5f9ad57c1ff4037867f773cf2b1e Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 7 Apr 2024 23:45:12 -0400 Subject: [PATCH 4/7] Bug Fix - Restore Undid Change --- frontend-next/.eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend-next/.eslintrc.json b/frontend-next/.eslintrc.json index 1082ea1..a12e071 100644 --- a/frontend-next/.eslintrc.json +++ b/frontend-next/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": ["next/core-web-vitals" ], + "extends": ["next/babel", "next/core-web-vitals"], "rules": { "no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }], "jsx-a11y/alt-text": "off", -- 2.52.0 From 3e354800ddf3566c7be98c04960bccc55e4cea99 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Sun, 7 Apr 2024 23:59:29 -0400 Subject: [PATCH 5/7] Bug Fix - DM List --- frontend-next/src/components/app/sidebar/home.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend-next/src/components/app/sidebar/home.js b/frontend-next/src/components/app/sidebar/home.js index 5f73074..5745b1b 100644 --- a/frontend-next/src/components/app/sidebar/home.js +++ b/frontend-next/src/components/app/sidebar/home.js @@ -92,7 +92,7 @@ export function Sidebar({user,location,loadingLoc}) { const [nearbyArrReady, setNearbyArrReady] = useState(false) const [friends, setFriends] = useState([]) const [friendRequests, setFriendRequests] = useState(null) - const [dms, setDMs] = useState(null) + const [dms, setDMs] = useState((
No DMs
)) // Add myRooms to Sidebar var myRoomArr = []; for (var room in user.rooms) { @@ -164,18 +164,17 @@ export function Sidebar({user,location,loadingLoc}) { get(ref(database, `/users/${dmsList[dmRoom].UIDs[1]}`)).then((snapshot) => { var friendObj = snapshot.val() dmArr.push(); + setDMs(dmArr); }) } else if (user.uid == dmsList[dmRoom].UIDs[1]) { get(ref(database, `/users/${dmsList[dmRoom].UIDs[0]}`)).then((snapshot) => { var friendObj = snapshot.val() dmArr.push(); + setDMs(dmArr); }) } } - if (dmArr.length == 0) { - dmArr.push(
No DMs
); - } - setDMs(dmArr); + }) }, [user]) -- 2.52.0 From bc25b0e6947771a7f521bfbd63b6bc38050462c3 Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Mon, 8 Apr 2024 00:08:21 -0400 Subject: [PATCH 6/7] Bug Fix - Unauth Redirect --- frontend-next/src/app/app/page.js | 8 +++++--- frontend-next/src/app/chat/page.js | 8 +++++--- frontend-next/src/app/dm/page.js | 24 +++++++++++++----------- frontend-next/src/app/user/page.js | 24 ++++++++++++++---------- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/frontend-next/src/app/app/page.js b/frontend-next/src/app/app/page.js index 521d193..4120c2c 100644 --- a/frontend-next/src/app/app/page.js +++ b/frontend-next/src/app/app/page.js @@ -27,7 +27,7 @@ function Home() { // State variables for app page const [user, setUser] = useState(null); // user data const [loadingLoc, setLoadingLoc] = useState(true); // location variable loading, true = loading, false = finished loading - const [authUser] = useAuthState(auth) // auth user object (used to obtain other user object) + const [authUser, authLoading] = useAuthState(auth) // auth user object (used to obtain other user object) const [drawerOpen, setDrawerOpen] = useState(true); // drawer open state const [coords, setCoords] = useState(null) @@ -42,7 +42,7 @@ function Home() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { - if (authUser) { + if (authUser && authLoading === false) { onValue(ref(database, `users/${authUser.uid}`), (userData) => { userData = userData.val(); if (userData) { @@ -51,8 +51,10 @@ function Home() { window.location.href = "/onboarding"; } }); + } else if (authLoading === false) { + window.location.href = "/login"; } - }, [authUser]) + }, [authLoading]) useEffect(() => { Geolocation.getCurrentPosition().then((position) => { diff --git a/frontend-next/src/app/chat/page.js b/frontend-next/src/app/chat/page.js index 9421a3c..3fed1f1 100644 --- a/frontend-next/src/app/chat/page.js +++ b/frontend-next/src/app/chat/page.js @@ -24,7 +24,7 @@ function Chat() { const [user, setUser] = useState(null); // user data const [chatRoomObj, setChatRoomObj] = useState(null); // Current chatroom object const [doneLoading, setDoneLoading] = useState(false) // is the page done loading or not - const [authUser] = useAuthState(auth) // auth user object (used to obtain other user object) + const [authUser, authLoading] = useAuthState(auth) // auth user object (used to obtain other user object) const [drawerOpen, setDrawerOpen] = useState(true); // drawer open state var windowSize = useWindowSize() @@ -38,7 +38,7 @@ function Chat() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { - if (authUser) { + if (authUser && authLoading === false) { onValue(ref(database, `users/${authUser.uid}`), (userData) => { userData = userData.val(); if (userData) { @@ -47,8 +47,10 @@ function Chat() { window.location.href = "/onboarding"; } }); + } else if (authLoading === false) { + window.location.href = "/login"; } - }, [authUser]) + }, [authLoading]) // Users URL params to load proper chatroom, then logs the user into that room useEffect(() => { diff --git a/frontend-next/src/app/dm/page.js b/frontend-next/src/app/dm/page.js index d2487a5..f71beb2 100644 --- a/frontend-next/src/app/dm/page.js +++ b/frontend-next/src/app/dm/page.js @@ -24,7 +24,7 @@ function Chat() { const [user, setUser] = useState(null); // user data const [chatRoomObj, setChatRoomObj] = useState(null); // Current chatroom object const [doneLoading, setDoneLoading] = useState(false) // is the page done loading or not - const [authUser] = useAuthState(auth) // auth user object (used to obtain other user object) + const [authUser, authLoading] = useAuthState(auth) // auth user object (used to obtain other user object) const [drawerOpen, setDrawerOpen] = useState(true); // drawer open state var windowSize = useWindowSize() @@ -38,17 +38,19 @@ function Chat() { // Authentication Verification / Redirection if Profile Data not Filled out useEffect(() => { - if (authUser) { - onValue(ref(database, `users/${authUser.uid}`), (userData) => { - userData = userData.val(); - if (userData) { - setUser(userData); - } else { - window.location.href = "/onboarding"; - } - }); + if (authUser && authLoading === false) { + onValue(ref(database, `users/${authUser.uid}`), (userData) => { + userData = userData.val(); + if (userData) { + setUser(userData); + } else { + window.location.href = "/onboarding"; + } + }); + } else if (authLoading === false) { + window.location.href = "/login"; } - }, [authUser]) + }, [authLoading]) // Users URL params to load proper chatroom, then logs the user into that room useEffect(() => { diff --git a/frontend-next/src/app/user/page.js b/frontend-next/src/app/user/page.js index 07acab1..df8364d 100644 --- a/frontend-next/src/app/user/page.js +++ b/frontend-next/src/app/user/page.js @@ -3,10 +3,12 @@ import { useState, useEffect } from "react"; import { auth, database } from "../../../firebase-config"; import { ref, onValue, get } from "firebase/database"; -import { onAuthStateChanged } from "firebase/auth"; +import { useAuthState } from "react-firebase-hooks/auth" + // Refactored Component Imports + // Data Structure Imports import { ProfileRoom } from "../../components/app/profile/ProfileRoom"; import { ProfileEdit } from "../../components/app/profile/ProfileEdit"; @@ -31,6 +33,8 @@ function UserProfile() { const [isOwner, setIsOwner] = useState(false); // Determines if user is owner of profile const [friends, setFriends] = useState(false); // is user a friend? const [isPending, setPending] = useState(false); // is friend request pending? + const [authUser, authLoading] = useAuthState(auth) // auth user object (used to obtain other user object) + // Handles Edit State in Component, shares useState with ProfileEdit const [isEditing, setIsEditing] = useState(false); @@ -40,25 +44,25 @@ function UserProfile() { // Authentication useEffect(() => { - onAuthStateChanged(auth, (user) => { + if (authUser && authLoading === false) { const searchParams = new URLSearchParams(document.location.search); var userUID = searchParams.get("uid") - if (user) { - get(ref(database, `users/${user.uid}`)).then((userData) => { + onValue(ref(database, `users/${authUser.uid}`), (userData) => { userData = userData.val(); if (userData) { if (userData.uid == userUID) { setIsOwner(true); } - setUser(userData); setIsAuthenticated(true); + setUser(userData); } else { - window.location.href = "/onboarding"; + window.location.href = "/onboarding"; } - }); - } - }); - }, []); + }); + } else if (authLoading === false) { + window.location.href = "/login"; + } + }, [authLoading]); // Grabs profile user data useEffect(() => { -- 2.52.0 From ed6c1b427ec223ecfae8920434e61ee82380270c Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Mon, 8 Apr 2024 00:13:14 -0400 Subject: [PATCH 7/7] Bug Fix - JSDoc Build Error --- frontend-next/src/components/app/friends/friends.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend-next/src/components/app/friends/friends.js b/frontend-next/src/components/app/friends/friends.js index 1dacf95..85facd2 100644 --- a/frontend-next/src/components/app/friends/friends.js +++ b/frontend-next/src/components/app/friends/friends.js @@ -55,7 +55,7 @@ export function Friend({user,friendObj}) { * * @prop {JSON} user - User Object * @prop {JSON} requestingUser - User Object of the user requesting to be friends - * @returns + * @returns {Object} Friend Request Component */ export function FriendRequest({user, requestingUser}) { /** -- 2.52.0