freego_api/ui/api/game.api.ts
fry 209a4f5caf Board that corresponds to what the api gives us (#4)
Display what the API gives us as the board + pieces.

Co-authored-by: David Frymoyer <david.frymoyer@gmail.com>
Reviewed-on: #4
Co-authored-by: fry <david.frymoyer@gmail.com>
Co-committed-by: fry <david.frymoyer@gmail.com>
2022-03-16 21:46:20 -04:00

21 lines
479 B
TypeScript

import wretch from "wretch";
import { Cell } from "../types";
const USER_ID_HEADER = "Player-id";
export const fetchGameState = async (
playerId: string,
gameId: number
): Promise<{ cells: Cell[]; cellWidth: number }> => {
const response: { board: Cell[][] } = await wretch(`/api/game/${gameId}`)
.headers({
[USER_ID_HEADER]: playerId,
})
.get()
.json();
return {
cells: response.board.flat(),
cellWidth: response.board[0].length,
};
};