From 724b8c8e387d962e6c73fbc526e6f5cf1af0e785 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sat, 15 Jan 2022 13:02:44 -0800 Subject: [PATCH] fetching team data --- components/Dashboard/Header.tsx | 67 ++++++++++++++++++++++++-- components/Dashboard/TeamVoiceLine.tsx | 2 - pages/teams/[teamid].tsx | 32 ++++++++++++ pages/teams/create.tsx | 5 +- services/teamService.tsx | 16 ++++++ 5 files changed, 115 insertions(+), 7 deletions(-) diff --git a/components/Dashboard/Header.tsx b/components/Dashboard/Header.tsx index b6ebab1..a6c37cf 100644 --- a/components/Dashboard/Header.tsx +++ b/components/Dashboard/Header.tsx @@ -9,6 +9,7 @@ import { FaBuilding, FaCalendarDay, FaClock, + FaPeopleCarry, } from "react-icons/fa"; import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; import router from "next/router"; @@ -19,13 +20,39 @@ import { Dropdown, Menu } from "antd"; import { useRouter } from "next/router"; import { TeamMemberRole, TeamMemberStatus } from "../../models/teamMember"; import { toast } from "react-hot-toast"; +import SubMenu from "antd/lib/menu/SubMenu"; +import { useEffect, useState } from "react"; +import TeamService from "../../services/teamService"; +import { Team } from "../../models/team"; +import Loading from "../Loading"; + +const teamService = new TeamService(); export default function Header() { - const { logOut } = useAuth(); + const { currUser, logOut } = useAuth(); const { team, user, userTeamMember } = useTeamDashboardContext(); const router = useRouter(); const { teamid } = router.query; + const [usersTeams, setUserTeams] = useState(null); + console.log("rendering"); + console.log(usersTeams); + + useEffect(() => { + (async function () { + try { + // get all the teams that this user is part of + const newTeams: Team[] = + await teamService.getActiveOrInvitedTeamsbyUser(currUser.uid); + console.log(newTeams); + setUserTeams(newTeams); + } catch (error) { + console.log("problem getting teams of this user"); + toast.error("problem on load"); + } + })(); + }, []); + async function handleSignOut() { console.log("clicked log out button"); @@ -51,10 +78,41 @@ export default function Header() { const UserMenu = ( - + - + + {/* all current teams that this person is a part of */} + {usersTeams && + usersTeams.map((team, i) => { + return ( + + + + ); + })} + + }> + + + + + @@ -87,6 +145,7 @@ export default function Header() { return (
{/* welcome message */} + {usersTeams && usersTeams.length} 👋Hey {user.firstName}, {periodOfDay}! @@ -121,7 +180,7 @@ export default function Header() { {/* avatar */} - + diff --git a/components/Dashboard/TeamVoiceLine.tsx b/components/Dashboard/TeamVoiceLine.tsx index c95049c..b87bca6 100644 --- a/components/Dashboard/TeamVoiceLine.tsx +++ b/components/Dashboard/TeamVoiceLine.tsx @@ -80,9 +80,7 @@ export default function TeamVoiceLine() { try { // listeners for all teammates' status if (teamMembers) { - console.log(teamMembers); teamMembers.map((tmember) => { - console.log(tmember); if (tmember.status == TeamMemberStatus.activated) { const docRef = doc(db, Collections.users, tmember.userId); diff --git a/pages/teams/[teamid].tsx b/pages/teams/[teamid].tsx index 72d4cbb..58386e9 100644 --- a/pages/teams/[teamid].tsx +++ b/pages/teams/[teamid].tsx @@ -14,11 +14,43 @@ import { Team } from "../../models/team"; import { TeamMemberStatus } from "../../models/teamMember"; import TeamService from "../../services/teamService"; +// User has switched back to the tab +const onFocus = () => { + console.log("Tab is in focus"); +}; + +// User has switched away from the tab (AKA tab is hidden) +const onBlur = () => { + console.log("Tab is blurred"); +}; + +const onClose = (ev) => { + // change user status to offline + + ev.preventDefault(); + return (ev.returnValue = "are you sure?"); +}; + function TeamDashboard() { const { currUser } = useAuth(); const router = useRouter(); const teamDashboardContext = useTeamDashboardContext(); + useEffect(() => { + window.addEventListener("focus", onFocus); + window.addEventListener("blur", onBlur); + // Calls onFocus when the window first loads + onFocus(); + // Specify how to clean up after this effect: + + window.addEventListener("beforeunload", onClose); + return () => { + window.removeEventListener("focus", onFocus); + window.removeEventListener("blur", onBlur); + window.removeEventListener("beforeunload", onClose); + }; + }, []); + console.log(teamDashboardContext); return ( diff --git a/pages/teams/create.tsx b/pages/teams/create.tsx index 859e1c6..ea9ad8a 100644 --- a/pages/teams/create.tsx +++ b/pages/teams/create.tsx @@ -112,7 +112,10 @@ export default function CreateTeam() {