freego_api/ui/api/game.api.ts

21 lines
479 B
TypeScript
Raw Normal View History

2022-03-10 18:57:15 -05:00
import wretch from "wretch";
import { Cell } from "../types";
2022-03-16 21:43:58 -04:00
const USER_ID_HEADER = "Player-id";
2022-03-10 18:57:15 -05:00
export const fetchGameState = async (
playerId: string,
gameId: number
2022-03-16 21:43:58 -04:00
): Promise<{ cells: Cell[]; cellWidth: number }> => {
const response: { board: Cell[][] } = await wretch(`/api/game/${gameId}`)
2022-03-10 18:57:15 -05:00
.headers({
2022-03-16 21:43:58 -04:00
[USER_ID_HEADER]: playerId,
2022-03-10 18:57:15 -05:00
})
.get()
.json();
2022-03-16 21:43:58 -04:00
return {
cells: response.board.flat(),
cellWidth: response.board[0].length,
};
2022-03-10 18:57:15 -05:00
};