From 299fc35685f8f9ed9cc357d2fdafd175c154f889 Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 23 Apr 2024 11:35:32 +0200 Subject: [PATCH] impr(loader): delay showing the loading bar by 125ms to avoid it flashing on screen for things that take a short time !nuf --- frontend/src/ts/elements/loader.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/frontend/src/ts/elements/loader.ts b/frontend/src/ts/elements/loader.ts index 2ea8b0f2e..369823120 100644 --- a/frontend/src/ts/elements/loader.ts +++ b/frontend/src/ts/elements/loader.ts @@ -1,7 +1,25 @@ +let timeout: NodeJS.Timeout | null = null; + +let visible = false; + +function clearTimeout(): void { + if (timeout !== null) { + window.clearTimeout(timeout); + timeout = null; + } +} + export function show(): void { - $("#backgroundLoader").stop(true, true).fadeIn(125); + if (visible) return; + timeout = setTimeout(() => { + $("#backgroundLoader").stop(true, true).show(); + }, 125); + visible = true; } export function hide(): void { + if (!visible) return; + clearTimeout(); $("#backgroundLoader").stop(true, true).fadeOut(125); + visible = false; }