aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/notification.js
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2023-05-25 04:31:26 +0200
committerGitHub <noreply@github.com>2023-05-25 02:31:26 +0000
commit27c221aa5db116e2cc90afbfa9b92f2a220af853 (patch)
treecd28eb0b3e8f60c52c9244cc955c68dc8b08acff /web_src/js/features/notification.js
parent309354c70ee994a1e8f261d7bc24e7473e601d02 (diff)
downloadgitea-27c221aa5db116e2cc90afbfa9b92f2a220af853.tar.gz
gitea-27c221aa5db116e2cc90afbfa9b92f2a220af853.zip
Rework notifications list (#24812)
- Replace `<table>` with flexbox - Add issue modification time and issue number - Remove big title - Replace tabs with menu items - Add clicked item deletion on back button cache restoration --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src/js/features/notification.js')
-rw-r--r--web_src/js/features/notification.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js
index 6c056c6d14..0c24d36e56 100644
--- a/web_src/js/features/notification.js
+++ b/web_src/js/features/notification.js
@@ -4,6 +4,30 @@ const {appSubUrl, csrfToken, notificationSettings, assetVersionEncoded} = window
let notificationSequenceNumber = 0;
export function initNotificationsTable() {
+ const table = document.getElementById('notification_table');
+ if (!table) return;
+
+ // when page restores from bfcache, delete previously clicked items
+ window.addEventListener('pageshow', (e) => {
+ if (e.persisted) { // page was restored from bfcache
+ const table = document.getElementById('notification_table');
+ const unreadCountEl = document.querySelector('.notifications-unread-count');
+ let unreadCount = parseInt(unreadCountEl.textContent);
+ for (const item of table.querySelectorAll('.notifications-item[data-remove="true"]')) {
+ item.remove();
+ unreadCount -= 1;
+ }
+ unreadCountEl.textContent = unreadCount;
+ }
+ });
+
+ // mark clicked unread links for deletion on bfcache restore
+ for (const link of table.querySelectorAll('.notifications-item[data-status="1"] .notifications-link')) {
+ link.addEventListener('click', (e) => {
+ e.target.closest('.notifications-item').setAttribute('data-remove', 'true');
+ });
+ }
+
$('#notification_table .button').on('click', function () {
(async () => {
const data = await updateNotification(