Attempt to show something on Hall page when no live challenges or games
[vchess.git] / client / src / views / Hall.vue
index 829e5b7..fa42e83 100644 (file)
@@ -227,7 +227,7 @@ export default {
         vid: parseInt(localStorage.getItem("vid")) || 0,
         to: "", //name of challenged player (if any)
         cadence: localStorage.getItem("cadence") || "",
-        randomness: parseInt(localStorage.getItem("randomness")) || 2,
+        randomness: parseInt(localStorage.getItem("challRandomness")) || 2,
         // VariantRules object, stored to not interfere with
         // diagrams of targetted challenges:
         V: null,
@@ -394,8 +394,31 @@ export default {
       dispCorr || localStorage.getItem("type-challenges") || "live";
     const showGtype =
       dispCorr || localStorage.getItem("type-games") || "live";
-    this.setDisplay("c", showCtype);
-    this.setDisplay("g", showGtype);
+    this.setDisplay('c', showCtype);
+    this.setDisplay('g', showGtype);
+    // Attempt to show something (at least a few correspondance challenges):
+    setTimeout(
+      () => {
+        const types = ["corr", "live"];
+        for (let i of [0,1]) {
+          if (
+            this.gdisplay == types[i] &&
+            this.games.length > 0 &&
+            this.games.every(g => g.type == types[1-i])
+          ) {
+            this.setDisplay('g', types[1-i]);
+          }
+          if (
+            this.cdisplay == types[i] &&
+            this.challenges.length > 0 &&
+            this.challenges.every(c => c.type == types[1-i])
+          ) {
+            this.setDisplay('c', types[1-i]);
+          }
+        }
+      },
+      1500
+    );
   },
   beforeDestroy: function() {
     document.removeEventListener('visibilitychange', this.visibilityChange);
@@ -845,8 +868,7 @@ export default {
       const vModule = await import("@/variants/" + vname + ".js");
       this.newchallenge.V = vModule.VariantRules;
       this.newchallenge.vname = vname;
-      if (!!cb)
-        cb();
+      if (!!cb) cb();
     },
     trySetNewchallDiag: function() {
       if (!this.newchallenge.fen) {
@@ -872,7 +894,7 @@ export default {
       this.newchallenge.vid = pchall.vid;
       this.newchallenge.cadence = pchall.cadence;
       this.newchallenge.randomness = pchall.randomness;
-      this.issueNewChallenge();
+      this.loadNewchallVariant(this.issueNewChallenge);
     },
     issueNewChallenge: async function() {
       if (!!(this.newchallenge.cadence.match(/^[0-9]+$/)))
@@ -970,7 +992,7 @@ export default {
         // Remember cadence  + vid for quicker further challenges:
         localStorage.setItem("cadence", chall.cadence);
         localStorage.setItem("vid", chall.vid);
-        localStorage.setItem("randomness", chall.randomness);
+        localStorage.setItem("challRandomness", chall.randomness);
         document.getElementById("modalNewgame").checked = false;
         // Show the challenge if not on current display
         if (