diff --git a/src/components/GameView.js b/src/components/GameView.js index 351850e7f7472abc17d8b669ce5790b77cc072c0..56d10ac831ca868d8fbbe7398b807f71112ca0fb 100644 --- a/src/components/GameView.js +++ b/src/components/GameView.js @@ -167,6 +167,7 @@ export default class GameView extends React.Component { <TaskListButton gameId={this.state.gameInfo.id} role={this.state.role} + factions={this.state.gameInfo.factions} /> )} {this.state.role !== "admin" && this.state.role !== "" && ( diff --git a/src/components/TaskList.js b/src/components/TaskList.js index ce08afc64a2f4ccfab6d1d77cd0f8594e1cce963..250cc92cf5257ed96ab1641228634d2bde003bd5 100644 --- a/src/components/TaskList.js +++ b/src/components/TaskList.js @@ -9,14 +9,12 @@ class TaskList extends React.Component { taskNameInput: "", // >= 3 taskDescriptionInput: "", // no limits tasks: [], - factionlist: [], selectedFactionId: "" }; } componentDidMount() { this.getTasks(this.props.gameId); - this.getFactionlist(this.props.gameId); // TODO: remove if the user is not admin? } getTasks(gameId) { @@ -42,25 +40,6 @@ class TaskList extends React.Component { .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 => { e.preventDefault(); if (this.state.taskNameInput === "") { @@ -206,10 +185,10 @@ class TaskList extends React.Component { } } - let factionlistItems = this.state.factionlist.map(item => { + let factionlistItems = this.props.factions.map(faction => { return ( - <option key={item.factionId} value={item.factionId}> - {item.factionName} + <option key={faction.factionId} value={faction.factionId}> + {faction.factionName} </option> ); }); diff --git a/src/components/TaskListButton.js b/src/components/TaskListButton.js index c0e5f8c1257edaaae2e062fbc8dce562538aa5c1..bb56314129f92204ab45d226b3d0f69593b18d05 100644 --- a/src/components/TaskListButton.js +++ b/src/components/TaskListButton.js @@ -45,7 +45,11 @@ export default class TaskListButton extends React.Component { Tasks </button> {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> );