feat: add htmx error toast on error class swap
This commit is contained in:
@@ -54,6 +54,14 @@ onReady(() => {
|
|||||||
toast("Something went wrong");
|
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", () => {
|
document.addEventListener("htmx:sendError", () => {
|
||||||
toast("Network error");
|
toast("Network error");
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user