import { Accessor, createContext, createResource, Show } from "solid-js"; import { GameState } from "../../../shared/types/cards"; import api from "../api"; import Hand from "./Hand"; import Pile from "./Pile"; export const GameContext = createContext<{ gameState: Accessor; setGameState: (state: GameState) => Promise; }>(); export default (props: { instanceId: number }) => { const [gameState, { refetch }] = createResource(() => api .gameState({ gameId: props.instanceId.toString() }) .get() .then((res) => res.data as GameState) ); const setGameState = (state: GameState) => api .gameState({ gameId: props.instanceId.toString() }) .put({ gameState: state, }) .then(refetch); return (
{ const [drawn, ...rest] = gameState()!.deck; setGameState({ deck: rest, hand: [drawn, ...gameState()!.hand], }); }} />
); };