Files
bookhoard/web/src/toast-error.ts
T
john-okeefe b78aacd320 feat: Add new Alpine.js component TypeScript files
Extracted inline JavaScript from templates into proper TypeScript modules:

- api-explorer-docs.ts: API explorer page functionality
- collection-rules.ts: Collection rules management page
- index.ts: Homepage theme and auth redirect
- login.ts: Login page theme initialization
- profile-modal.ts: Profile modal close and escape key
- profile.ts: Profile page delete account
- register.ts: Registration page theme init
- toast-error.ts: Error toast with retry button
- unlinked_books.ts: Unlinked books management page

Each file:
- Uses ES imports (showToast, getToken, etc.)
- Has proper TypeScript types
- Registers with Alpine.js via Alpine.global()
- Uses async/await for API calls
2026-03-08 21:35:47 -04:00

38 lines
1.2 KiB
TypeScript

import { Alpine } from "./alpine";
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);
// 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);
}
}
}, 100);
}
}
export { showErrorToast };
Alpine.global("toastError", {
showErrorToast,
});