diff --git a/src/components/frontend/minigames/blackjack/BlackjackArena.tsx b/src/components/frontend/minigames/blackjack/BlackjackArena.tsx index 60a025e..8879d71 100644 --- a/src/components/frontend/minigames/blackjack/BlackjackArena.tsx +++ b/src/components/frontend/minigames/blackjack/BlackjackArena.tsx @@ -1,6 +1,7 @@ "use client"; import { useCallback, useEffect, useRef, useState } from "react"; +import { toast } from "sonner"; import { fetchBlackjackTable, joinBlackjackTable, @@ -11,7 +12,6 @@ import { } from "@/app/(frontend)/minigames/blackjack/actions"; import type { BlackjackPhase } from "@/lib/minigames/blackjack"; import { useRealtimePresence } from "@/hooks/useRealtimePresence"; -import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ChipBankCard } from "@/components/frontend/minigames/ChipBankCard"; import { BlackjackGuide } from "./BlackjackGuide"; @@ -61,7 +61,6 @@ export function BlackjackArena({ const [activeTableId, setActiveTableId] = useState(initialTableId ?? null); const [tableError, setTableError] = useState(null); const [loading, setLoading] = useState(Boolean(initialTableId)); - const [terminated, setTerminated] = useState(null); const [leaderboardRefreshKey, setLeaderboardRefreshKey] = useState(0); const [lobbyRefreshKey, setLobbyRefreshKey] = useState(0); const lastRoundRef = useRef(null); @@ -73,7 +72,6 @@ export function BlackjackArena({ return next; }); setActiveTableId(next.tableId); - setTerminated((current) => (current !== next.tableId ? null : current)); if (syncedTableIdRef.current !== next.tableId) { syncedTableIdRef.current = next.tableId; window.history.replaceState( @@ -134,7 +132,8 @@ export function BlackjackArena({ const handleTerminated = (event: Event) => { const detail = readBlackjackTerminatedEvent(event); if (!detail || detail.tableId !== activeTableId) return; - setTerminated(detail.tableId); + toast.info("An administrator ended your blackjack game."); + resetToLobby(); }; window.addEventListener(BLACKJACK_STATE_EVENT, handleState); window.addEventListener(BLACKJACK_TABLES_EVENT, handleTables); @@ -150,13 +149,18 @@ export function BlackjackArena({ // deliver server-action pushes (dev per-bundle module duplication). The // SSE push stays as an instant bonus; applySnapshot dedupes by version. useEffect(() => { - if (view !== "table" || activeTableId === null || terminated === activeTableId) return; + if (view !== "table" || activeTableId === null) return; let cancelled = false; const poll = window.setInterval(() => { void fetchBlackjackTable(activeTableId) .then((result) => { if (cancelled) return; - if (result.success && result.data) applySnapshot(result.data); + if (result.success && result.data) { + applySnapshot(result.data); + } else if (result.error === "Table not found.") { + toast.info("An administrator ended your blackjack game."); + resetToLobby(); + } }) .catch(() => undefined); }, 1250); @@ -164,7 +168,7 @@ export function BlackjackArena({ cancelled = true; window.clearInterval(poll); }; - }, [activeTableId, terminated, view, applySnapshot]); + }, [activeTableId, view, applySnapshot]); const resetToLobby = useCallback(() => { setView("lobby"); @@ -172,7 +176,6 @@ export function BlackjackArena({ setActiveTableId(null); setTableError(null); setLoading(false); - setTerminated(null); lastRoundRef.current = null; if (syncedTableIdRef.current !== null) { syncedTableIdRef.current = null; @@ -304,22 +307,6 @@ export function BlackjackArena({ onOpenTable={applySnapshot} isSuperuser={isSuperuser} /> - ) : terminated === activeTableId ? ( - - - - Game ended by an administrator - - - -

- An administrator forcefully ended this blackjack table. -

- -
-
) : (