Board that corresponds to what the api gives us #4
@ -8,9 +8,11 @@ FROM base as dependencies
|
|||||||
COPY pages /pages
|
COPY pages /pages
|
||||||
COPY public /public
|
COPY public /public
|
||||||
COPY styles /styles
|
COPY styles /styles
|
||||||
|
COPY api /api
|
||||||
COPY components /components
|
COPY components /components
|
||||||
COPY next* /
|
COPY next* /
|
||||||
COPY tsconfig.json /
|
COPY tsconfig.json /
|
||||||
|
COPY types.ts /
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
18
ui/api/game.api.ts
Normal file
18
ui/api/game.api.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import wretch from "wretch";
|
||||||
|
import { Cell } from "../types";
|
||||||
|
|
||||||
|
const USER_ID_HEADER = 'Player-id';
|
||||||
|
|
||||||
|
export const fetchGameState = async (
|
||||||
|
playerId: string,
|
||||||
|
gameId: number
|
||||||
|
): Promise<Cell[]> => {
|
||||||
|
const response = await wretch(`/game/${gameId}`)
|
||||||
|
.headers({
|
||||||
|
USER_ID_HEADER: playerId
|
||||||
|
})
|
||||||
|
.get()
|
||||||
|
.json();
|
||||||
|
console.log(response);
|
||||||
|
return [];
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Cell } from "./types";
|
import { Cell } from "../types";
|
||||||
import styles from "../styles/board.module.css";
|
import styles from "../styles/board.module.css";
|
||||||
|
|
||||||
interface BoardProps {
|
interface BoardProps {
|
||||||
|
@ -1,30 +1,34 @@
|
|||||||
import React from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { fetchGameState } from "../api/game.api";
|
||||||
import Board from "./board";
|
import Board from "./board";
|
||||||
|
|
||||||
const Game = () => {
|
const Game = () => {
|
||||||
return (
|
const [isLoading, setLoading] = useState(false);
|
||||||
<Board
|
const [cellWidth, setCellWidth] = useState(4);
|
||||||
cellWidth={4}
|
const [cells, setCells] = useState([
|
||||||
cells={[
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
{ terrainType: 1 },
|
||||||
{ terrainType: 1 },
|
]);
|
||||||
]}
|
useEffect(() => {
|
||||||
/>
|
setLoading(true);
|
||||||
);
|
fetchGameState("red", 1).then(console.log);
|
||||||
|
});
|
||||||
|
|
||||||
|
return <Board cellWidth={cellWidth} cells={cells} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Game;
|
export default Game;
|
||||||
|
13
ui/package-lock.json
generated
13
ui/package-lock.json
generated
@ -10,7 +10,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "12.1.0",
|
"next": "12.1.0",
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-dom": "17.0.2"
|
"react-dom": "17.0.2",
|
||||||
|
"wretch": "^1.7.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "17.0.21",
|
"@types/node": "17.0.21",
|
||||||
@ -2527,6 +2528,11 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/wretch": {
|
||||||
|
"version": "1.7.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/wretch/-/wretch-1.7.9.tgz",
|
||||||
|
"integrity": "sha512-uUSze1Z72RiQjyoqr7r1KW+05WDNeqqKOeyJDPhw6EVEaOgp9RQNrr8AQt3OF7qylQbh2iVtT9r0nXIHlbJgqQ=="
|
||||||
|
},
|
||||||
"node_modules/yallist": {
|
"node_modules/yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
@ -4060,6 +4066,11 @@
|
|||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"wretch": {
|
||||||
|
"version": "1.7.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/wretch/-/wretch-1.7.9.tgz",
|
||||||
|
"integrity": "sha512-uUSze1Z72RiQjyoqr7r1KW+05WDNeqqKOeyJDPhw6EVEaOgp9RQNrr8AQt3OF7qylQbh2iVtT9r0nXIHlbJgqQ=="
|
||||||
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"dev": true
|
"dev": true
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"next": "12.1.0",
|
"next": "12.1.0",
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-dom": "17.0.2"
|
"react-dom": "17.0.2",
|
||||||
|
"wretch": "^1.7.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "17.0.21",
|
"@types/node": "17.0.21",
|
||||||
|
Loading…
Reference in New Issue
Block a user