diff --git a/src/components/frontend/minigames/poker/PokerLobby.tsx b/src/components/frontend/minigames/poker/PokerLobby.tsx index 7a071c1..7d746a9 100644 --- a/src/components/frontend/minigames/poker/PokerLobby.tsx +++ b/src/components/frontend/minigames/poker/PokerLobby.tsx @@ -49,8 +49,8 @@ function createdLabel(createdAt: string): string { } export function PokerLobby({ refreshKey, onOpenTable, isSuperuser = false }: PokerLobbyProps) { - const [tables, setTables] = useState([]); - const [loading, setLoading] = useState(true); + const [tables, setTables] = useState(null); + const [refreshing, setRefreshing] = useState(false); const [pendingTable, setPendingTable] = useState(null); const [forceEndingTable, setForceEndingTable] = useState(null); const [creating, setCreating] = useState(false); @@ -58,22 +58,28 @@ export function PokerLobby({ refreshKey, onOpenTable, isSuperuser = false }: Pok const [error, setError] = useState(null); const loadTables = useCallback(async () => { - setLoading(true); - setError(null); try { const result = await listPokerTables(); if (!result.success) { setError(result.error ?? "Could not load poker tables."); return; } + setError(null); setTables(result.data ?? []); } catch (caught) { setError(caught instanceof Error ? caught.message : "Could not load poker tables."); - } finally { - setLoading(false); } }, []); + const manualRefresh = useCallback(async () => { + setRefreshing(true); + try { + await loadTables(); + } finally { + setRefreshing(false); + } + }, [loadTables]); + useEffect(() => { void loadTables(); }, [loadTables, refreshKey]); @@ -172,12 +178,12 @@ export function PokerLobby({ refreshKey, onOpenTable, isSuperuser = false }: Pok type="button" variant="outline" size="icon" - onClick={() => void loadTables()} - disabled={loading} + onClick={() => void manualRefresh()} + disabled={refreshing} aria-label="Refresh poker tables" title="Refresh tables" > - +