ui: Use HTMX to eliminate full page reloads

HTMX implementation is limited to HTML and JS files. No changes to Python files.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
Joseph Nuthalapati authored and Sunil Mohan Adapa committed 2026-02-02 13:49:51 -08:00
1 parent 3c5f81ab8c
commit 01cafafcda
3 files changed
+24 -29

No files matched your search

+13 -18
View File
@@ -33,24 +33,6 @@ document.addEventListener('DOMContentLoaded', function (event) {
html.classList.add('js');
});
/*
* Refresh page if marked for refresh.
*/
document.addEventListener('DOMContentLoaded', function () {
const body = document.querySelector('body');
if (body.hasAttribute('data-refresh-page-sec')) {
let seconds = body.getAttribute('data-refresh-page-sec');
seconds = parseInt(seconds, 10);
if (isNaN(seconds))
return;
window.setTimeout(() => {
// Refresh the page without resubmitting the POST data.
window.location = window.location.href;
}, seconds * 1000);
}
});
/*
* Return all submit buttons on the page
*/
@@ -303,3 +285,16 @@ document.addEventListener('click', function (event) {
bsCollapse.hide();
}
});
/*
* Detect when hx-select element is not found in the response and reload the
* page. HTMX unfortunately does not seem to provide a JS event when hx-select
* element is not found in the response. However, in htmx:afterSwap event we can
* see that the target has no children and choose to refresh the whole page.
*/
document.addEventListener('htmx:afterSwap', function (event) {
const target = event.detail.target;
if (target && target.children.length === 0) {
window.location.reload();
}
});