From 0441568fabf12116cbc6e40b8db338dd817aa3f3 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 9 Mar 2026 16:46:33 -0400 Subject: [PATCH] refactor: Replace window global with direct import in toast-error - Import showToast function directly from toast module - Remove dependency on window global for error handling - Simplify code and improve type safety This change aligns with the ESBuild migration by using proper ES module imports instead of runtime global lookups. --- web/src/toast-error.ts | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/web/src/toast-error.ts b/web/src/toast-error.ts index 7efd62d..51b2d3f 100644 --- a/web/src/toast-error.ts +++ b/web/src/toast-error.ts @@ -1,33 +1,31 @@ import { Alpine } from "./alpine"; +import { showToast } from "./toast"; function showErrorToast(message: string): void { - // Use the global showToast from toast.ts - if (typeof (window as any).showToast !== "undefined") { - (window as any).showToast.error(message, 8000); + showToast(message, "error", 8000); - // Add retry button to the toast - setTimeout(() => { - const toastContainer = document.getElementById("toast-container"); - if (toastContainer && toastContainer.lastElementChild) { - const toast = toastContainer.lastElementChild as HTMLElement; - const retryBtn = document.createElement("button"); - retryBtn.className = - "ml-4 px-3 py-1 bg-white/20 hover:bg-white/30 rounded text-sm font-medium transition-colors"; - retryBtn.textContent = "Retry"; - retryBtn.onclick = function () { - window.location.reload(); - }; + // Add retry button to the toast + setTimeout(() => { + const toastContainer = document.getElementById("toast-container"); + if (toastContainer && toastContainer.lastElementChild) { + const toast = toastContainer.lastElementChild as HTMLElement; + const retryBtn = document.createElement("button"); + retryBtn.className = + "ml-4 px-3 py-1 bg-white/20 hover:bg-white/30 rounded text-sm font-medium transition-colors"; + retryBtn.textContent = "Retry"; + retryBtn.onclick = function () { + window.location.reload(); + }; - // Insert before the close button - const closeBtn = toast.querySelector(".toast-close"); - if (closeBtn && closeBtn.parentElement) { - closeBtn.parentElement.insertBefore(retryBtn, closeBtn); - } else { - toast.appendChild(retryBtn); - } + // Insert before the close button + const closeBtn = toast.querySelector(".toast-close"); + if (closeBtn && closeBtn.parentElement) { + closeBtn.parentElement.insertBefore(retryBtn, closeBtn); + } else { + toast.appendChild(retryBtn); } - }, 100); - } + } + }, 100); } export { showErrorToast };