From 8325736ccfe74258fbd816ddaf897687c5ad49a9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taneli=20Riihim=C3=A4ki?= <m3034@student.jamk.fi>
Date: Wed, 3 Jul 2019 16:00:23 +0300
Subject: [PATCH] Minor bugfixes, still need some fixin (if you change a game
 from the list while you are tracking, it will break)

---
 components/GameList.js | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/components/GameList.js b/components/GameList.js
index d9404d2..cab9824 100644
--- a/components/GameList.js
+++ b/components/GameList.js
@@ -25,7 +25,8 @@ class GameList extends Component {
       .then(response => response.json())
       .then(games => {
         this.setState({
-          games
+          games,
+          selectedGame: games[0]
         });
       })
       .catch(error => {
@@ -39,7 +40,11 @@ class GameList extends Component {
 
   startTracking() {
     this.intervalID = setInterval(() => {
-      console.log("Nyt träkätää nim birusti.");
+      console.log("Valittu peli: " + this.state.selectedGame);
+      console.log(
+        "Nyt träkätää nim birusti peliä: " + this.state.selectedGame.name
+      );
+      console.log("Tracking: " + this.state.tracking);
     }, 3000);
   }
 
@@ -65,12 +70,13 @@ class GameList extends Component {
           <Picker
             style={styles.picker}
             selectedValue={this.state.selectedGame}
-            onValueChange={(selectedGame, itemIndex) =>
-              this.setState({ selectedGame })
-            }
+            onValueChange={(selectedGame, itemIndex) => {
+              clearInterval(this.intervalID);
+              this.setState({ selectedGame, tracking: "false" });
+            }}
           >
             {this.state.games.map(game => (
-              <Picker.Item label={game.name} value={game.id} />
+              <Picker.Item label={game.name} value={game} />
             ))}
           </Picker>
           <LocationTracker
-- 
GitLab