From 319f066edf29a1c88900d445ef6398e297a719bc Mon Sep 17 00:00:00 2001 From: Nicholas Pease Date: Tue, 5 Mar 2024 05:38:23 +0000 Subject: [PATCH] Main App Page Refactor, Commenting, Chat Room Sidebar Work --- frontend-next/src/app/app/page.js | 148 ++++++++++++++++-------------- 1 file changed, 80 insertions(+), 68 deletions(-) diff --git a/frontend-next/src/app/app/page.js b/frontend-next/src/app/app/page.js index 0ce303d..de9f42d 100644 --- a/frontend-next/src/app/app/page.js +++ b/frontend-next/src/app/app/page.js @@ -6,7 +6,10 @@ import { app } from "../api/firebase-config"; import { getDatabase, ref, onValue, get, set} from "firebase/database"; var database = getDatabase(app) -// Data types + +// Data Types + +// Chat Message function Chat({chatObj}) { let dateOptions = { weekday: 'long', @@ -28,14 +31,16 @@ function Chat({chatObj}) { ) } +// Member for Active/Room members in sidebar function Member() { return ( -
+
LAX18
) } +// Chat Room for myRooms and Nearby in sidebar function ChatRoomSidebar({roomObj, click}) { return (
@@ -47,7 +52,25 @@ return ( ) } +// Map module for main page and chat room sidebar +// TODO: MAKE NOT MOVABLE +function Geo({loc, zoom, movable}) { + if (loc) { + return ( + + + {zoom && } + + ) + } else { + return ( + + ) + } + +} +// Module for Welcome Message on main tab landing page function WelcomeMessage() { //TODO: REALLY GROSS WAY TO GET COOKIES, NEED NEW WAY TO STORE USER DATA WITHOUT API CALLS. THIS PAGE HAS TO BE CLIENT SIDE DUE TO MAPS / GEOLOCATION const [data, setData] = useState(null) @@ -76,26 +99,8 @@ function WelcomeMessage() { } -// TODO: MAKE NOT MOVABLE -function Geo({loc, zoom, movable}) { - if (loc) { - return ( - - - {zoom && } - - ) - } else { - return ( - - ) - } - -} - - - // Main Tabs +// Primary App Landing Page function MainTabHome({loc}) { return ( <> @@ -107,6 +112,7 @@ function MainTabHome({loc}) { ) } +// Chatroom Module for Primary Tab function MainTabChatRoom({room, user}) { var { register, control, reset, handleSubmit} = useForm() const [chats, setData] = useState(null) @@ -153,48 +159,56 @@ function MainTabChatRoom({room, user}) { ) } -function CreateRoom({loc}) { - var { register, control, reset, handleSubmit} = useForm() +// Contains most everything for the app homepage +// +function Home() { + // It's time to document and change these awful variable names + // State variables for app page + const [mainTab, setMainTab] = useState("home") // Primary tab + const [tab, setTab] = useState("nearby") // Sidebar Tab + const [chatRoom, setChatRoom] = useState(null) // Selected chatroom path + const [user, setUser] = useState(null) // Current user 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 [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 - function createRoom(data) { - reset() - var path = String(loc.latitude.toFixed(2)).replace(".","")+"/"+String(loc.longitude.toFixed(2)).replace(".","") - var timestamp = new Date().getTime() - var payload = { - name: data.name, - description: data.description, - timestamp: timestamp, - latitude: loc.latitude, - longitude: loc.longitude, - path: path + // CreateRoom Module for Sidebar Create Tab + function CreateRoom({loc}) { + var { register, control, reset, handleSubmit} = useForm() + + function createRoom(data) { + reset() + var path = String(loc.latitude.toFixed(2)).replace(".","")+"/"+String(loc.longitude.toFixed(2)).replace(".","") + var timestamp = new Date().getTime() + var payload = { + name: data.name, + description: data.description, + timestamp: timestamp, + latitude: loc.latitude, + longitude: loc.longitude, + path: path + } + set(ref(database,`/rooms/${path}/${data.name}-${timestamp}`), payload) } - set(ref(database,`/rooms/${path}/${data.name}-${timestamp}`), payload) + + return ( +
+
+ +
+
+ Creating room near ({loc.latitude.toFixed(2)}, {loc.longitude.toFixed(2)}) +
+ +
+
+ ) } - return ( -
-
- -
-
- Creating room near ({loc.latitude.toFixed(2)}, {loc.longitude.toFixed(2)}) -
- -
-
- ) -} - -function Home() { - var [tab, setTab] = useState("nearby") - var [mainTab, setMainTab] = useState("home") - var [chatRoom, setChatRoom] = useState("Dev") - const [chatSidebar, setChatSidebar] = useState("home") - var [user, setUser] = useState(null) - - - const [myRooms, setRoomData] = useState(null) - const [isRoomLoading, setRoomLoading] = useState(true) + // Grabs user data, saves to user, then lists the users saved rooms useEffect(() => { fetch('/api/user').then((res) => res.json()) .then((user) => { @@ -211,12 +225,7 @@ function Home() { }) }, []) - - const [location, setLocation] = useState(null); - const [loadingLoc, setLoadingLoc] = useState(true) - const [nearby, setNearby] = useState(null); - const [loadingNearby, setLoadingNearby] = useState(true); - const [myRoomsData, setMyRoomsData] = useState(null) + // Grabs the user location useEffect(() => { if('geolocation' in navigator) { // Retrieve latitude & longitude coordinates from `navigator.geolocation` Web API @@ -241,10 +250,11 @@ function Home() { } }, []); - return (
+ {/* Left Side of Page */}
+ {/* Header */}
@@ -256,12 +266,14 @@ function Home() { Sign Out
+ {/* Main Page Section */}
{(mainTab == "home" && !loadingLoc) && } {(mainTab == "home" && loadingLoc) && } {mainTab == "chat" && }
+ {/* Sidebar (Right Side of Page) */} {mainTab == "home" &&
@@ -290,7 +302,7 @@ function Home() { {(tab == "create" && loadingLoc) &&
Loading...
}
} - {(mainTab == "chat" && chatSidebar=="home") && + {(mainTab == "chat") &&
@@ -314,7 +326,7 @@ function Home() {
} - {(mainTab == "chat" && chatSidebar=="profile") && + {(mainTab == "profile") &&
Profile