2024-07-07 15:32:30 +00:00
|
|
|
import {showErrorToast} from './modules/toast.ts';
|
2024-08-28 16:32:38 +00:00
|
|
|
import 'idiomorph/dist/idiomorph-ext.js'; // https://github.com/bigskysoftware/idiomorph#htmx
|
|
|
|
import type {HtmxResponseInfo} from 'htmx.org';
|
2024-01-30 14:45:54 +00:00
|
|
|
|
2024-08-28 16:32:38 +00:00
|
|
|
type HtmxEvent = Event & {detail: HtmxResponseInfo};
|
2024-02-16 02:52:25 +00:00
|
|
|
|
2024-01-30 14:45:54 +00:00
|
|
|
// https://htmx.org/reference/#config
|
2024-07-11 10:20:51 +00:00
|
|
|
window.htmx.config.requestClass = 'is-loading';
|
|
|
|
window.htmx.config.scrollIntoViewOnBoost = false;
|
2024-01-30 14:45:54 +00:00
|
|
|
|
|
|
|
// https://htmx.org/events/#htmx:sendError
|
2024-08-28 16:32:38 +00:00
|
|
|
document.body.addEventListener('htmx:sendError', (event: HtmxEvent) => {
|
2024-01-30 14:45:54 +00:00
|
|
|
// TODO: add translations
|
|
|
|
showErrorToast(`Network error when calling ${event.detail.requestConfig.path}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
// https://htmx.org/events/#htmx:responseError
|
2024-08-28 16:32:38 +00:00
|
|
|
document.body.addEventListener('htmx:responseError', (event: HtmxEvent) => {
|
2024-01-30 14:45:54 +00:00
|
|
|
// TODO: add translations
|
|
|
|
showErrorToast(`Error ${event.detail.xhr.status} when calling ${event.detail.requestConfig.path}`);
|
|
|
|
});
|