diff --git a/app/(main)/admin/leaderboard/page.js b/app/(main)/admin/leaderboard/page.js index e1042b6..d9011de 100644 --- a/app/(main)/admin/leaderboard/page.js +++ b/app/(main)/admin/leaderboard/page.js @@ -29,49 +29,13 @@ export default function AdminLeaderboardPage() { setLoading(true); setError(""); - // This is a placeholder - you'll need to implement the actual API - // For now, we'll just set dummy data - const dummyTeams = [ - { - id: 1, - name: "Team Alpha", - code: "ALPHA1", - memberCount: 4, - cluesFound: 5, - totalClues: 10, - lastActivity: new Date().toISOString(), - }, - { - id: 2, - name: "Team Beta", - code: "BETA12", - memberCount: 3, - cluesFound: 8, - totalClues: 10, - lastActivity: new Date().toISOString(), - }, - { - id: 3, - name: "Team Gamma", - code: "GAMMA3", - memberCount: 5, - cluesFound: 2, - totalClues: 10, - lastActivity: new Date().toISOString(), - }, - ]; - - setTeams(dummyTeams); - - // Uncomment this when API is ready - /* const response = await fetch("/api/admin/leaderboard", { method: "GET", headers: { "Content-Type": "application/json", - "Cache-Control": "no-cache, no-store, must-revalidate" + "Cache-Control": "no-cache, no-store, must-revalidate", }, - credentials: "include" + credentials: "include", }); if (!response.ok) { @@ -80,7 +44,6 @@ export default function AdminLeaderboardPage() { const data = await response.json(); setTeams(data); - */ } catch (err) { console.error("Error fetching leaderboard data:", err); setError(err.message); @@ -89,6 +52,54 @@ export default function AdminLeaderboardPage() { } }; + // Handle resetting a team's progress + const handleResetTeamProgress = async (teamId, teamName) => { + if ( + !confirm( + `Are you sure you want to reset progress for team "${teamName}"?` + ) + ) { + return; + } + + try { + setLoading(true); + + const response = await fetch( + `/api/admin/teams/${teamId}/reset-progress`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + credentials: "include", + } + ); + + if (!response.ok) { + throw new Error("Failed to reset team progress"); + } + + // Refresh the data after successful reset + fetchLeaderboardData(); + } catch (err) { + console.error("Error resetting team progress:", err); + setError(err.message); + setLoading(false); + } + }; + + // Auto refresh data every 30 seconds + useEffect(() => { + if (session?.user?.role === "admin") { + const interval = setInterval(() => { + fetchLeaderboardData(); + }, 30000); + + return () => clearInterval(interval); + } + }, [session]); + if (status === "loading" || loading) { return
Loading...
; } @@ -119,7 +130,7 @@ export default function AdminLeaderboardPage() { {teams.length === 0 ? ( -

No team data available.

+

No teams currently participating.

) : (
@@ -142,7 +153,16 @@ export default function AdminLeaderboardPage() {
{team.memberCount} - {team.cluesFound} / {team.totalClues} +
+
+ + {team.cluesFound} / {team.totalClues} ( + {team.progress}%) + +
{team.lastActivity @@ -153,7 +173,7 @@ export default function AdminLeaderboardPage() {