From 421d2843a64ba3f94e773b4ea50238bbf94c742e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 28 Oct 2023 22:38:46 +0200 Subject: no spinner on error --- web/script/transition.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'web') diff --git a/web/script/transition.ts b/web/script/transition.ts index 9b00523..6c7df14 100644 --- a/web/script/transition.ts +++ b/web/script/transition.ts @@ -39,6 +39,8 @@ async function transition_to(href: string, back?: boolean) { } function show_error(mesg: string) { + if (spinner_timeout) clearTimeout(spinner_timeout) + if (spinner_element) spinner_element.remove() document.body.append(e("span", { class: "jst-error" }, mesg)) } @@ -58,11 +60,13 @@ function prepare_load(href: string, back?: boolean) { if (!back) window.history.pushState({}, "", href) document.head.innerHTML = head document.body.outerHTML = body + spinner_timeout = spinner_element = undefined globalThis.dispatchEvent(new Event("DOMContentLoaded")) fade(true) } } +let spinner_timeout: number | undefined, spinner_element: HTMLElement | undefined; function fade(dir: boolean) { const overlay = document.createElement("div") overlay.classList.add("jst-fade") @@ -74,8 +78,8 @@ function fade(dir: boolean) { return new Promise(res => { setTimeout(() => { if (dir) document.body.removeChild(overlay) - setTimeout(() => { - overlay.append(e("div", { class: "jst-spinner" }, "This is a spinner.")) + spinner_timeout = setTimeout(() => { + overlay.append(spinner_element = e("div", { class: "jst-spinner" }, "This is a spinner.")) }, 500) res() }, duration) -- cgit v1.2.3-70-g09d2