Attempt to show something on Hall page when no live challenges or games
[vchess.git] / client / src / views / Hall.vue
index 4c73df2..fa42e83 100644 (file)
@@ -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);