diff --git a/ui/Dockerfile b/ui/Dockerfile index 1a9d0d8..996fb37 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -8,9 +8,11 @@ FROM base as dependencies COPY pages /pages COPY public /public COPY styles /styles +COPY api /api COPY components /components COPY next* / COPY tsconfig.json / +COPY types.ts / EXPOSE 3000 RUN npm run build diff --git a/ui/api/game.api.ts b/ui/api/game.api.ts new file mode 100644 index 0000000..00a0df9 --- /dev/null +++ b/ui/api/game.api.ts @@ -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 => { + const response = await wretch(`/game/${gameId}`) + .headers({ + USER_ID_HEADER: playerId + }) + .get() + .json(); + console.log(response); + return []; +}; diff --git a/ui/components/board.tsx b/ui/components/board.tsx index 7f1884b..1e04adb 100644 --- a/ui/components/board.tsx +++ b/ui/components/board.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Cell } from "./types"; +import { Cell } from "../types"; import styles from "../styles/board.module.css"; interface BoardProps { diff --git a/ui/components/game.tsx b/ui/components/game.tsx index 013c79a..facf1a0 100644 --- a/ui/components/game.tsx +++ b/ui/components/game.tsx @@ -1,30 +1,34 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; +import { fetchGameState } from "../api/game.api"; import Board from "./board"; const Game = () => { - return ( - - ); + const [isLoading, setLoading] = useState(false); + const [cellWidth, setCellWidth] = useState(4); + const [cells, setCells] = useState([ + { 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 ; }; export default Game; diff --git a/ui/package-lock.json b/ui/package-lock.json index 1adaf33..227dea1 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -10,7 +10,8 @@ "dependencies": { "next": "12.1.0", "react": "17.0.2", - "react-dom": "17.0.2" + "react-dom": "17.0.2", + "wretch": "^1.7.9" }, "devDependencies": { "@types/node": "17.0.21", @@ -2527,6 +2528,11 @@ "dev": true, "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": { "version": "4.0.0", "dev": true, @@ -4060,6 +4066,11 @@ "version": "1.0.2", "dev": true }, + "wretch": { + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/wretch/-/wretch-1.7.9.tgz", + "integrity": "sha512-uUSze1Z72RiQjyoqr7r1KW+05WDNeqqKOeyJDPhw6EVEaOgp9RQNrr8AQt3OF7qylQbh2iVtT9r0nXIHlbJgqQ==" + }, "yallist": { "version": "4.0.0", "dev": true diff --git a/ui/package.json b/ui/package.json index a9ac96c..fe3cab8 100644 --- a/ui/package.json +++ b/ui/package.json @@ -11,7 +11,8 @@ "dependencies": { "next": "12.1.0", "react": "17.0.2", - "react-dom": "17.0.2" + "react-dom": "17.0.2", + "wretch": "^1.7.9" }, "devDependencies": { "@types/node": "17.0.21", diff --git a/ui/components/types.ts b/ui/types.ts similarity index 100% rename from ui/components/types.ts rename to ui/types.ts