diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 9d9f07e..fd762f8 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -263,6 +263,15 @@ export default function App() { // ===== New game flow ===== const createGame = async () => { + // ✅ wichtig: alten Game-State weg, damit nix "hängen" bleibt + setSheet(null); + setGameMeta(null); + setMembers([]); + setWinnerUserId(""); + setPulseId(null); + setChipOpen(false); + setChipEntry(null); + const g = await api("/games", { method: "POST", body: JSON.stringify({ name: "Spiel " + new Date().toLocaleString() }), @@ -270,9 +279,10 @@ export default function App() { const gs = await api("/games"); setGames(gs); + + // ✅ auf neues Spiel wechseln (triggered dann reloadSheet/loadGameMeta via effect) setGameId(g.id); - // meta/members will load via gameId effect return g; // includes code }; @@ -503,6 +513,9 @@ export default function App() { onClose={() => setNewGameOpen(false)} onCreate={createGame} onJoin={joinGame} + currentCode={gameMeta?.code || ""} + gameFinished={!!gameMeta?.winner_user_id} + hasGame={!!gameId} /> joinCode.trim().length >= 4, [joinCode]); + // ✅ wichtig: beim Öffnen entscheidet der Modus anhand "läuft vs beendet" + useEffect(() => { + if (!open) return; + + setErr(""); + setToast(""); + setJoinCode(""); + setCreated(null); + + // Wenn ein Spiel läuft (und nicht finished) -> nur Code anzeigen + if (hasGame && !gameFinished) { + setMode("running"); + } else { + setMode("choice"); + } + }, [open, hasGame, gameFinished]); + if (!open) return null; const showToast = (msg) => { @@ -44,15 +67,19 @@ export default function NewGameModal({ } }; - const copyCode = async () => { + const copyText = async (text, okMsg = "✅ Code kopiert") => { try { - await navigator.clipboard.writeText(created?.code || ""); - showToast("✅ Code kopiert"); + await navigator.clipboard.writeText(text || ""); + showToast(okMsg); } catch { showToast("❌ Copy nicht möglich"); } }; + const codeToShow = + (created?.code || "").trim() || + (currentCode || "").trim(); + return (
e.stopPropagation()}> @@ -85,6 +112,63 @@ export default function NewGameModal({ )}
+ {/* ✅ RUNNING: Nur Code anzeigen, keine Choice */} + {mode === "running" && ( + <> +
+ Das Spiel läuft noch. Hier ist der Join-Code: +
+ +
+
+ Spiel-Code +
+ +
+ {codeToShow || "—"} +
+ + +
+ +
+ Sobald ein Sieger gesetzt wurde, kannst du hier ein neues Spiel erstellen oder beitreten. +
+ +
+ +
+ + )} + + {/* ✅ CHOICE: nur wenn Spiel beendet oder kein Spiel selected */} {mode === "choice" && ( <>
@@ -159,7 +243,7 @@ export default function NewGameModal({ {created.code}
-