From 0d90872414bafe086939958dc4dd67e1009e9fa1 Mon Sep 17 00:00:00 2001 From: Joni Laukka <jonilaukka@hotmail.com> Date: Mon, 15 Jul 2019 20:32:59 +0300 Subject: [PATCH] Redirect to root if game was not found --- src/components/GameView.js | 14 ++++++++++++-- src/components/PlayerlistView.js | 33 +++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/components/GameView.js b/src/components/GameView.js index 83ef451..04f12f6 100644 --- a/src/components/GameView.js +++ b/src/components/GameView.js @@ -21,8 +21,18 @@ export default class GameView extends React.Component { componentDidMount() { let gameId = new URL(window.location.href).searchParams.get("id"); let token = sessionStorage.getItem("token"); - let error = false; - // TODO: redirect to root if the game is not found + + console.log(gameId); + fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`) + .then(res => { + if (!res.ok) { + throw Error(); + } + }) + .catch(error => { + alert("Game not found"); + window.document.location.href = "/"; + }); // Get game info fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`) diff --git a/src/components/PlayerlistView.js b/src/components/PlayerlistView.js index 5eeeb64..6967b0e 100644 --- a/src/components/PlayerlistView.js +++ b/src/components/PlayerlistView.js @@ -58,18 +58,29 @@ export default class PlayerlistView extends React.Component { return false; } - let factionlistItems = this.state.factions.map(faction => { - return ( - <PlayerlistFaction - key={faction.factionId} - faction={faction} - role={this.props.role} - gameId={this.props.gameId} - /> - ); - }); + let factionlistItems = this.state.factions.map(faction => ( + <PlayerlistFaction + key={faction.factionId} + faction={faction} + role={this.props.role} + gameId={this.props.gameId} + /> + )); - return <div className="fade-main">{factionlistItems}</div>; + return ( + <div className="fade-main"> + <div className="sticky"> + <span + id="closeEditGameFormX" + className="close" + onClick={() => this.props.toggleView()} + > + × + </span> + </div> + {factionlistItems} + </div> + ); } } -- GitLab