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