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

game info view added. game edit button now needs game state 'CREATED'

parent 35eb3767
No related branches found
No related tags found
3 merge requests!46Development to testing,!41Notifications + small updates,!39Notification view
import React from "react";
import { Map, TileLayer } from "react-leaflet";
export default class GameInfoView extends React.Component {
componentDidMount() {
document.addEventListener("keyup", this.handleEsc);
}
componentWillUnmount() {
document.removeEventListener("keyup", this.handleEsc);
}
handleEsc = e => {
if (e.keyCode === 27) {
this.props.toggleView();
}
};
render() {
if (this.props.gameInfo === undefined) {
return false;
}
return (
<div className="fade-main">
<div className="sticky">
<span
id="closeEditGameFormX"
className="close"
onClick={this.props.toggleView}
>
×
</span>
</div>
<div className="">
<h1>Game Info</h1>
<p>Game name: {this.props.gameInfo.name}</p>
<p>Description: {this.props.gameInfo.desc}</p>
<p>Start date: {this.props.gameInfo.startdate}</p>
<p>End date: {this.props.gameInfo.enddate}</p>
<h2>Factions</h2>
<div>
{this.props.gameInfo.factions.map(faction => (
<p key={faction.factionId} style={{ color: faction.colour }}>
{faction.factionName}
</p>
))}
</div>
<div>
<Map
id="gameInfoCenterMap"
className=""
center={[
this.props.gameInfo.center.lat,
this.props.gameInfo.center.lng
]}
zoom="13"
maxZoom="13"
style={{ height: "400px", width: "400px" }}
>
<TileLayer
attribution="Maanmittauslaitoksen kartta"
url=" https://tiles.kartat.kapsi.fi/taustakartta/{z}/{x}/{y}.jpg"
/>
</Map>
</div>
</div>
</div>
);
}
}
...@@ -9,6 +9,7 @@ import NotificationView from "./NotificationView"; ...@@ -9,6 +9,7 @@ import NotificationView from "./NotificationView";
import GameStateButtons from "./GameStateButtons"; import GameStateButtons from "./GameStateButtons";
import ClientSocket from "./Socket"; import ClientSocket from "./Socket";
import NotificationPopup from "./NotificationPopup"; import NotificationPopup from "./NotificationPopup";
import GameInfoView from "./GameInfoView";
export default class GameView extends React.Component { export default class GameView extends React.Component {
state = { state = {
...@@ -133,14 +134,18 @@ export default class GameView extends React.Component { ...@@ -133,14 +134,18 @@ export default class GameView extends React.Component {
{this.state.role !== "" && ( {this.state.role !== "" && (
<div>Your role in this game: {this.state.role}</div> <div>Your role in this game: {this.state.role}</div>
)} )}
{this.state.role === "admin" && ( {this.state.role === "admin" &&
<button this.state.gameInfo.state === "CREATED" && (
id="editGameButton" <button
onClick={() => this.setState({ form: "edit" })} id="editGameButton"
> onClick={() => this.setState({ form: "edit" })}
Edit >
</button> Edit
)} </button>
)}
<button onClick={() => this.setState({ form: "info" })}>
Game Info
</button>
{this.state.role === "" && ( {this.state.role === "" && (
<button <button
id="joinGameButton" id="joinGameButton"
...@@ -225,6 +230,12 @@ export default class GameView extends React.Component { ...@@ -225,6 +230,12 @@ export default class GameView extends React.Component {
} }
/> />
)} )}
{this.state.form === "info" && (
<GameInfoView
gameInfo={this.state.gameInfo}
toggleView={() => this.setState({ form: "" })}
/>
)}
</div> </div>
)} )}
</div> </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