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

Role fix

parent c1790195
No related branches found
No related tags found
2 merge requests!31Development,!28Routing
import React from "react";
import EditGameForm from "./EditGameForm";
import { Link } from "react-router-dom";
export default class GameCard extends React.Component {
......@@ -57,22 +56,6 @@ export default class GameCard extends React.Component {
>
<button type="button">Select</button>
</Link>
{/* <button
id="editGameButton"
onClick={() => this.setState({ editForm: true })}
>
Edit
</button> */}
{/* {this.state.editForm && (
<EditGameForm
gameId={this.state.gameInfo.id}
toggleView={() => this.setState({ editForm: false })}
onEditSave={() => {
this.props.onEditSave();
this.getGameInfo();
}}
/>
)} */}
</div>
);
}
......
......@@ -10,7 +10,7 @@ import NotificationView from "./NotificationView";
export default class GameView extends React.Component {
state = {
gameInfo: null,
role: "", //empty, soldier, admin
role: "", //empty, soldier, factionleader, admin
form: "",
lat: 62.2416479,
lng: 25.7597186,
......@@ -41,28 +41,15 @@ export default class GameView extends React.Component {
Authorization: "Bearer " + token
}
})
.then(res => res.json())
.then(res => {
if (!res.ok) {
error = true;
}
return res.json();
})
.then(res => {
if (error && res.message === "You are admin for this game!") {
this.setState({
role: "admin"
});
} else if (error) {
return;
} else {
this.setState({
role: "soldier"
});
}
this.setState({ role: res.role });
})
.catch();
.catch(error => console.log(error));
}
handleLeaveFaction = e => {};
render() {
const initialPosition = [this.state.lat, this.state.lng];
......@@ -116,11 +103,8 @@ export default class GameView extends React.Component {
role={this.state.role}
/>
)}
{this.state.role === "soldier" && (
<button
id="leaveFactionButton"
onClick={() => console.log("WIP: leave faction")}
>
{this.state.role !== "admin" && this.state.role !== "" && (
<button id="leaveFactionButton" onClick={this.handleLeaveFaction}>
Leave Faction
</button>
)}
......
......@@ -10,11 +10,12 @@ export default class PlayerlistView extends React.Component {
componentDidMount() {
let token = sessionStorage.getItem("token");
if (this.props.role !== "soldier") {
if (this.props.role !== "soldier" && this.props.role !== "factionleader") {
// get all factions in the game
fetch(`${process.env.REACT_APP_API_URL}/game/${this.props.gameId}`)
.then(res => res.json())
.then(res => {
console.log(res);
this.setState({ factions: res.factions });
})
.catch(error => console.log(error));
......
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