From 96f56b2154195191132fb43c5b27f0a7c2ce1bb6 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 21 Feb 2021 09:30:40 +0100 Subject: working game-id's --- pages/game.tsx | 56 ++++++++++++++++++++++++++++---------------------------- pages/index.tsx | 3 ++- 2 files changed, 30 insertions(+), 29 deletions(-) (limited to 'pages') diff --git a/pages/game.tsx b/pages/game.tsx index 5f610f8..6890a7e 100644 --- a/pages/game.tsx +++ b/pages/game.tsx @@ -17,7 +17,8 @@ import LinkRoundedIcon from '@material-ui/icons/LinkRounded'; import RefreshIcon from '@material-ui/icons/Refresh'; interface VoerGameProps { - + gameID: string; + token: string; } class VoerGame extends Component { @@ -71,22 +72,12 @@ class VoerGame extends Component { }; board = [...Array(this.width * this.height)].map(() => 0); - userID = ""; move(column: number) { - if(this.state.userID == "") { - axios.request({ - method: "get", - url: `/api/user/info`, - headers: {"content-type": "application/json"} - }) - .then(request => this.setState({ userID: request.data.id })) - .catch(() => {}); - } this.io.emit("newMove", { move: column, - token: cookies.load("token"), - gameID: "fortnite" + token: this.props.token, + game_id: this.props.gameID }); } @@ -172,30 +163,33 @@ export default class GamePage extends Component { constructor(props: {}) { super(props); - if (typeof window === "undefined") return; - if (document.cookie.includes("token") == false) return; - axios.request({ - method: "get", - url: `/api/user/info`, - headers: {"content-type": "application/json"} - }) - .then(request => this.setState({ userID: request.data.id })) - .catch(() => {}); + /* if (typeof window === "undefined") return; */ + /* if (document.cookie.includes("token") == false) return; */ + /* axios.request({ */ + /* method: "get", */ + /* url: `/api/user/info`, */ + /* headers: {"content-type": "application/json"} */ + /* }) */ + /* .then(request => this.setState({ */ + /* user: request.data, */ + /* token: cookies.load("token") */ + /* })) */ + /* .catch(() => {}); */ } state: { - userID: string; gameID: string; + token: string; } = { - userID: "", gameID: "", + token: "", } render() { return
- + {true &&
this.setState({ gameID: request.data.id })) + .then(request => this.setState({ + gameID: request.data.id, + token: cookies.load("token") + })) .catch(() => {}); }}>
-

{this.state.gameID}

+ + {this.state.gameID} + {this.state.token} +
}
diff --git a/pages/index.tsx b/pages/index.tsx index 84f08b8..f341c35 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -61,7 +61,8 @@ function LoginOrRegisterBox() { display: "inline-block", position: "absolute", fontSize: 14, - left: 0, right: 0, top: 0 + left: 0, right: 0, top: 0, + margin: "0 100px" }}>Log in of maak een account aan om je scores op te slaan en toegang te krijgen tot meer functies