fix: #12044, only load notifications when opening dropdown

update code to use bs5 class "show"
This commit is contained in:
Barış Soner Uşaklı
2023-09-27 17:23:55 -04:00
parent 2627e9742a
commit dbd0a715f2

View File

@@ -1,25 +1,24 @@
'use strict'; 'use strict';
define('forum/header/notifications', ['components'], function (components) { define('forum/header/notifications', function () {
const notifications = {}; const notifications = {};
notifications.prepareDOM = function () { notifications.prepareDOM = function () {
const notifContainer = components.get('notifications'); const notifTrigger = $('[component="notifications"] [data-bs-toggle="dropdown"]');
const notifTrigger = notifContainer.children('a'); if (!notifTrigger.length) {
const notifList = components.get('notifications/list'); return;
}
notifTrigger.on('click', function (e) { notifTrigger.on('show.bs.dropdown', (ev) => {
e.preventDefault(); requireAndCall('loadNotifications', $(ev.target).parent().find('[component="notifications/list"]'));
if (notifContainer.hasClass('open')) {
return;
}
requireAndCall('loadNotifications', notifList);
}); });
if (notifTrigger.parents('.dropdown').hasClass('open')) { notifTrigger.each((index, el) => {
requireAndCall('loadNotifications', notifList); const dropdownEl = $(el).parent().find('.dropdown-menu');
} if (dropdownEl.hasClass('show')) {
requireAndCall('loadNotifications', dropdownEl.find('[component="notifications/list"]'));
}
});
socket.removeListener('event:new_notification', onNewNotification); socket.removeListener('event:new_notification', onNewNotification);
socket.on('event:new_notification', onNewNotification); socket.on('event:new_notification', onNewNotification);