From 96d59a8303da65c453946223731b0c96709475bb Mon Sep 17 00:00:00 2001
From: Joni Laukka <joni.laukka.overflow@gmail.com>
Date: Mon, 24 Jun 2019 10:45:48 +0300
Subject: [PATCH] Get selected game info when edit game button is clicked

---
 src/components/GameList.js | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/components/GameList.js b/src/components/GameList.js
index 20b5d91..4bcf97f 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>
     );
   }
-- 
GitLab