"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useRouter, useParams } from "next/navigation"; import RoomConnector from "../../components/RoomConnector"; import PlayerList from "../../components/PlayerList"; import ChatBox from "../../components/ChatBox"; import { getSocket } from "../../lib/socket-client"; import { useGame } from "../../lib/store"; export default function LobbyPage() { const params = useParams<{ code: string }>(); const code = String(params.code || "").toUpperCase(); const router = useRouter(); const room = useGame((s) => s.room); const myId = useGame((s) => s.myId); const [copied, setCopied] = useState(false); const [err, setErr] = useState(""); useEffect(() => { if (room && room.phase === "playing") router.push(`/room/${code}/play`); if (room && room.phase === "results") router.push(`/room/${code}/results`); }, [room?.phase, code, router]); const isHost = room && myId && room.hostId === myId; const shareUrl = typeof window !== "undefined" ? `${window.location.origin}/join?code=${code}` : ""; const playerCount = room?.players.filter(p => p.connected).length || 0; const garticNeedsMore = room?.mode === "gartic" && playerCount < 3; const start = () => { setErr(""); getSocket().emit("game:start", null, (resp: any) => { if (!resp?.ok) setErr(resp?.error || "could not start"); }); }; const copy = async () => { try { await navigator.clipboard.writeText(shareUrl); setCopied(true); setTimeout(()=>setCopied(false), 1500); } catch {} }; return (
DrawTogether
Room {code}

Players

{room?.players.length || 0} / 12

Invite friends

{shareUrl}
Room code
{code}

Game settings

Mode: {room?.mode || "—"}
{room?.mode === "skribbl" && <> } {room?.mode === "gartic" && <> } {room?.mode === "color" && <> {room?.settings?.canvasType === "template" && } }
{garticNeedsMore && (
Gartic Phone is way more fun with friends! Grab at least 3 players to start. ({playerCount}/3)
)} {isHost ? ( ) : (
Waiting for host to start...
)} {err &&
{err}
}

Lobby chat

); } function SettingTile({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); }