« get me outta code hell

content, client: handle random data failing to load - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-15 18:56:10 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-15 18:56:58 -0400
commit28371f6e029fb86ba536bf4c20e787dba44d202b (patch)
tree8fef79f97b06d136ccbe920f9729d5dedc984e51 /src
parent91f00a36b33d13630ea7a9ac6fcd03110b0f1a73 (diff)
content, client: handle random data failing to load
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/listRandomPageLinks.js3
-rw-r--r--src/static/client3.js15
-rw-r--r--src/static/site5.css7
-rw-r--r--src/strings-default.yaml5
4 files changed, 27 insertions, 3 deletions
diff --git a/src/content/dependencies/listRandomPageLinks.js b/src/content/dependencies/listRandomPageLinks.js
index 5e2972ad..18585696 100644
--- a/src/content/dependencies/listRandomPageLinks.js
+++ b/src/content/dependencies/listRandomPageLinks.js
@@ -119,6 +119,9 @@ export default {
 
         html.tag('p', {id: 'data-loaded-line'},
           language.$('listingPage.other.randomPages.dataLoadedLine')),
+
+        html.tag('p', {id: 'data-error-line'},
+          language.$('listingPage.other.randomPages.dataErrorLine')),
       ],
 
       showSkipToSection: true,
diff --git a/src/static/client3.js b/src/static/client3.js
index 31eddfe9..d2f2bd17 100644
--- a/src/static/client3.js
+++ b/src/static/client3.js
@@ -287,6 +287,7 @@ if (
 ) {
   const dataLoadingLine = document.getElementById('data-loading-line');
   const dataLoadedLine = document.getElementById('data-loaded-line');
+  const dataErrorLine = document.getElementById('data-error-line');
 
   dataLoadingLine.style.display = 'block';
 
@@ -300,8 +301,20 @@ if (
 
       dataLoadingLine.style.display = 'none';
       dataLoadedLine.style.display = 'block';
-    });
+    })
+    .catch(() => {
+      const info = scriptedLinkInfo;
+
+      for (const a of info.randomLinks) {
+        const href = determineRandomLinkHref(a);
+        if (!href) {
+          a.removeAttribute('href');
+        }
+      }
 
+      dataLoadingLine.style.display = 'none';
+      dataErrorLine.style.display = 'block';
+    });
 }
 
 // Data & info card ---------------------------------------
diff --git a/src/static/site5.css b/src/static/site5.css
index 9111f3a6..bb83fe67 100644
--- a/src/static/site5.css
+++ b/src/static/site5.css
@@ -793,10 +793,15 @@ html[data-url-key="localized.albumCommentary"] li.no-commentary {
 }
 
 html[data-url-key="localized.listing"][data-url-value0="random"] #data-loading-line,
-html[data-url-key="localized.listing"][data-url-value0="random"] #data-loaded-line {
+html[data-url-key="localized.listing"][data-url-value0="random"] #data-loaded-line,
+html[data-url-key="localized.listing"][data-url-value0="random"] #data-error-line {
   display: none;
 }
 
+html[data-url-key="localized.listing"][data-url-value0="random"] #content a:not([href]) {
+  opacity: 0.7;
+}
+
 /* Images */
 
 .image-container {
diff --git a/src/strings-default.yaml b/src/strings-default.yaml
index a21758e7..e6b8d6db 100644
--- a/src/strings-default.yaml
+++ b/src/strings-default.yaml
@@ -1556,7 +1556,7 @@ listingPage:
           If your browser doesn't support relatively modern JavaScript
           or you've disabled it, these links won't work - sorry.
 
-      # dataLoadingLine, dataLoadedLine:
+      # dataLoadingLine, dataLoadedLine, dataErrorLine:
       #   Since the links on this page depend on access to a fairly
       #   large data file that is downloaded separately and in the
       #   background, these messages indicate the status of that
@@ -1568,6 +1568,9 @@ listingPage:
       dataLoadedLine: >-
         (Data files have finished being downloaded. The links should work!)
 
+      dataErrorLine: >-
+        (Data files failed to download. Sorry, some of these links won't work right now!)
+
       chunk:
 
         title: