Skip to content
Snippets Groups Projects

Join, edit game form

Merged H9031 requested to merge joinGame-form into development
5 files
+ 239
103
Compare changes
  • Side-by-side
  • Inline
Files
5
import React from "react";
import React, {Fragment} from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom";
import { Map, TileLayer } from "react-leaflet";
import { Map, TileLayer } from "react-leaflet";
@@ -17,7 +17,13 @@ export class EditGameForm extends React.Component {
@@ -17,7 +17,13 @@ export class EditGameForm extends React.Component {
mapCenter: {
mapCenter: {
lat: 62.2416479,
lat: 62.2416479,
lng: 25.7597186
lng: 25.7597186
}
},
 
factionNameInput: "",
 
factionPasswordInput: "",
 
factions: [{
 
name: "Overflow",
 
password: "Wimma"
 
}]
};
};
this.handleMapDrag = this.handleMapDrag.bind(this);
this.handleMapDrag = this.handleMapDrag.bind(this);
@@ -32,6 +38,27 @@ export class EditGameForm extends React.Component {
@@ -32,6 +38,27 @@ export class EditGameForm extends React.Component {
this.setState({ [name]: value });
this.setState({ [name]: value });
};
};
 
handleFactionAdd = e =>{
 
e.preventDefault();
 
 
if(this.state.factionNameInput === "" || this.state.factionPasswordInput === ""){
 
return alert("Faction needs a name and password");
 
}
 
 
this.setState(state => {
 
let factions = state.factions;
 
factions.push({
 
name: this.state.factionNameInput,
 
password: this.state.factionPasswordInput
 
});
 
return {
 
factions: factions,
 
factionNameInput: "",
 
factionPasswordInput: ""
 
}
 
})
 
}
 
// show/hide this form
// show/hide this form
handleView = e => {
handleView = e => {
this.props.toggleView(this.props.view);
this.props.toggleView(this.props.view);
@@ -124,7 +151,28 @@ export class EditGameForm extends React.Component {
@@ -124,7 +151,28 @@ export class EditGameForm extends React.Component {
});
});
}
}
 
removeFaction(index){
 
this.setState(state => {
 
let factions = state.factions;
 
factions.splice(index,1);
 
 
return factions;
 
});
 
}
 
render() {
render() {
 
 
let factions = [];
 
for (let i = 0; i < this.state.factions.length; i++) {
 
const faction = this.state.factions[i];
 
factions.push(
 
<Fragment>
 
<li key={i}>{faction.name} : {faction.password}</li>
 
<button onClick={() => this.removeFaction(i)}>Remove</button>
 
</Fragment>
 
);
 
}
 
return ReactDOM.createPortal(
return ReactDOM.createPortal(
<div className="fade-main">
<div className="fade-main">
<div className="sticky">
<div className="sticky">
@@ -137,8 +185,12 @@ export class EditGameForm extends React.Component {
@@ -137,8 +185,12 @@ export class EditGameForm extends React.Component {
</span>
</span>
</div>
</div>
<div className="">
<div className="">
 
 
<form id="gameCreationForm" onSubmit={this.handleGameCreation}></form>
 
<form id="factionAddFrom" onSubmit={this.handleFactionAdd}></form>
 
<form onSubmit={this.handleGameSave}>
<form onSubmit={this.handleGameSave}>
<h1>Demo Game Creation</h1>
<h1>Demo Game Editor</h1>
<br />
<br />
<input
<input
placeholder="Game name"
placeholder="Game name"
@@ -146,6 +198,8 @@ export class EditGameForm extends React.Component {
@@ -146,6 +198,8 @@ export class EditGameForm extends React.Component {
value={this.state.gamename}
value={this.state.gamename}
onChange={this.handleChange}
onChange={this.handleChange}
id="editGameNameInput"
id="editGameNameInput"
 
form="gameCreationForm"
 
required
/>
/>
<br />
<br />
<input
<input
@@ -155,6 +209,8 @@ export class EditGameForm extends React.Component {
@@ -155,6 +209,8 @@ export class EditGameForm extends React.Component {
value={this.state.description}
value={this.state.description}
onChange={this.handleChange}
onChange={this.handleChange}
id="editGameDescriptionInput"
id="editGameDescriptionInput"
 
form="gameCreationForm"
 
required
/>
/>
<br />
<br />
<label className="">Start:</label>
<label className="">Start:</label>
@@ -165,6 +221,8 @@ export class EditGameForm extends React.Component {
@@ -165,6 +221,8 @@ export class EditGameForm extends React.Component {
value={this.state.startDate}
value={this.state.startDate}
onChange={this.handleChange}
onChange={this.handleChange}
id="editGameDateStartInput"
id="editGameDateStartInput"
 
form="gameCreationForm"
 
required
/>
/>
<input
<input
className="formTime"
className="formTime"
@@ -172,7 +230,9 @@ export class EditGameForm extends React.Component {
@@ -172,7 +230,9 @@ export class EditGameForm extends React.Component {
name="startTime"
name="startTime"
value={this.state.startTime}
value={this.state.startTime}
onChange={this.handleChange}
onChange={this.handleChange}
rid="editGameTimeStartInput"
sid="editGameTimeStartInput"
 
form="gameCreationForm"
 
required
/>
/>
<br />
<br />
<label className="">End:</label>
<label className="">End:</label>
@@ -184,6 +244,8 @@ export class EditGameForm extends React.Component {
@@ -184,6 +244,8 @@ export class EditGameForm extends React.Component {
onChange={this.handleChange}
onChange={this.handleChange}
min={this.state.startDate}
min={this.state.startDate}
id="editGameDateEndInput"
id="editGameDateEndInput"
 
form="gameCreationForm"
 
required
/>
/>
<input
<input
className="formTime"
className="formTime"
@@ -192,8 +254,21 @@ export class EditGameForm extends React.Component {
@@ -192,8 +254,21 @@ export class EditGameForm extends React.Component {
value={this.state.endTime}
value={this.state.endTime}
onChange={this.handleChange}
onChange={this.handleChange}
id="editGameTimeEndInput"
id="editGameTimeEndInput"
 
form="gameCreationForm"
 
required
/>
/>
<br />
<br />
 
<br />
 
 
<label>Factions</label>
 
<br />
 
<input name="factionNameInput" value={this.state.factionNameInput} onChange={this.handleChange} placeholder="Add new faction" form="factionAddFrom"></input>
 
<input name="factionPasswordInput" value={this.state.factionPasswordInput} onChange={this.handleChange} placeholder="Faction password" form="factionAddFrom"></input>
 
<button type="submit" form="factionAddFrom">Add</button>
 
<ul>
 
{factions}
 
</ul>
 
<label>Map things</label>
<label>Map things</label>
<br />
<br />
<Map
<Map
@@ -211,7 +286,7 @@ export class EditGameForm extends React.Component {
@@ -211,7 +286,7 @@ export class EditGameForm extends React.Component {
/>
/>
</Map>
</Map>
<br />
<br />
<button id="editGameSubmitButton" type="submit">
<button id="editGameSubmitButton" type="submit" form="gameCreationForm">
Save changes
Save changes
</button>
</button>
<h2>{this.state.errorMsg}</h2>
<h2>{this.state.errorMsg}</h2>
Loading