import { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { useWebSocket } from "../lib/useWebSocket"; import { gameUIRegistry } from "./registry"; import "./chess"; interface RoomSummary { id: string; gameSlug: string; gameName: string; host: string; playerCount: number; maxPlayers: number; spectatorCount: number; status: "waiting" | "playing" | "finished"; } export function GameLobby() { const { send, subscribe, connected } = useWebSocket(); const navigate = useNavigate(); const [rooms, setRooms] = useState([]); const [filter, setFilter] = useState(null); const [showCreate, setShowCreate] = useState(false); const gameTypes = gameUIRegistry.list(); useEffect(() => { if (!connected) return; const unsubscribe = subscribe((msg: any) => { if (msg.type === "ROOM_LIST_UPDATE") { setRooms(msg.rooms); } if (msg.type === "ROOM_CREATED") { navigate(`/${msg.gameSlug}/${msg.roomId}`); } }); return unsubscribe; }, [connected, subscribe, navigate]); const filteredRooms = filter ? rooms.filter(r => r.gameSlug === filter) : rooms; const activeRooms = filteredRooms.filter(r => r.status !== "finished"); function createRoom(gameSlug: string) { send({ type: "CREATE_ROOM", gameType: gameSlug }); setShowCreate(false); } return (

Games

Browse and create game rooms

{gameTypes.map(g => ( ))}
Active Rooms ({activeRooms.length})
{activeRooms.length === 0 ? (
No active rooms. Create one to get started!
) : (
{activeRooms.map(room => { const plugin = gameUIRegistry.get(room.gameSlug); return (
{plugin?.icon ?? "๐ŸŽฎ"}
{room.gameName}
{room.status === "waiting" ? "Waiting" : "Playing"} {room.playerCount}/{room.maxPlayers} players {room.spectatorCount > 0 && ยท ๐Ÿ‘ {room.spectatorCount}}
); })}
)}
{showCreate && (
setShowCreate(false)}>
e.stopPropagation()}>

Create a Room

{gameTypes.map(g => ( ))}
)}
); }