From 700362e55b2b60329b4d4cdd138865203093e720 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Wed, 7 Dec 2022 16:57:18 -0800
Subject: [PATCH] Timeout on image generation after 60 seconds

If the image doesn't come back, just hide the spinner and bring back
the form so they can try again.
---
 index.html | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/index.html b/index.html
index f88dd5b..d055878 100644
--- a/index.html
+++ b/index.html
@@ -115,6 +115,7 @@ mute.addEventListener("click", () => {
     const safety= document.querySelector("#safety");
 
     const spinner = document.querySelector("#spinner");
+    var spinner_timeout;
 
     comment_form.addEventListener('submit', function(e) {
         e.preventDefault();
@@ -142,19 +143,25 @@ mute.addEventListener("click", () => {
         images.prepend(figure);
     });
 
+    function hide_spinner() {
+        zombo_form.style.display = "grid";
+        spinner.style.display = "none";
+    }
+
     zombo_form.addEventListener('submit', function(e) {
         e.preventDefault();
         /* Hide the form and show spinner while generation is happening. */
         zombo_form.style.display = "none";
         spinner.style.display = "block";
+        spinner_timeout = setTimeout(hide_spinner, 60000);
         socket.emit('generate', {"prompt": prompt.value, "code": code.value});
         prompt.value = '';
     });
 
     socket.on('generation-done', () => {
         /* Re-display the form and hide spinner now that generation is over. */
-        zombo_form.style.display = "grid";
-        spinner.style.display = "none";
+        cancelTimeout(spinner_timeout);
+        hide_spinner();
     });
 
     // TODO: Dynamically generate many different prompts here
-- 
2.45.2