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