"use client"; import { useEffect, useState, useCallback, useRef } from "react"; interface LobbyManagerProps { roomId: string; } type LobbyEntry = { id: string; sessionId: string; displayName: string; createdAt: string; }; export default function LobbyManager({ roomId }: LobbyManagerProps) { const [entries, setEntries] = useState([]); const [acting, setActing] = useState(null); const pollRef = useRef>(undefined); const fetchEntries = useCallback(async () => { try { const res = await fetch(`/api/rooms/${roomId}/lobby`); if (res.ok) { const data = await res.json(); setEntries(data); } } catch { // silent } }, [roomId]); useEffect(() => { fetchEntries(); pollRef.current = setInterval(fetchEntries, 3000); return () => { if (pollRef.current) clearInterval(pollRef.current); }; }, [fetchEntries]); async function handleAction(entry: LobbyEntry, action: "APPROVED" | "REJECTED") { setActing(entry.id); try { await fetch(`/api/rooms/${roomId}/lobby`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ lobbyEntryId: entry.id, action }), }); setEntries((prev) => prev.filter((e) => e.id !== entry.id)); } catch { // silent } finally { setActing(null); } } return (

Зал ожидания ({entries.length})

{entries.length === 0 ? (

Никто не ожидает

) : (
{entries.map((entry) => (
{entry.displayName}
))}
)}
); }