working e2e
This commit is contained in:
@@ -3,46 +3,45 @@ import {
|
||||
GameState,
|
||||
Action,
|
||||
vGameState,
|
||||
PlayerView,
|
||||
} from "../../../server/src/games/simple";
|
||||
import api from "../api";
|
||||
import Hand from "./Hand";
|
||||
import Pile from "./Pile";
|
||||
|
||||
export const GameContext = createContext<{
|
||||
gameState: Accessor<GameState | undefined>;
|
||||
view: Accessor<PlayerView | undefined>;
|
||||
submitAction: (action: Action) => Promise<any>;
|
||||
}>();
|
||||
|
||||
export default (props: { instanceId: string }) => {
|
||||
const [gameState, { mutate }] = createResource(() =>
|
||||
const [view, { mutate }] = createResource(() =>
|
||||
api
|
||||
.simple(props)
|
||||
.get()
|
||||
.then((res) => res.data as GameState)
|
||||
.then((res) => res.data as PlayerView)
|
||||
);
|
||||
const submitAction = (action: Action) =>
|
||||
api
|
||||
.simple(props)
|
||||
.post({ action })
|
||||
.then((res) => res.status == 200 && mutate(res.data as vGameState));
|
||||
.then((res) => res.status == 200 && mutate(res.data as PlayerView));
|
||||
|
||||
return (
|
||||
<GameContext.Provider value={{ gameState, submitAction }}>
|
||||
<Show when={gameState.latest != undefined}>
|
||||
<GameContext.Provider value={{ view, submitAction }}>
|
||||
<Show when={view.latest != undefined}>
|
||||
<div
|
||||
class="full column center"
|
||||
style={{ "row-gap": "20px", "font-size": "32px" }}
|
||||
>
|
||||
<div class="full center">
|
||||
<Pile
|
||||
pile={gameState.latest!.deck}
|
||||
count={view.latest!.deckCount}
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() =>
|
||||
api.simple({ instanceId: props.instanceId })
|
||||
}
|
||||
onClick={() => submitAction({ type: "draw" })}
|
||||
/>
|
||||
</div>
|
||||
<Hand hand={gameState.latest!.players["daniel"]} />
|
||||
<Hand hand={view.latest!.myHand} />
|
||||
</div>
|
||||
</Show>
|
||||
</GameContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user