diff --git a/src/components/GameList.js b/src/components/GameList.js index 20b5d91de6d24d8a291e20984c4f95a7f20cc6e8..4bcf97fe7676dd558d7a3485dfeb45a6bfde2139 100644 --- a/src/components/GameList.js +++ b/src/components/GameList.js @@ -4,7 +4,8 @@ class GameList extends React.Component { constructor(props){ super(props); this.state = { - games: [] + games: [], + selectedGame: null } } @@ -16,7 +17,19 @@ class GameList extends React.Component { } 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() { @@ -35,6 +48,7 @@ class GameList extends React.Component { <select onChange={this.handleChange}> {items} </select> + <button onClick={this.handleEditClick}>Edit game</button> </Fragment> ); }