import { Component, createEffect, createSignal, Match, Switch } from 'solid-js'; import createWebsocket from '@solid-primitives/websocket'; import { wsUrl } from './constants'; import Spinner from './components/Spinner'; import Welcome from './components/Welcome'; import { Board as BoardData, Move, ServerChessEvent } from './events'; import Board from './components/Board'; interface Props { gameId: string; } const App: Component = (props) => { const [board, setBoard] = createSignal(Array(64).fill(null)); const [possibleMoves, setPossibleMoves] = createSignal([]); function handleEvent(e: MessageEvent) { const data = JSON.parse(e.data); const event = ServerChessEvent.parse(data); if (event.event === 'BoardUpdate') { console.log(event.data.board); setBoard(event.data.board); } else if (event.event === 'PossibleMoves') { console.log(event.data.moves); setPossibleMoves(event.data.moves); } } createEffect(() => { console.log('board is now', board()); }); createEffect(() => { console.log('moves is now', possibleMoves()); }); const [connect, disconnect, send, state, socket] = createWebsocket(wsUrl(props.gameId), handleEvent, console.error); function makeMove(move: Move) { send(JSON.stringify({ event: 'MakeMove', data: { move, }, })); } return

Hello, World!

}> connect()} />
}; export default App;