fry
209a4f5caf
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>
29 lines
739 B
TypeScript
29 lines
739 B
TypeScript
import React, { useState, useEffect } from "react";
|
|
import { fetchGameState } from "../api/game.api";
|
|
import { Cell } from "../types";
|
|
import Board from "./board";
|
|
|
|
interface GameProps {
|
|
gameId: number;
|
|
}
|
|
|
|
const Game = (props: GameProps) => {
|
|
const [isLoading, setLoading] = useState(false);
|
|
const [cellWidth, setCellWidth] = useState(4);
|
|
const [cells, setCells] = useState([] as Cell[]);
|
|
useEffect(() => {
|
|
setLoading(true);
|
|
fetchGameState("red", props.gameId).then(
|
|
({ cells: cellList, cellWidth: width }) => {
|
|
setCellWidth(width);
|
|
setCells(cellList);
|
|
setLoading(false);
|
|
}
|
|
);
|
|
}, [props.gameId]);
|
|
|
|
return <Board cellWidth={cellWidth} cells={cells} />;
|
|
};
|
|
|
|
export default Game;
|