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.
This commit is contained in:
2026-03-09 16:46:33 -04:00
parent 4480fb7817
commit 0441568fab
+22 -24
View File
@@ -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 };