feat: add htmx error toast on error class swap

This commit is contained in:
2026-06-06 16:53:56 +02:00
committed by Milas Holsting
parent 9b2846af33
commit 33b0d4b3c6

View File

@@ -54,6 +54,14 @@ onReady(() => {
toast("Something went wrong");
});
document.addEventListener("htmx:afterSwap", (event) => {
const detail = event as CustomEvent<{ target?: EventTarget | null }>;
const target = detail.detail?.target;
if (!(target instanceof HTMLElement)) return;
if (!target.classList.contains("error")) return;
toast("Failed to load content");
});
document.addEventListener("htmx:sendError", () => {
toast("Network error");
});