Skip to content
Snippets Groups Projects

Join game update fix

Merged H9031 requested to merge join-game-update-fix into development
2 files
+ 29
25
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 28
24
@@ -23,30 +23,13 @@ export default class GameView extends React.Component {
componentDidMount() {
let gameId = new URL(window.location.href).searchParams.get("id");
let token = sessionStorage.getItem("token");
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 = "/";
});
this.getGameInfo(gameId);
this.getPlayerRole(gameId);
}
// Get game info
fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`)
.then(res => res.json())
.then(res => {
this.setState({
gameInfo: res
});
})
.catch(error => console.log(error));
getPlayerRole(gameId) {
let token = sessionStorage.getItem("token");
// Get Role
fetch(`${process.env.REACT_APP_API_URL}/faction/check-faction/${gameId}`, {
method: "GET",
headers: {
@@ -60,6 +43,26 @@ export default class GameView extends React.Component {
.catch(error => console.log(error));
}
getGameInfo(gameId) {
fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`)
.then(res => {
if (!res.ok) {
throw Error();
} else {
return res.json();
}
})
.then(res => {
this.setState({
gameInfo: res
});
})
.catch(error => {
alert("Game not found");
window.document.location.href = "/";
});
}
handleLeaveFaction = e => {
let token = sessionStorage.getItem("token");
let error = false;
@@ -82,6 +85,7 @@ export default class GameView extends React.Component {
})
.then(res => {
alert(res.message);
this.getPlayerRole(this.state.gameInfo.id);
})
.catch(error => console.log(error));
};
@@ -184,7 +188,7 @@ export default class GameView extends React.Component {
gameId={this.state.gameInfo.id}
toggleView={() => this.setState({ form: "" })}
onEditSave={() => {
this.getGameInfo();
this.getGameInfo(this.state.gameInfo.id);
}}
/>
)}
@@ -192,7 +196,7 @@ export default class GameView extends React.Component {
<JoinGameForm
gameId={this.state.gameInfo.id}
toggleView={() => this.setState({ form: "" })}
onJoin={() => console.log("joinde")}
onJoin={() => this.getPlayerRole(this.state.gameInfo.id)}
/>
)}
{this.state.form === "players" && (
Loading