diff --git a/frontend-next/src/app/user/page.js b/frontend-next/src/app/user/page.js
index 52a7a25..3f724f8 100644
--- a/frontend-next/src/app/user/page.js
+++ b/frontend-next/src/app/user/page.js
@@ -8,7 +8,6 @@ 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";
@@ -20,6 +19,9 @@ import { Header } from "../../components/app/header";
// Friend Import
import { addFriend } from "../../components/app/friends/friends";
+// Icons
+import CircleIcon from '@mui/icons-material/Circle';
+
/**
* User Profile Page
* @returns {Object} - User Profile Page
@@ -128,8 +130,8 @@ function UserProfile() {
style={{maxWidth: "350px", maxHeight: "450px"}}
className="relative mx-auto rounded-2xl overflow-hidden"
/>
-
- {profileData.firstName} {profileData.lastName}
+
+ {profileData.lastOnline == true && }{profileData.firstName} {profileData.lastName}
@{profileData.username}
{profileData.bio}
diff --git a/frontend-next/src/components/app/datatypes.js b/frontend-next/src/components/app/datatypes.js
index e03dfff..c55b64a 100644
--- a/frontend-next/src/components/app/datatypes.js
+++ b/frontend-next/src/components/app/datatypes.js
@@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
// Icons
import PersonIcon from '@mui/icons-material/Person';
+import CircleIcon from '@mui/icons-material/Circle';
// Colors for Messages
const userColors = [
@@ -149,7 +150,7 @@ export function Member({ memberObj }) {
return (
- {memberObj.username}
+ {memberObj.lastOnline == true && }{memberObj.username}
);
diff --git a/frontend-next/src/components/app/friends/friends.js b/frontend-next/src/components/app/friends/friends.js
index 467a2ff..30493b9 100644
--- a/frontend-next/src/components/app/friends/friends.js
+++ b/frontend-next/src/components/app/friends/friends.js
@@ -12,6 +12,7 @@ import { openDM } from './dm';
// Icons
import CheckIcon from '@mui/icons-material/Check';
import CloseIcon from '@mui/icons-material/Close';
+import CircleIcon from '@mui/icons-material/Circle';
/**
* Send a friend request to a user
@@ -41,7 +42,7 @@ export function Friend({user,friendObj}) {
-
{friendObj.firstName} {friendObj.lastName}
+
{friendObj.lastOnline == true && }{friendObj.firstName} {friendObj.lastName}
@{friendObj.username}
diff --git a/frontend-next/src/components/app/header.js b/frontend-next/src/components/app/header.js
index aa860c8..467f89d 100644
--- a/frontend-next/src/components/app/header.js
+++ b/frontend-next/src/components/app/header.js
@@ -3,7 +3,7 @@ import Link from "next/link"
// Firebase Imports
import { database } from "../../../firebase-config";
-import { ref, set, remove } from "firebase/database";
+import { ref, set, remove, onDisconnect, serverTimestamp } from "firebase/database";
// Component Imports
import { NotificationPanel } from "./notifications/notifications";
@@ -88,6 +88,17 @@ export function Header({mainTab,chatRoomObj,user,sidebarControl}) {
}
}
+
+ // Sets User Online / Offline
+ // Stored in header for easy code maintenance and retains user online/offline throughout app
+ // Makes user online
+ if (user.invisibleStatus == false) {
+ set(ref(database, `/users/${user.uid}/lastOnline`), true)
+ }
+
+ // Makes user offline (with last time online)
+ onDisconnect(ref(database, `/users/${user.uid}/lastOnline`)).set(serverTimestamp())
+
return (
diff --git a/frontend-next/src/components/app/profile/ProfilePanel.js b/frontend-next/src/components/app/profile/ProfilePanel.js
index 0b3dcb3..387025d 100644
--- a/frontend-next/src/components/app/profile/ProfilePanel.js
+++ b/frontend-next/src/components/app/profile/ProfilePanel.js
@@ -3,8 +3,9 @@ import { Popover } from "@headlessui/react";
import Link from "next/link"
// Firebase Imports
-import { auth } from "../../../../firebase-config";
+import { auth, database } from "../../../../firebase-config";
import { signOut } from "firebase/auth";
+import {update, ref, serverTimestamp} from "firebase/database";
/**
* Logs out from Firebase Authentication
@@ -43,6 +44,18 @@ export function ProfilePanel({user}) {
>
View Profile
+
{
+ // Toggle Invisible Status
+ update(ref(database, `/users/${user.uid}`), {
+ invisibleStatus: user.invisibleStatus? !user.invisibleStatus: true,
+ lastOnline: user.invisibleStatus? true: serverTimestamp()
+ }
+ );
+ }}
+ >
+ {user.invisibleStatus ? "Go Online" : "Go Invisible"}
+