Skip to content

Commit a646b32

Browse files
committed
fix htmx process, remove bfcache support
1 parent 45f1d57 commit a646b32

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

web_src/js/features/notification.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
import {GET} from '../modules/fetch.ts';
2-
import {toggleElem, type DOMEvent, createElementFromHTML} from '../utils/dom.ts';
2+
import {toggleElem, createElementFromHTML} from '../utils/dom.ts';
33
import {logoutFromWorker} from '../modules/worker.ts';
44

55
const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config;
66
let notificationSequenceNumber = 0;
77

8-
export function initNotificationsTable() {
9-
const table = document.querySelector('#notification_table');
10-
if (!table) return;
11-
12-
// when page restores from bfcache, delete previously clicked items
13-
window.addEventListener('pageshow', (e) => {
14-
if (e.persisted) { // page was restored from bfcache
15-
const table = document.querySelector('#notification_table');
16-
const unreadCountEl = document.querySelector<HTMLElement>('.notifications-unread-count');
17-
let unreadCount = parseInt(unreadCountEl.textContent);
18-
for (const item of table.querySelectorAll('.notifications-item[data-remove="true"]')) {
19-
item.remove();
20-
unreadCount -= 1;
21-
}
22-
unreadCountEl.textContent = String(unreadCount);
23-
}
24-
});
25-
26-
// mark clicked unread links for deletion on bfcache restore
27-
for (const link of table.querySelectorAll<HTMLAnchorElement>('.notifications-item[data-status="1"] .notifications-link')) {
28-
link.addEventListener('click', (e: DOMEvent<MouseEvent>) => {
29-
e.target.closest('.notifications-item').setAttribute('data-remove', 'true');
30-
});
31-
}
32-
}
33-
348
async function receiveUpdateCount(event: MessageEvent) {
359
try {
3610
const data = event.data;
@@ -143,11 +117,11 @@ async function updateNotificationCountWithCallback(callback: (timeout: number, n
143117
}
144118

145119
async function updateNotificationTable() {
146-
const notificationDiv = document.querySelector('#notification_div');
120+
let notificationDiv = document.querySelector('#notification_div');
147121
if (notificationDiv) {
148122
try {
149123
const params = new URLSearchParams(window.location.search);
150-
params.set('div-only', String(true));
124+
params.set('div-only', 'true');
151125
params.set('sequence-number', String(++notificationSequenceNumber));
152126
const response = await GET(`${appSubUrl}/notifications?${params.toString()}`);
153127

@@ -159,7 +133,8 @@ async function updateNotificationTable() {
159133
const el = createElementFromHTML(data);
160134
if (parseInt(el.getAttribute('data-sequence-number')) === notificationSequenceNumber) {
161135
notificationDiv.outerHTML = data;
162-
initNotificationsTable();
136+
notificationDiv = document.querySelector('#notification_div');
137+
window.htmx.process(notificationDiv); // when using htmx, we must always remember to process the new content changed by us
163138
}
164139
} catch (error) {
165140
console.error(error);

web_src/js/index-domready.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {initTableSort} from './features/tablesort.ts';
1515
import {initAdminUserListSearchForm} from './features/admin/users.ts';
1616
import {initAdminConfigs} from './features/admin/config.ts';
1717
import {initMarkupAnchors} from './markup/anchors.ts';
18-
import {initNotificationCount, initNotificationsTable} from './features/notification.ts';
18+
import {initNotificationCount} from './features/notification.ts';
1919
import {initRepoIssueContentHistory} from './features/repo-issue-content.ts';
2020
import {initStopwatch} from './features/stopwatch.ts';
2121
import {initFindFileInRepo} from './features/repo-findfile.ts';
@@ -117,7 +117,6 @@ const initPerformanceTracer = callInitFunctions([
117117
initDashboardRepoList,
118118

119119
initNotificationCount,
120-
initNotificationsTable,
121120

122121
initOrgTeam,
123122

0 commit comments

Comments
 (0)