From b800d7e12906460041cf69181dee548292e5a673 Mon Sep 17 00:00:00 2001 From: Brainstem2000 Date: Tue, 10 Mar 2026 21:05:17 -0400 Subject: [PATCH] Fix dashboard player online status not refreshing The dashboard fetched player info (including online/offline status) once and never updated it. If a player came online or went offline while viewing the dashboard, the status indicator stayed stale. Changes: - Add 30-second polling interval for selected player info - Add 30-second polling interval for all player card summaries when the Players tab is active - Remove the allPlayerInfo.length === 0 guard that prevented re-fetching when returning to the Players tab - Add silent mode to fetchAllPlayerInfo to avoid showing the loading spinner on background refreshes Co-Authored-By: Claude Opus 4.6 --- src/app/dashboard/page.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 164702f..7331d11 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -341,9 +341,9 @@ function DashboardContent() { } }, [authHeaders]) - const fetchAllPlayerInfo = useCallback(async () => { + const fetchAllPlayerInfo = useCallback(async (silent = false) => { if (players.length === 0) return - setChatPlayersLoading(true) + if (!silent) setChatPlayersLoading(true) try { const headers = await authHeaders() const results: PlayerInfo[] = [] @@ -361,7 +361,7 @@ function DashboardContent() { } setAllPlayerInfo(results) } finally { - setChatPlayersLoading(false) + if (!silent) setChatPlayersLoading(false) } }, [authHeaders, players]) @@ -370,14 +370,15 @@ function DashboardContent() { fetchRegistrationCode() }, [userLoaded, authLoaded, user, fetchRegistrationCode]) - // Fetch all player info when switching to players tab (needed for chat subsection) + // Fetch all player info when switching to players tab, and poll every 30s useEffect(() => { - if (activeTab === 'players' && authLoaded && players.length > 0 && allPlayerInfo.length === 0) { - fetchAllPlayerInfo() - } - }, [activeTab, authLoaded, players.length, allPlayerInfo.length, fetchAllPlayerInfo]) + if (activeTab !== 'players' || !authLoaded || players.length === 0) return + fetchAllPlayerInfo() + const interval = setInterval(() => fetchAllPlayerInfo(true), 30_000) + return () => clearInterval(interval) + }, [activeTab, authLoaded, players.length, fetchAllPlayerInfo]) - // Fetch player info + log when selected player changes + // Fetch player info + log when selected player changes, and poll info every 30s useEffect(() => { if (!selectedPlayer || !authLoaded) return setCaptainsLog(null) @@ -385,6 +386,8 @@ function DashboardContent() { setPasswordVisible(false) fetchPlayerInfo(selectedPlayer) fetchCaptainsLog(selectedPlayer) + const interval = setInterval(() => fetchPlayerInfo(selectedPlayer), 30_000) + return () => clearInterval(interval) }, [selectedPlayer, authLoaded, fetchPlayerInfo, fetchCaptainsLog])