Fix challenge persistence issue
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 3 Jul 2019 15:21:55 +0000 (17:21 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 3 Jul 2019 15:21:55 +0000 (17:21 +0200)
client/src/store.js
client/src/views/Hall.vue

index 055fff9..070b22c 100644 (file)
@@ -50,7 +50,7 @@ export const store =
     };
     const socketCloseListener = () => {
       this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid);
     };
     const socketCloseListener = () => {
       this.state.conn = new WebSocket(params.socketUrl + "/?sid=" + mysid);
-    }
+    };
     this.state.conn.onclose = socketCloseListener;
     const supportedLangs = ["en","es","fr"];
     this.state.lang = localStorage["lang"] ||
     this.state.conn.onclose = socketCloseListener;
     const supportedLangs = ["en","es","fr"];
     this.state.lang = localStorage["lang"] ||
index c7dc588..6a57622 100644 (file)
@@ -113,6 +113,15 @@ export default {
   created: function() {
     // Always add myself to players' list
     this.people.push(this.st.user);
   created: function() {
     // Always add myself to players' list
     this.people.push(this.st.user);
+    // Retrieve live challenge (not older than 30 minute) if any:
+    const chall = JSON.parse(localStorage.getItem("challenge") || "false");
+    if (!!chall)
+    {
+      if ((Date.now() - chall.added)/1000 <= 30*60)
+        this.challenges.push(chall);
+      else
+        localStorage.removeItem("challenge");
+    }
     if (this.st.user.id > 0)
     {
     // Ask server for current corr games (all but mines)
     if (this.st.user.id > 0)
     {
     // Ask server for current corr games (all but mines)
@@ -407,6 +416,7 @@ export default {
         chall.vname = vname;
         chall.from = this.st.user;
         this.challenges.push(chall);
         chall.vname = vname;
         chall.from = this.st.user;
         this.challenges.push(chall);
+        localStorage.setItem("challenge", JSON.stringify(chall));
         document.getElementById("modalNewgame").checked = false;
       };
       const cIdx = this.challenges.findIndex(
         document.getElementById("modalNewgame").checked = false;
       };
       const cIdx = this.challenges.findIndex(