This commit is contained in:
Anbraten 2024-09-19 18:54:22 +02:00
parent a2e1c1475d
commit 85cf27e9cf
No known key found for this signature in database
GPG Key ID: B1222603899C6B25
3 changed files with 12 additions and 5 deletions

6
package-lock.json generated
View File

@ -29,6 +29,7 @@
"esbuild-loader": "4.2.2",
"escape-goat": "4.0.0",
"fast-glob": "3.3.2",
"htmx-ext-ws": "2.0.1",
"htmx.org": "2.0.2",
"idiomorph": "0.3.0",
"jquery": "3.7.1",
@ -10547,6 +10548,11 @@
"entities": "^4.4.0"
}
},
"node_modules/htmx-ext-ws": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/htmx-ext-ws/-/htmx-ext-ws-2.0.1.tgz",
"integrity": "sha512-gddFXSzzHH9I7RWm93pGfGIKGPUo2lDtLiK8uoPn8mp/ivC0KQx4LAuQdXdg13S78lBD40Fs/mLEM/xoJCeJxQ=="
},
"node_modules/htmx.org": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/htmx.org/-/htmx.org-2.0.2.tgz",

View File

@ -28,6 +28,7 @@
"esbuild-loader": "4.2.2",
"escape-goat": "4.0.0",
"fast-glob": "3.3.2",
"htmx-ext-ws": "2.0.1",
"htmx.org": "2.0.2",
"idiomorph": "0.3.0",
"jquery": "3.7.1",

View File

@ -1,6 +1,6 @@
import {showErrorToast} from './modules/toast.ts';
import 'idiomorph/dist/idiomorph-ext.js'; // https://github.com/bigskysoftware/idiomorph#htmx
import 'htmx.org/dist/ext/ws.js';
import 'htmx-ext-ws';
import type {HtmxResponseInfo} from 'htmx.org';
type HtmxEvent = Event & {detail: HtmxResponseInfo};
@ -12,19 +12,19 @@ window.htmx.config.scrollIntoViewOnBoost = false;
// https://htmx.org/events/#htmx:sendError
document.body.addEventListener('htmx:sendError', (event: HtmxEvent) => {
// TODO: add translations
showErrorToast(`Network error when calling ${e.detail.requestConfig.path}`);
showErrorToast(`Network error when calling ${event.detail.requestConfig.path}`);
});
// https://htmx.org/events/#htmx:responseError
document.body.addEventListener('htmx:responseError', (event: HtmxEvent) => {
// TODO: add translations
showErrorToast(`Error ${e.detail.xhr.status} when calling ${e.detail.requestConfig.path}`);
showErrorToast(`Error ${event.detail.xhr.status} when calling ${event.detail.requestConfig.path}`);
});
// TODO: move websocket creation to SharedWorker by overriding htmx.createWebSocket
document.body.addEventListener('htmx:wsOpen', (e) => {
const socket = e.detail.socketWrapper;
document.body.addEventListener('htmx:wsOpen', (event: HtmxEvent) => {
const socket = event.detail.socketWrapper;
socket.send(
JSON.stringify({action: 'subscribe', data: {url: window.location.href}})
);