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