import { useState, useEffect } from "react"; import { useNakama } from "./providers/NakamaProvider"; import Board from "./Board"; import Player from "./Player"; // import { Match } from "@heroiclabs/nakama-js"; // import MatchList from "./MatchList"; export default function TicTacToe() { const [board, setBoard] = useState([ ["", "", ""], ["", "", ""], ["", "", ""] ]); const [turn, setTurn] = useState(0); const [winner, setWinner] = useState(null); // const [openMatches, setOpenMatches] = useState([]); const [players, setPlayers] = useState([]); function onMatchDataCallback(msg: { opCode: number; data: any }) { console.log("[Match Data]", msg); if (msg.opCode === 2) { const state = msg.data; console.log("Match state:", state); setBoard(state.board); setTurn(state.turn); setWinner(state.winner || null); // new: setPlayers(state.players || []); } } const { onMatchData, sendMatchData, // listOpenMatches, matchId, session, } = useNakama(); useEffect(() => { onMatchData(onMatchDataCallback); }, [onMatchData]); // useEffect(() => { // let active = true; // // async function refreshLoop() { // while (active) { // const matches = await listOpenMatches(); // setOpenMatches(matches); // // await new Promise(res => setTimeout(res, 500)); // 0.5s refresh // } // } // // refreshLoop(); // // return () => { // active = false; // }; // }, [listOpenMatches]); // ------------------------------------------ // SEND A MOVE // ------------------------------------------ function handleCellClick(row: number, col: number) { if (!matchId) return; sendMatchData(matchId, 1, { row, col }); // OpMove=1 } return (

Tic Tac Toe Multiplayer

{matchId && ( )}
); }