-
Notifications
You must be signed in to change notification settings - Fork 14
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
Pause ALL my notifications #910
Conversation
@thecalcc can you review this? |
|
||
class NotificationList extends React.Component<any, any> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's quick, can you type the props as well?
)} | ||
ref={(elem: any) => this.elem = elem} | ||
title={gettext('Notifications')}> | ||
<h3 className="a11y-only">Notification bell</h3> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add gettext here, we shouldn't care if it's hidden
|
||
export const UPDATE_NOTIFICATION_COUNT = 'UPDATE_NOTIFICATION_COUNT'; | ||
export function updateNotificationCount(count: any) { | ||
return {type: UPDATE_NOTIFICATION_COUNT, count}; | ||
} | ||
|
||
export const INIT_DATA = 'INIT_DATA'; | ||
export function initData(data: any) { | ||
return {type: INIT_DATA, data}; | ||
export function initData(notificationData: any, profileData: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you type props here?
if (this.formRef.current == null) { | ||
throw new Error('ref missing'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this meant to stop the function execution? What does throwing an error serve us here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few reasons for this. One is to stop the execution in case it is null
and another is to tell compiler that if execution is not stopped, it should be treated as non-null
.
We could also achieve this using if/else
or early return. But - it is preferrable to throw errors when we're guarding against invalid application states.
const hasErrors = [...inputs].some(input => { | ||
return input.checkValidity() !== true; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason here to spread inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
querySelectorAll
returns a collection which is not an array and doesn't have array methods. @dzonidoo use Array.from(inputs)
instead.
const newMaxDate = new Date(state); | ||
newMaxDate.setDate(newMaxDate.getDate() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do this in one line, but if you think readability is better this way, let's keep it.
Add 1
to a constant that explains what its purpose is, we can't have magic numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when 0
and 1
are used, most of the times it's obvious what's being done thus 0/1 are not considered magic numbers.
disabledMaxOption(state: string | undefined) { | ||
if (state != '' && state != undefined) { | ||
const newMaxDate = new Date(state); | ||
newMaxDate.setDate(newMaxDate.getDate() - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same goes for here, I bet 1 is some kind of offset, I understand it but others would need to know also
type="date" | ||
name="date-from" | ||
className="form-control" | ||
onChange={(event) => this.updateDate(event, 'pauseFrom')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we're expecting a return from this function which isn't the case, can you add curly braces to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thecalcc you shouldn't approve a PR until your comments are addressed/answered.
I'll also block the merging so after you finish the review, I'll take a look too.
I clicked approve by mistake, my bad |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would component prop types take too long to be properly typed?
Actually yes... |
@dzonidoo ok got it. What about not adding new redux forms, is it possible that we don't use redux? |
@thecalcc its not.. we need it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this.formRef.current == null) { | ||
throw new Error('ref missing'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few reasons for this. One is to stop the execution in case it is null
and another is to tell compiler that if execution is not stopped, it should be treated as non-null
.
We could also achieve this using if/else
or early return. But - it is preferrable to throw errors when we're guarding against invalid application states.
const hasErrors = [...inputs].some(input => { | ||
return input.checkValidity() !== true; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
querySelectorAll
returns a collection which is not an array and doesn't have array methods. @dzonidoo use Array.from(inputs)
instead.
const newMaxDate = new Date(state); | ||
newMaxDate.setDate(newMaxDate.getDate() + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when 0
and 1
are used, most of the times it's obvious what's being done thus 0/1 are not considered magic numbers.
where did you see Redux being used for forms @thecalcc ? If data that you gather from a form is being sent to a redux action, it doesn't make it a redux based form. Those are when validation and form data while typing live inside redux store. |
assets/user-profile/components/EditNotificationScheduleModal.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also check one other comment I left unresolved
@@ -70,9 +85,11 @@ class NotificationList extends React.Component<any, any> { | |||
} | |||
|
|||
render() { | |||
const notificationArePaused: boolean = new Date(this.props.fullUser.notification_schedule?.pauseFrom ?? '') < new Date(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should't be creating a date from an empty string. If it's not defined, simply set notificationArePaused
to false
and compare dates only if it's defined.
https://sofab.atlassian.net/browse/CPCN-186
Checklist
lodash.get
with optional chaining for modified code segments