From 6b9d4d1295be1326096a98ddc54acf44855585cc Mon Sep 17 00:00:00 2001 From: nessi Date: Fri, 6 Feb 2026 14:07:26 +0100 Subject: [PATCH] Add live refresh for game members and metadata Implemented a useEffect to periodically refresh game member and winner metadata every 2.5 seconds. This ensures new joiners are visible without requiring a page reload, balancing performance and usability. --- frontend/src/App.jsx | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 724fe73..9d9f07e 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -131,6 +131,36 @@ export default function App() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [gameId]); + // ✅ Live refresh (Members/Meta) – damit neue Joiner ohne Reload sichtbar sind + // Für 5–6 Spieler reicht 2.5s völlig, ist "live genug" und schont Backend. + useEffect(() => { + if (!me || !gameId) return; + + let alive = true; + + const tick = async () => { + try { + await loadGameMeta(); // refresh members + winner meta + } catch { + // ignore + } + }; + + // sofort einmal ziehen + tick(); + + const id = setInterval(() => { + if (!alive) return; + tick(); + }, 2500); + + return () => { + alive = false; + clearInterval(id); + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [me?.id, gameId]); + // ===== Auth actions ===== const doLogin = async () => { await api("/auth/login", {