diff --git a/app/(main)/[teamId]/page.js b/app/(main)/[teamId]/page.js index 0a8b073..e82bac5 100644 --- a/app/(main)/[teamId]/page.js +++ b/app/(main)/[teamId]/page.js @@ -3,11 +3,9 @@ import { useState, useEffect, useCallback } from "react"; import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import Link from "next/link"; -import { use } from "react"; // Add this import for React.use() +import { use } from "react"; import NavBar from "@/components/NavBar"; import { getHuntTimer } from "@/utils/timerService"; -// Remove the CSS module import -// import styles from "./teamId.module.css"; export default function TeamPage({ params }) { const { status, data: session } = useSession(); @@ -19,11 +17,9 @@ export default function TeamPage({ params }) { const [huntInProgress, setHuntInProgress] = useState(false); const router = useRouter(); - // Unwrap the params Promise using React.use() const unwrappedParams = use(params); const teamId = unwrappedParams.teamId; - // Add a function to check if the hunt has been activated by admin const checkHuntStatus = useCallback(async () => { try { const response = await fetch("/api/hunt-status", { @@ -47,7 +43,6 @@ export default function TeamPage({ params }) { throw new Error("Invalid team ID"); } - // First check if the user is still part of this team by fetching current user data const userResponse = await fetch("/api/user", { method: "GET", headers: { @@ -59,7 +54,6 @@ export default function TeamPage({ params }) { const userData = await userResponse.json(); - // If the user is not in this team anymore, redirect to team selection if (!userData.teamId || userData.teamId != teamId) { console.log("User no longer in team, redirecting to team selection"); window.location.href = "/team-selection"; @@ -68,7 +62,6 @@ export default function TeamPage({ params }) { console.log("Fetching team data for team ID:", teamId); - // Add timestamp to URL to ensure fresh data on every request const timestamp = new Date().getTime(); const response = await fetch(`/api/teams/${teamId}?_t=${timestamp}`, { method: "GET", @@ -106,12 +99,10 @@ export default function TeamPage({ params }) { setTeamMembers(data.members || []); setError(""); - // Check hunt status whenever we fetch team data await checkHuntStatus(); } catch (err) { console.error("Team page error:", err); setError(err.message); - // If we get a 401 error, redirect to login if (err.message.includes("401")) { router.push("/login"); } @@ -121,15 +112,12 @@ export default function TeamPage({ params }) { }, [teamId, router, checkHuntStatus]); useEffect(() => { - // Only attempt to fetch data when session is ready and we have a teamId if (status === "authenticated" && teamId) { console.log("Session authenticated, fetching team data"); fetchTeamData(); - // Use a shorter interval (3 seconds) for more responsive updates const refreshInterval = setInterval(fetchTeamData, 3000); - // Clean up the interval when component unmounts return () => clearInterval(refreshInterval); } else if (status === "unauthenticated") { console.log("User not authenticated, redirecting to login"); @@ -137,9 +125,7 @@ export default function TeamPage({ params }) { } }, [teamId, status, fetchTeamData, router]); - // Check if hunt is already in progress on component mount useEffect(() => { - // Get timer data and check if a hunt has already been started const timerData = getHuntTimer(); setHuntInProgress(timerData && timerData.startTime); }, []); @@ -190,26 +176,36 @@ export default function TeamPage({ params }) { -
-

Team Members

+
+
+ Waves +
- {teamMembers.length > 0 ? ( -
- {teamMembers.map((member) => ( -
-
👤
-
-
- {member.username} - {member.id === session?.user?.id && " (You)"} -
+
+
+

Team Members

+ +
+ {teamMembers.length > 0 ? ( +
+ {teamMembers.map((member) => ( +
+
👤
+
+
+ {member.username} + {member.id === session?.user?.id && " (You)"} +
+
+
+ ))}
-
- ))} + ) : ( +
No team members found
+ )} +
- ) : ( -
No team members found
- )} +
@@ -226,14 +222,9 @@ export default function TeamPage({ params }) { }); if (response.ok) { - // Immediately remove team data from all storage localStorage.removeItem("teamData"); sessionStorage.removeItem("teamData"); - - // Set a flag so we know the user has left this team localStorage.setItem("userLeftTeam", "true"); - - // Force redirect to team selection window.location.href = "/team-selection"; } else { const errorData = await response.json(); @@ -249,7 +240,6 @@ export default function TeamPage({ params }) { Leave Team - {/* New Start Hunt button with conditional behavior */}
- {/* Replace the outdated navbar with the correct one */}