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