From ef8ffcf060c9e505f880efa0b00ae76d69e3617e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 29 Mar 2024 11:00:10 +0000 Subject: [PATCH 1/4] Remove jQuery class from the notification count - Switched from jQuery class functions to plain JavaScript `classList` - Tested the notification count and it works as before Signed-off-by: Yarden Shoham --- web_src/js/features/notification.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index d9f6e50202c40..a3d61189d3ab1 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -1,5 +1,6 @@ import $ from 'jquery'; import {GET} from '../modules/fetch.js'; +import {hideElem, showElem} from '../utils/dom.js'; const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config; let notificationSequenceNumber = 0; @@ -177,14 +178,15 @@ async function updateNotificationCount() { const data = await response.json(); - const $notificationCount = $('.notification_count'); if (data.new === 0) { - $notificationCount.addClass('tw-hidden'); + hideElem('.notification_count'); } else { - $notificationCount.removeClass('tw-hidden'); + showElem('.notification_count'); } - $notificationCount.text(`${data.new}`); + for (const el of document.getElementsByClassName('notification_count')) { + el.textContent = `${data.new}`; + } return `${data.new}`; } catch (error) { From 9f83631c3f5fc7ed8e54227e3245a2e78ee929c5 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 29 Mar 2024 12:47:28 +0000 Subject: [PATCH 2/4] Use toggleElem Co-authored-by: wxiaoguang --- web_src/js/features/notification.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index a3d61189d3ab1..2de640e6742c0 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -1,6 +1,6 @@ import $ from 'jquery'; import {GET} from '../modules/fetch.js'; -import {hideElem, showElem} from '../utils/dom.js'; +import {toggleElem} from '../utils/dom.js'; const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config; let notificationSequenceNumber = 0; @@ -178,11 +178,7 @@ async function updateNotificationCount() { const data = await response.json(); - if (data.new === 0) { - hideElem('.notification_count'); - } else { - showElem('.notification_count'); - } + toggleElem('.notification_count', data.new !== 0); for (const el of document.getElementsByClassName('notification_count')) { el.textContent = `${data.new}`; From 99d4ea3b08f426ea29eefcb1dd07258a66db5c5c Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 29 Mar 2024 13:06:29 +0000 Subject: [PATCH 3/4] Use elementsCall --- web_src/js/features/notification.js | 7 ++----- web_src/js/utils/dom.js | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index 2de640e6742c0..fd18345fe3b22 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -1,6 +1,6 @@ import $ from 'jquery'; import {GET} from '../modules/fetch.js'; -import {toggleElem} from '../utils/dom.js'; +import {elementsCall, toggleElem} from '../utils/dom.js'; const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config; let notificationSequenceNumber = 0; @@ -179,10 +179,7 @@ async function updateNotificationCount() { const data = await response.json(); toggleElem('.notification_count', data.new !== 0); - - for (const el of document.getElementsByClassName('notification_count')) { - el.textContent = `${data.new}`; - } + elementsCall('.notification_count', (el) => el.textContent = `${data.new}`); return `${data.new}`; } catch (error) { diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 59c455e2ab483..6894c1a834749 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -1,6 +1,6 @@ import {debounce} from 'throttle-debounce'; -function elementsCall(el, func, ...args) { +export function elementsCall(el, func, ...args) { if (typeof el === 'string' || el instanceof String) { el = document.querySelectorAll(el); } From 892cdc75a882b890356c0a572679efbf8c167f8e Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 29 Mar 2024 15:16:46 +0000 Subject: [PATCH 4/4] Revert "Use elementsCall" This reverts commit 99d4ea3b08f426ea29eefcb1dd07258a66db5c5c. --- web_src/js/features/notification.js | 7 +++++-- web_src/js/utils/dom.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web_src/js/features/notification.js b/web_src/js/features/notification.js index fd18345fe3b22..2de640e6742c0 100644 --- a/web_src/js/features/notification.js +++ b/web_src/js/features/notification.js @@ -1,6 +1,6 @@ import $ from 'jquery'; import {GET} from '../modules/fetch.js'; -import {elementsCall, toggleElem} from '../utils/dom.js'; +import {toggleElem} from '../utils/dom.js'; const {appSubUrl, notificationSettings, assetVersionEncoded} = window.config; let notificationSequenceNumber = 0; @@ -179,7 +179,10 @@ async function updateNotificationCount() { const data = await response.json(); toggleElem('.notification_count', data.new !== 0); - elementsCall('.notification_count', (el) => el.textContent = `${data.new}`); + + for (const el of document.getElementsByClassName('notification_count')) { + el.textContent = `${data.new}`; + } return `${data.new}`; } catch (error) { diff --git a/web_src/js/utils/dom.js b/web_src/js/utils/dom.js index 6894c1a834749..59c455e2ab483 100644 --- a/web_src/js/utils/dom.js +++ b/web_src/js/utils/dom.js @@ -1,6 +1,6 @@ import {debounce} from 'throttle-debounce'; -export function elementsCall(el, func, ...args) { +function elementsCall(el, func, ...args) { if (typeof el === 'string' || el instanceof String) { el = document.querySelectorAll(el); }