import { useEffect, useRef, useState } from "react" import { createFileRoute } from "@tanstack/react-router" import { useWebSocket } from "@/hooks/use-websocket" import { useRoomStore } from "@/stores/room-store" import { PlayerList } from "@/components/player-list" import { PredictionsForm } from "@/components/predictions-form" import { JuryVoting } from "@/components/jury-voting" import { BingoCard } from "@/components/bingo-card" import { Leaderboard } from "@/components/leaderboard" import { RoomHeader } from "@/components/room-header" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" export const Route = createFileRoute("/play/$roomCode")({ component: PlayerView, }) function PlayerView() { const { roomCode } = Route.useParams() const { send } = useWebSocket(roomCode) const { room, mySessionId, connectionStatus, gameState } = useRoomStore() const joinSentRef = useRef(false) const [manualName, setManualName] = useState("") useEffect(() => { if (connectionStatus !== "connected" || mySessionId || joinSentRef.current) return const displayName = sessionStorage.getItem("esc-party-join-name") if (displayName) { joinSentRef.current = true sessionStorage.removeItem("esc-party-join-name") send({ type: "join_room", displayName }) } }, [connectionStatus, mySessionId, send]) if (!room) { return (

{connectionStatus === "connecting" ? "Connecting..." : "Room not found"}

) } if (!mySessionId && connectionStatus === "connected" && !joinSentRef.current) { return (

Join Room {roomCode}

setManualName(e.target.value)} maxLength={20} onKeyDown={(e) => { if (e.key === "Enter" && manualName.trim()) { joinSentRef.current = true send({ type: "join_room", displayName: manualName.trim() }) } }} />
) } if (!mySessionId) { return (

Joining room...

) } return (
{gameState && (room.currentAct === "lobby" || room.currentAct === "pre-show") && (
send({ type: "submit_prediction", ...prediction }) } />
)} {gameState && room.currentAct === "live-event" && ( Jury Bingo {gameState.currentJuryRound ? ( send({ type: "submit_jury_vote", rating })} /> ) : (
Waiting for host to open voting...
)}
{gameState.myBingoCard ? ( send({ type: "tap_bingo_square", tropeId })} /> ) : (
No bingo card yet
)}
)} {gameState && room.currentAct === "scoring" && ( )} {room.currentAct === "ended" && (

The party has ended. Thanks for playing!

{gameState && }
)}
) }