-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Remove jQuery class from the notification count #30172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ef8ffcf
9f83631
99d4ea3
06129a3
892cdc7
6d75d26
283ea3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -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}`; | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's better to introduce a util function:
I have seen too many loops for the refactoring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe export Line 3 in 849eee8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, it is a good candidate, meanwhile I guess it needs some rewriting and renaming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to push here for nits There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would name it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also just use built-in methods, a bit more verbose but does the same: Array.from(document.querySelectorAll('.foo')).forEach((el) => el.checked = true); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks there is document.querySelectorAll('.foo').forEach((el) => el.checked = true); @wxiaoguang @yardenshoham is that acceptable to you? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Lint converts it into a for-of loop.
Honestly I think using a loop is OK, I don't see a big need to avoid it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yes the rule thinks it's So yes, I prefer revert to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
|
||||
return `${data.new}`; | ||||
} catch (error) { | ||||
|
Uh oh!
There was an error while loading. Please reload this page.