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:
+22
-24
@@ -1,33 +1,31 @@
|
|||||||
import { Alpine } from "./alpine";
|
import { Alpine } from "./alpine";
|
||||||
|
import { showToast } from "./toast";
|
||||||
|
|
||||||
function showErrorToast(message: string): void {
|
function showErrorToast(message: string): void {
|
||||||
// Use the global showToast from toast.ts
|
showToast(message, "error", 8000);
|
||||||
if (typeof (window as any).showToast !== "undefined") {
|
|
||||||
(window as any).showToast.error(message, 8000);
|
|
||||||
|
|
||||||
// Add retry button to the toast
|
// Add retry button to the toast
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const toastContainer = document.getElementById("toast-container");
|
const toastContainer = document.getElementById("toast-container");
|
||||||
if (toastContainer && toastContainer.lastElementChild) {
|
if (toastContainer && toastContainer.lastElementChild) {
|
||||||
const toast = toastContainer.lastElementChild as HTMLElement;
|
const toast = toastContainer.lastElementChild as HTMLElement;
|
||||||
const retryBtn = document.createElement("button");
|
const retryBtn = document.createElement("button");
|
||||||
retryBtn.className =
|
retryBtn.className =
|
||||||
"ml-4 px-3 py-1 bg-white/20 hover:bg-white/30 rounded text-sm font-medium transition-colors";
|
"ml-4 px-3 py-1 bg-white/20 hover:bg-white/30 rounded text-sm font-medium transition-colors";
|
||||||
retryBtn.textContent = "Retry";
|
retryBtn.textContent = "Retry";
|
||||||
retryBtn.onclick = function () {
|
retryBtn.onclick = function () {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Insert before the close button
|
// Insert before the close button
|
||||||
const closeBtn = toast.querySelector(".toast-close");
|
const closeBtn = toast.querySelector(".toast-close");
|
||||||
if (closeBtn && closeBtn.parentElement) {
|
if (closeBtn && closeBtn.parentElement) {
|
||||||
closeBtn.parentElement.insertBefore(retryBtn, closeBtn);
|
closeBtn.parentElement.insertBefore(retryBtn, closeBtn);
|
||||||
} else {
|
} else {
|
||||||
toast.appendChild(retryBtn);
|
toast.appendChild(retryBtn);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 100);
|
}
|
||||||
}
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { showErrorToast };
|
export { showErrorToast };
|
||||||
|
|||||||
Reference in New Issue
Block a user