ui: Dismiss notifications without page reload

- Delete only the <li> of the notification using HTMX.
- Notifications list stays open. User can dismiss another notification.
- Decrement notification counter using JavaScript after removing
  notification from the list.
- Added HTMX to every kind of notification.
- Tested dismissing notifications from the top, middle and bottom of the
  list.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Update comment format in .js file]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati authored and Sunil Mohan Adapa committed 2026-02-03 14:16:55 -08:00
1 parent 4e668c8a98
commit 13a575017c
6 files changed
+43 -1

No files matched your search

+21
View File
@@ -298,3 +298,24 @@ document.addEventListener('htmx:afterSwap', function (event) {
window.location.reload();
}
});
/*
* Decrement notification counter badge when a notification is dismissed via
* HTMX.
*/
document.addEventListener('notification-dismissed', function (evt) {
// There are 2 badges on the page. One for mobile navbar and one for desktop
// navbar.
const badges = document.querySelectorAll('.notifications-dropdown .badge');
badges.forEach(badge => {
const count = parseInt(badge.textContent.trim());
if (count > 1) {
badge.textContent = count - 1;
} else {
const dropdowns = document.querySelectorAll('.notifications-dropdown');
dropdowns.forEach(dropdown => dropdown.remove());
}
});
});