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

Get selected game info when edit game button is clicked

parent d51508db
No related branches found
No related tags found
4 merge requests!21Development,!15Get game creation to user-marker-database-interactions,!13Resolve "Pelinluontilomake",!11Combine gamelist and new game form
...@@ -4,7 +4,8 @@ class GameList extends React.Component { ...@@ -4,7 +4,8 @@ class GameList extends React.Component {
constructor(props){ constructor(props){
super(props); super(props);
this.state = { this.state = {
games: [] games: [],
selectedGame: null
} }
} }
...@@ -16,7 +17,19 @@ class GameList extends React.Component { ...@@ -16,7 +17,19 @@ class GameList extends React.Component {
} }
handleChange = (e) =>{ handleChange = (e) =>{
console.log(e.target.value); this.setState({
selectedGame: e.target.value
});
}
handleEditClick = (e) => {
if(this.state.selectedGame === null){alert('No game selected');}
else{
fetch('http://localhost:5000/game/' + this.state.selectedGame)
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.log(error))
}
} }
render() { render() {
...@@ -35,6 +48,7 @@ class GameList extends React.Component { ...@@ -35,6 +48,7 @@ class GameList extends React.Component {
<select onChange={this.handleChange}> <select onChange={this.handleChange}>
{items} {items}
</select> </select>
<button onClick={this.handleEditClick}>Edit game</button>
</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