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

Factions are now props in tasklist

parent e1fa53aa
No related branches found
No related tags found
3 merge requests!46Development to testing,!41Notifications + small updates,!39Notification view
...@@ -167,6 +167,7 @@ export default class GameView extends React.Component { ...@@ -167,6 +167,7 @@ export default class GameView extends React.Component {
<TaskListButton <TaskListButton
gameId={this.state.gameInfo.id} gameId={this.state.gameInfo.id}
role={this.state.role} role={this.state.role}
factions={this.state.gameInfo.factions}
/> />
)} )}
{this.state.role !== "admin" && this.state.role !== "" && ( {this.state.role !== "admin" && this.state.role !== "" && (
......
...@@ -9,14 +9,12 @@ class TaskList extends React.Component { ...@@ -9,14 +9,12 @@ class TaskList extends React.Component {
taskNameInput: "", // >= 3 taskNameInput: "", // >= 3
taskDescriptionInput: "", // no limits taskDescriptionInput: "", // no limits
tasks: [], tasks: [],
factionlist: [],
selectedFactionId: "" selectedFactionId: ""
}; };
} }
componentDidMount() { componentDidMount() {
this.getTasks(this.props.gameId); this.getTasks(this.props.gameId);
this.getFactionlist(this.props.gameId); // TODO: remove if the user is not admin?
} }
getTasks(gameId) { getTasks(gameId) {
...@@ -42,25 +40,6 @@ class TaskList extends React.Component { ...@@ -42,25 +40,6 @@ class TaskList extends React.Component {
.catch(error => console.log(error)); .catch(error => console.log(error));
} }
getFactionlist(gameId) {
fetch(`${process.env.REACT_APP_API_URL}/game/${gameId}`, {
method: "GET"
})
.then(result => {
if (!result.ok) {
throw Error(result.responseText);
} else {
return result.json();
}
})
.then(result => {
this.setState({
factionlist: result.factions
});
})
.catch(error => console.log(error));
}
handleTaskCreation = e => { handleTaskCreation = e => {
e.preventDefault(); e.preventDefault();
if (this.state.taskNameInput === "") { if (this.state.taskNameInput === "") {
...@@ -206,10 +185,10 @@ class TaskList extends React.Component { ...@@ -206,10 +185,10 @@ class TaskList extends React.Component {
} }
} }
let factionlistItems = this.state.factionlist.map(item => { let factionlistItems = this.props.factions.map(faction => {
return ( return (
<option key={item.factionId} value={item.factionId}> <option key={faction.factionId} value={faction.factionId}>
{item.factionName} {faction.factionName}
</option> </option>
); );
}); });
......
...@@ -45,7 +45,11 @@ export default class TaskListButton extends React.Component { ...@@ -45,7 +45,11 @@ export default class TaskListButton extends React.Component {
Tasks Tasks
</button> </button>
{this.state.open && ( {this.state.open && (
<TaskList gameId={this.props.gameId} role={this.props.role} /> <TaskList
gameId={this.props.gameId}
role={this.props.role}
factions={this.props.factions}
/>
)} )}
</Fragment> </Fragment>
); );
......
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