From e2a8c75d46199ee087ccfb73eabeb43be340f32d Mon Sep 17 00:00:00 2001
From: ClarkLach <102780236+ClarkLach@users.noreply.github.com>
Date: Sat, 30 Mar 2024 02:19:49 -0400
Subject: [PATCH] Profile Edit into Component
Continuing to break up functionality into separate files
---
frontend-next/src/app/app/page.js | 26 ++--
frontend-next/src/app/onboarding/page.js | 2 +-
frontend-next/src/app/user/[stub]/page.js | 130 ++----------------
frontend-next/src/components/app/datatypes.js | 2 -
frontend-next/src/components/app/map/geo.js | 1 +
.../src/components/app/profile/ProfileEdit.js | 124 +++++++++++++++++
.../src/components/app/sidebar/chat.js | 1 -
7 files changed, 151 insertions(+), 135 deletions(-)
create mode 100644 frontend-next/src/components/app/profile/ProfileEdit.js
diff --git a/frontend-next/src/app/app/page.js b/frontend-next/src/app/app/page.js
index 801bfce..b5e5dea 100644
--- a/frontend-next/src/app/app/page.js
+++ b/frontend-next/src/app/app/page.js
@@ -7,6 +7,7 @@ import { useBeforeunload } from "react-beforeunload";
import { Marker } from "pigeon-maps";
import { onAuthStateChanged } from "firebase/auth";
+
// Refactored Component Imports
// Data Structure Imports
import { ChatRoomSidebar, Member } from "../../components/app/datatypes";
@@ -31,18 +32,18 @@ function Home() {
const [tab, setTab] = useState("nearby"); // Sidebar Tab
const [chatRoomObj, setChatRoomObj] = useState(null); // Current chatroom object
const [myRoomsObj, setMyRoomsObj] = useState(null); // My Rooms Object
- const [myRooms, setRoomData] = useState(null); // Current user saved rooms list
- const [isRoomLoading, setRoomLoading] = useState(true); // myRooms loading variable, true = myRooms loading, false = finished loading
+ const [roomData, setRoomData] = useState(null); // Current user saved rooms list
+ const [isRoomLoading, setIsRoomLoading] = useState(true); // myRooms loading variable, true = myRooms loading, false = finished loading
const [isMyRoom, setIsMyRoom] = useState(false); // Is current room in myRooms? true, false
const [location, setLocation] = useState(null); // location variable [lat,long]
const [loadingLoc, setLoadingLoc] = useState(true); // location variable loading, true = loading, false = finished loading
const [nearby, setNearby] = useState(null); // nearby rooms array
const [loadingNearby, setLoadingNearby] = useState(true); // loading nearby rooms array, true = loading, false = finished loading
- const [chatroomOnline, setChatRoomOnline] = useState(null); // holds online users
+ const [chatroomOnline, setChatroomOnline] = useState(null); // holds online users
const [chatroomUsers, setChatroomUsers] = useState(null); // holds all chatroom users
const [chatroomUsersLoading, setChatroomUsersLoading] = useState(true);
const [markers, setMarkers] = useState([]);
- const [isAuthenticated, setAuth] = useState(false);
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
const [user, setUser] = useState(null);
const [usingSearchParams, setUsingSearchParams] = useState(true);
@@ -68,13 +69,13 @@ function Home() {
userData = userData.val();
if (userData) {
setUser(userData);
- setAuth(true);
+ setIsAuthenticated(true);
} else {
window.location.href = "/onboarding";
}
});
} else {
- setAuth(false);
+ setIsAuthenticated(false);
window.location.href = "/login";
}
});
@@ -84,7 +85,7 @@ function Home() {
useEffect(() => {
if (user) {
onValue(ref(database, "/users/" + user.uid + "/rooms"), (snapshot) => {
- setRoomLoading(true);
+ setIsRoomLoading(true);
var rooms = snapshot.val();
setMyRoomsObj(rooms);
var roomArr = [];
@@ -117,7 +118,7 @@ function Home() {
}
setMarkers(markerArr);
setRoomData(roomArr);
- setRoomLoading(false);
+ setIsRoomLoading(false);
});
}
}, [user]);
@@ -175,7 +176,7 @@ function Home() {
useEffect(() => {
if (myRoomsObj && chatRoomObj) {
var roomName = chatRoomObj.name + "-" + chatRoomObj.timestamp;
- if (myRooms != null && roomName in myRoomsObj) {
+ if (roomData != null && roomName in myRoomsObj) {
// its in there
setIsMyRoom(true);
} else {
@@ -211,7 +212,7 @@ function Home() {
// Code for Room Data
set(ref(database, `/rooms/${path}/users/online/${user.uid}`), user);
onValue(ref(database, `/rooms/${path}`), (snapshot) => {
- setChatRoomOnline(null);
+ setChatroomOnline(null);
setChatroomUsers(null);
// Active users list
@@ -223,7 +224,7 @@ function Home() {
var activeUsersJSON = snapshot.val().users.online;
for (var user in activeUsersJSON)
activeUsers.push(
diff --git a/frontend-next/src/app/user/[stub]/page.js b/frontend-next/src/app/user/[stub]/page.js
index df4796b..2f2e520 100644
--- a/frontend-next/src/app/user/[stub]/page.js
+++ b/frontend-next/src/app/user/[stub]/page.js
@@ -3,18 +3,17 @@
import { useState, useEffect } from "react";
import { auth, database, storage } from "../../../../firebase-config";
import { ref, onValue, get, update } from "firebase/database";
-import { ref as sRef, getDownloadURL } from "firebase/storage";
import { onAuthStateChanged } from "firebase/auth";
-import { useForm, Form } from "react-hook-form";
// Refactored Component Imports
+
// Data Structure Imports
import { ProfileRoom } from "../../../components/app/profile/ProfileRoom";
+import { ProfileEdit } from "../../../components/app/profile/ProfileEdit";
import { Interest } from "../../../components/app/profile/Interest";
// Header Import
import { Header } from "../../../components/app/header";
-import { uploadBytes } from "firebase/storage";
// Contains most everything for the app homepage
function Home({ params }) {
@@ -26,9 +25,13 @@ function Home({ params }) {
const [userInterestArray, setUserInterestArray] = useState(null);
const [userRoomsArray, setUserRoomsArray] = useState(null);
const [isOwner, setIsOwner] = useState(false);
+
const [isEditing, setIsEditing] = useState(false);
- var { register, control } = useForm();
+ //Handles Edit State in Component, shares useState with ProfileEdit
+ const handleIsEditing = (newValue) => {
+ setIsEditing(newValue);
+ };
// Authentication
useEffect(() => {
@@ -58,6 +61,10 @@ function Home({ params }) {
onValue(ref(database, "/users/" + params.stub), (snapshot) => {
setProfileData(snapshot.val());
var interests = snapshot.val().interests || null;
+ if (interests == null) {
+ // Placeholder for no interests specified, will be replaced with default interests
+ interests = "Music, Sports, Movies";
+ }
interests = interests.split(",");
var interestArray = [];
var i = 0;
@@ -76,36 +83,6 @@ function Home({ params }) {
});
}, []);
- function save({ data }) {
- if (data.pfp[0]) {
- // image stuff
- uploadBytes(sRef(storage, `users/${user.uid}/pfp`), data.pfp[0]).then(
- () => {
- getDownloadURL(sRef(storage, `users/${user.uid}/pfp`)).then((url) => {
- data.pfp = url;
- for (var key in data) {
- if (data[key] == "") {
- data[key] = profileData[key];
- }
- }
-
- setIsEditing(false);
- update(ref(database, `users/${user.uid}`), data);
- });
- }
- );
- } else {
- for (var key in data) {
- if (data[key] == "") {
- data[key] = profileData[key];
- }
- }
- data.pfp = profileData.pfp;
- setIsEditing(false);
- update(ref(database, `users/${user.uid}`), data);
- }
- }
-
return (