"use client"; import { useEffect, useState } from "react"; import Confetti from "react-confetti"; import { useConnection } from "@/lib/connection"; export default function Celebration() { const { subscribe } = useConnection(); const [winner, setWinner] = useState(null); const [viewport, setViewport] = useState({ width: 0, height: 0 }); useEffect(() => { const updateViewport = () => { setViewport({ width: window.innerWidth, height: window.innerHeight, }); }; updateViewport(); window.addEventListener("resize", updateViewport); return () => window.removeEventListener("resize", updateViewport); }, []); useEffect(() => { let timeoutId: ReturnType | null = null; const unsubscribe = subscribe((msg) => { if (msg.type !== "TOURNAMENT_WINNER") return; setWinner(msg.username || "Unknown player"); }); return () => { unsubscribe(); }; }, [subscribe]); if (!winner) return null; return ( <>
🏆

Tournament Winner

{winner}

Dominated the bracket and closed out the tournament.

); }