starting attaching to server

This commit is contained in:
fry 2022-03-10 18:57:15 -05:00
parent 75431afaa9
commit 20fc6cf9ed
7 changed files with 63 additions and 27 deletions

View File

@ -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

18
ui/api/game.api.ts Normal file
View 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 [];
};

View File

@ -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 {

View File

@ -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 (
<Board
cellWidth={4}
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 },
]}
/>
);
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 <Board cellWidth={cellWidth} cells={cells} />;
};
export default Game;

13
ui/package-lock.json generated
View File

@ -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

View File

@ -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",