Skip to content
Snippets Groups Projects
Commit 0d908724 authored by Joni Laukka's avatar Joni Laukka
Browse files

Redirect to root if game was not found

parent 8d669808
No related branches found
No related tags found
2 merge requests!31Development,!28Routing
......@@ -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}`)
......
......@@ -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>
);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment