diff --git a/frontend/src/ts/test/timer-progress.ts b/frontend/src/ts/test/timer-progress.ts index 1937f1c37582..e97f02d94d70 100644 --- a/frontend/src/ts/test/timer-progress.ts +++ b/frontend/src/ts/test/timer-progress.ts @@ -19,49 +19,31 @@ const textEl = document.querySelector( ) as HTMLElement; const miniEl = document.querySelector("#liveStatsMini .time") as HTMLElement; +function showElement(el: HTMLElement): void { + animate(el, { + opacity: [0, 1], + duration: applyReducedMotion(125), + onBegin: () => { + el.classList.remove("hidden"); + }, + }); +} + export function show(): void { if (!TestState.isActive) return; requestDebouncedAnimationFrame("timer-progress.show", () => { if (Config.mode !== "zen" && Config.timerStyle === "bar") { - animate(barOpacityEl, { - opacity: [0, 1], - duration: applyReducedMotion(125), - onBegin: () => { - barOpacityEl.classList.remove("hidden"); - }, - }); - } else if (Config.timerStyle === "text") { - animate(textEl, { - opacity: [0, 1], - duration: applyReducedMotion(125), - onBegin: () => { - textEl.classList.remove("hidden"); - }, - }); - } else if (Config.timerStyle === "flash_mini") { - animate(miniEl, { - opacity: [0, 1], - duration: applyReducedMotion(125), - onBegin: () => { - miniEl.classList.remove("hidden"); - }, - }); - } else if (Config.timerStyle === "flash_text") { - animate(textEl, { - opacity: [0, 1], - duration: applyReducedMotion(125), - onBegin: () => { - textEl.classList.remove("hidden"); - }, - }); - } else if (Config.timerStyle === "mini") { - animate(miniEl, { - opacity: [0, 1], - duration: applyReducedMotion(125), - onBegin: () => { - miniEl.classList.remove("hidden"); - }, - }); + showElement(barOpacityEl); + } else if ( + Config.timerStyle === "text" || + Config.timerStyle === "flash_text" + ) { + showElement(textEl); + } else if ( + Config.timerStyle === "mini" || + Config.timerStyle === "flash_mini" + ) { + showElement(miniEl); } }); } @@ -85,28 +67,30 @@ export function reset(): void { }); } -export function hide(): void { - requestDebouncedAnimationFrame("timer-progress.hide", () => { - animate(barOpacityEl, { - opacity: 0, - duration: applyReducedMotion(125), - }); +function hideElement(el: HTMLElement, hideOnComplete: boolean): void { + const args = { + opacity: 0, + duration: applyReducedMotion(125), + }; - animate(miniEl, { - opacity: 0, - duration: applyReducedMotion(125), - onComplete: () => { - miniEl.classList.add("hidden"); - }, - }); + animate( + el, + hideOnComplete + ? { + ...args, + onComplete: () => { + el.classList.add("hidden"); + }, + } + : args, + ); +} - animate(textEl, { - opacity: 0, - duration: applyReducedMotion(125), - onComplete: () => { - textEl.classList.add("hidden"); - }, - }); +export function hide(): void { + requestDebouncedAnimationFrame("timer-progress.hide", () => { + hideElement(barOpacityEl, false); + hideElement(miniEl, true); + hideElement(textEl, true); }); } @@ -131,6 +115,24 @@ function getCurrentCount(): number { } } +function setTimerHtmlToInputLength(el: HTMLElement, wrapInDiv: boolean): void { + let historyLength = `${TestInput.input.getHistory().length}`; + + if (wrapInDiv) { + historyLength = `