Skip to content
Snippets Groups Projects
Commit d58dd0b9 authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Merged join game update fix

parents 46736d13 1304a31e
No related branches found
No related tags found
2 merge requests!46Development to testing,!38Join game update fix
...@@ -23,8 +23,27 @@ export default class GameView extends React.Component { ...@@ -23,8 +23,27 @@ export default class GameView extends React.Component {
componentDidMount() { componentDidMount() {
let gameId = new URL(window.location.href).searchParams.get("id"); let gameId = new URL(window.location.href).searchParams.get("id");
this.getGameInfo(gameId);
this.getPlayerRole(gameId);
}
getPlayerRole(gameId) {
let token = sessionStorage.getItem("token"); let token = sessionStorage.getItem("token");
fetch(`${process.env.REACT_APP_API_URL}/faction/check-faction/${gameId}`, {
method: "GET",
headers: {
Authorization: "Bearer " + token
}
})
.then(res => res.json())
.then(res => {
this.setState({ role: res.role });
})
.catch(error => console.log(error));
}
getGameInfo(gameId) {
fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`) fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`)
.then(res => { .then(res => {
if (!res.ok) { if (!res.ok) {
...@@ -42,19 +61,6 @@ export default class GameView extends React.Component { ...@@ -42,19 +61,6 @@ export default class GameView extends React.Component {
alert("Game not found"); alert("Game not found");
window.document.location.href = "/"; window.document.location.href = "/";
}); });
// Get Role
fetch(`${process.env.REACT_APP_API_URL}/faction/check-faction/${gameId}`, {
method: "GET",
headers: {
Authorization: "Bearer " + token
}
})
.then(res => res.json())
.then(res => {
this.setState({ role: res.role });
})
.catch(error => console.log(error));
} }
handleLeaveFaction = e => { handleLeaveFaction = e => {
...@@ -79,6 +85,7 @@ export default class GameView extends React.Component { ...@@ -79,6 +85,7 @@ export default class GameView extends React.Component {
}) })
.then(res => { .then(res => {
alert(res.message); alert(res.message);
this.getPlayerRole(this.state.gameInfo.id);
}) })
.catch(error => console.log(error)); .catch(error => console.log(error));
}; };
...@@ -182,7 +189,7 @@ export default class GameView extends React.Component { ...@@ -182,7 +189,7 @@ export default class GameView extends React.Component {
gameId={this.state.gameInfo.id} gameId={this.state.gameInfo.id}
toggleView={() => this.setState({ form: "" })} toggleView={() => this.setState({ form: "" })}
onEditSave={() => { onEditSave={() => {
this.getGameInfo(); this.getGameInfo(this.state.gameInfo.id);
}} }}
/> />
)} )}
...@@ -190,7 +197,7 @@ export default class GameView extends React.Component { ...@@ -190,7 +197,7 @@ export default class GameView extends React.Component {
<JoinGameForm <JoinGameForm
gameId={this.state.gameInfo.id} gameId={this.state.gameInfo.id}
toggleView={() => this.setState({ form: "" })} toggleView={() => this.setState({ form: "" })}
onJoin={() => console.log("joinde")} onJoin={() => this.getPlayerRole(this.state.gameInfo.id)}
/> />
)} )}
{this.state.form === "players" && ( {this.state.form === "players" && (
......
...@@ -14,7 +14,7 @@ export default class JoinGameForm extends React.Component { ...@@ -14,7 +14,7 @@ export default class JoinGameForm extends React.Component {
} }
// Get game info // Get game info
//TODO: from props //TODO: gameinfo from props
componentDidMount() { componentDidMount() {
if (this.props.gameId === undefined) { if (this.props.gameId === undefined) {
alert("game not selected"); alert("game not selected");
......
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