From 0ee35787b643723d5b4fa023d83b4eb6630089c8 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 26 Mar 2019 19:16:19 +0100
Subject: [PATCH] Fix ajax calls after whoami request; TODO: finish challenges
 system + laucnh games

---
 client/src/views/Hall.vue | 51 +++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue
index 77ca7718..b2ab334f 100644
--- a/client/src/views/Hall.vue
+++ b/client/src/views/Hall.vue
@@ -122,32 +122,37 @@ export default {
       return playerList;
     },
   },
+  watch: {
+    // Watch event "user infos retrieved" (through /whoami)
+    "st.user.id": function(newId) {
+      if (newId > 0) //should always be the case
+      {
+      // Ask server for current corr games (all but mines)
+  //    ajax(
+  //      "/games",
+  //      "GET",
+  //      {excluded: this.st.user.id},
+  //      response => {
+  //        this.games = this.games.concat(response.games);
+  //      }
+  //    );
+      // Also ask for corr challenges (open + sent to me)
+        ajax(
+          "/challenges",
+          "GET",
+          {uid: this.st.user.id},
+          response => {
+            console.log(response.challenges);
+            // TODO: post-treatment on challenges ?
+            this.challenges = this.challenges.concat(response.challenges);
+          }
+        );
+      }
+    },
+  },
   created: function() {
     // Always add myself to players' list
     this.players.push(this.st.user);
-    if (this.st.user.id > 0)
-    {
-    // Ask server for current corr games (all but mines)
-//    ajax(
-//      "/games",
-//      "GET",
-//      {excluded: this.st.user.id},
-//      response => {
-//        this.games = this.games.concat(response.games);
-//      }
-//    );
-    // Also ask for corr challenges (open + sent to me)
-      ajax(
-        "/challenges",
-        "GET",
-        {uid: this.st.user.id},
-        response => {
-          console.log(response.challenges);
-          // TODO: post-treatment on challenges ?
-          this.challenges = this.challenges.concat(response.challenges);
-        }
-      );
-    }
     // 0.1] Ask server for room composition:
     const socketOpenListener = () => {
       this.st.conn.send(JSON.stringify({code:"pollclients"}));
-- 
2.44.0