]> git.ardis.lu - block-hash-calculator/commitdiff
Add basic loading indicator
authorArdis Lu <ardisglu@gmail.com>
Wed, 22 May 2024 04:17:57 +0000 (21:17 -0700)
committerArdis Lu <ardisglu@gmail.com>
Wed, 22 May 2024 04:17:57 +0000 (21:17 -0700)
index.html
style.css

index a872b4145df877021bd0d792c2429dc5db9f76b7..0ef827a05e6e37ea6c38c8f7b76acfa427dd8aa1 100644 (file)
     document.querySelector('form').addEventListener('submit', async e => {
       e.preventDefault();
 
+      if (e.target.hasAttribute('data-loading')) {
+        return;
+      }
+      e.target.setAttribute('data-loading', '');
+      document.querySelector('output').style.setProperty('display', 'none');
+
       const { num, rpc } = Object.fromEntries(new FormData(e.target));
       const response = await fetch(rpc, {
         method: 'POST',
       }
       const { header, rlp, hash } = calculate(block);
 
-      document.querySelector('output').style.setProperty('display', 'unset');
       document.querySelector('#out-header').textContent = `[\n  ${header.join(',\n  ')}\n]`;
       document.querySelector('#out-rlp').textContent = rlp;
       document.querySelector('#out-hash').textContent = hash;
+      document.querySelector('output').style.setProperty('display', 'unset');
+
+      e.target.removeAttribute('data-loading');
     });
   </script>
 </body>
index 592587861eaae5f28489ad974e40c6de147b8dee..df2fb8eec37bc49166b68e3210fa95be23b85dad 100644 (file)
--- a/style.css
+++ b/style.css
@@ -43,6 +43,17 @@ form {
   & * {
     font-size: 1rem;
   }
+
+  &[data-loading] button {
+    cursor: not-allowed;
+    filter: unset;
+    background-color: hsl(216deg 15% 80%);
+  }
+
+  &[data-loading]::after {
+    content: 'Loading...';
+    content: '⏳' / 'Loading...';
+  }
 }
 
 label {
This page took 0.040196 seconds and 4 git commands to generate.