-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[core] Batch small changes #20823
Merged
oliviertassinari
merged 14 commits into
mui:master
from
oliviertassinari:batch-small-changes-v4
Apr 29, 2020
Merged
[core] Batch small changes #20823
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
42c32dc
Close the developer survey
oliviertassinari 16bdb64
[l10n] Improve fr-FR value
oliviertassinari 611a655
[docs] Automatically redirect pt to pt-BR
oliviertassinari cea1d62
[Autocomplete] Improve the heading structure
oliviertassinari a4ec727
[core] Most of the time, we use aria-hidden as a boolean
oliviertassinari a638ef8
[l10n] Fix dark mode support of the demo
oliviertassinari ee96096
[docs] Add a new introduction series of videos
oliviertassinari bee571e
[docs] Warn about the a11y implication of changing htmlf ont size
oliviertassinari 3f0bed0
[Autocomplete] Use useControlled instead of custom logic
oliviertassinari 7e64043
[docs] Fix centering of code on mobile
oliviertassinari 18bee68
[docs] Display a loading state for notifications
oliviertassinari c517ab8
fix ci
oliviertassinari 73fc569
Merge branch 'master' into batch-small-changes-v4
oliviertassinari 03d3b2f
Josh review
oliviertassinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import { useSelector, useDispatch } from 'react-redux'; | |||||
import { makeStyles } from '@material-ui/core/styles'; | ||||||
import NotificationsIcon from '@material-ui/icons/Notifications'; | ||||||
import Tooltip from '@material-ui/core/Tooltip'; | ||||||
import CircularProgress from '@material-ui/core/CircularProgress'; | ||||||
import IconButton from '@material-ui/core/IconButton'; | ||||||
import Badge from '@material-ui/core/Badge'; | ||||||
import Typography from '@material-ui/core/Typography'; | ||||||
|
@@ -32,6 +33,11 @@ const useStyles = makeStyles((theme) => ({ | |||||
display: 'flex', | ||||||
flexDirection: 'column', | ||||||
}, | ||||||
loading: { | ||||||
display: 'flex', | ||||||
justifyContent: 'center', | ||||||
margin: theme.spacing(1, 0), | ||||||
}, | ||||||
divider: { | ||||||
margin: theme.spacing(1, 0), | ||||||
}, | ||||||
|
@@ -53,34 +59,34 @@ export default function Notifications() { | |||||
const messages = useSelector((state) => state.notifications.messages); | ||||||
const lastSeen = useSelector((state) => state.notifications.lastSeen); | ||||||
|
||||||
const messageList = (messages || []) | ||||||
.filter((message) => { | ||||||
if ( | ||||||
message.userLanguage && | ||||||
message.userLanguage !== userLanguage && | ||||||
message.userLanguage !== navigator.language.substring(0, 2) | ||||||
) { | ||||||
return false; | ||||||
} | ||||||
return true; | ||||||
}) | ||||||
.reverse(); | ||||||
|
||||||
const unseenNotificationsCount = messageList.reduce( | ||||||
(count, message) => (message.id > lastSeen ? count + 1 : count), | ||||||
0, | ||||||
); | ||||||
const messageList = messages | ||||||
? messages | ||||||
.filter((message) => { | ||||||
if ( | ||||||
message.userLanguage && | ||||||
message.userLanguage !== userLanguage && | ||||||
message.userLanguage !== navigator.language.substring(0, 2) | ||||||
) { | ||||||
return false; | ||||||
} | ||||||
return true; | ||||||
}) | ||||||
.reverse() | ||||||
: null; | ||||||
|
||||||
const handleToggle = () => { | ||||||
setOpen((prevOpen) => !prevOpen); | ||||||
setTooltipOpen(false); | ||||||
dispatch({ | ||||||
type: ACTION_TYPES.NOTIFICATIONS_CHANGE, | ||||||
payload: { | ||||||
lastSeen: messageList[0].id, | ||||||
}, | ||||||
}); | ||||||
document.cookie = `lastSeenNotification=${messageList[0].id};path=/;max-age=31536000`; | ||||||
|
||||||
if (messageList) { | ||||||
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. All though it shouldn't happen if this is an empty array below will still throw.
Suggested change
|
||||||
dispatch({ | ||||||
type: ACTION_TYPES.NOTIFICATIONS_CHANGE, | ||||||
payload: { | ||||||
lastSeen: messageList[0].id, | ||||||
}, | ||||||
}); | ||||||
document.cookie = `lastSeenNotification=${messageList[0].id};path=/;max-age=31536000`; | ||||||
} | ||||||
}; | ||||||
|
||||||
React.useEffect(() => { | ||||||
|
@@ -142,7 +148,17 @@ export default function Notifications() { | |||||
data-ga-event-category="AppBar" | ||||||
data-ga-event-action="toggleNotifications" | ||||||
> | ||||||
<Badge color="secondary" badgeContent={unseenNotificationsCount}> | ||||||
<Badge | ||||||
color="secondary" | ||||||
badgeContent={ | ||||||
messageList | ||||||
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. You could use |
||||||
? messageList.reduce( | ||||||
(count, message) => (message.id > lastSeen ? count + 1 : count), | ||||||
0, | ||||||
) | ||||||
: 0 | ||||||
} | ||||||
> | ||||||
<NotificationsIcon /> | ||||||
</Badge> | ||||||
</IconButton> | ||||||
|
@@ -165,31 +181,37 @@ export default function Notifications() { | |||||
<Grow in={open} {...TransitionProps}> | ||||||
<Paper className={classes.paper}> | ||||||
<List className={classes.list}> | ||||||
{messageList.map((message, index) => ( | ||||||
<React.Fragment key={message.id}> | ||||||
<ListItem alignItems="flex-start" className={classes.listItem}> | ||||||
<Typography gutterBottom>{message.title}</Typography> | ||||||
<Typography gutterBottom variant="body2"> | ||||||
<span | ||||||
id="notification-message" | ||||||
dangerouslySetInnerHTML={{ __html: message.text }} | ||||||
/> | ||||||
</Typography> | ||||||
{message.date && ( | ||||||
<Typography variant="caption" color="textSecondary"> | ||||||
{new Date(message.date).toLocaleDateString('en-US', { | ||||||
year: 'numeric', | ||||||
month: 'long', | ||||||
day: 'numeric', | ||||||
})} | ||||||
{messageList ? ( | ||||||
messageList.map((message, index) => ( | ||||||
<React.Fragment key={message.id}> | ||||||
<ListItem alignItems="flex-start" className={classes.listItem}> | ||||||
<Typography gutterBottom>{message.title}</Typography> | ||||||
<Typography gutterBottom variant="body2"> | ||||||
<span | ||||||
id="notification-message" | ||||||
dangerouslySetInnerHTML={{ __html: message.text }} | ||||||
/> | ||||||
</Typography> | ||||||
)} | ||||||
</ListItem> | ||||||
{index < messageList.length - 1 ? ( | ||||||
<Divider className={classes.divider} /> | ||||||
) : null} | ||||||
</React.Fragment> | ||||||
))} | ||||||
{message.date && ( | ||||||
<Typography variant="caption" color="textSecondary"> | ||||||
{new Date(message.date).toLocaleDateString('en-US', { | ||||||
year: 'numeric', | ||||||
month: 'long', | ||||||
day: 'numeric', | ||||||
})} | ||||||
</Typography> | ||||||
)} | ||||||
</ListItem> | ||||||
{index < messageList.length - 1 ? ( | ||||||
<Divider className={classes.divider} /> | ||||||
) : null} | ||||||
</React.Fragment> | ||||||
)) | ||||||
) : ( | ||||||
<div className={classes.loading}> | ||||||
<CircularProgress size={32} /> | ||||||
</div> | ||||||
)} | ||||||
</List> | ||||||
</Paper> | ||||||
</Grow> | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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 advantage?
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.
It’s more explicit but ultimately doesn’t need to happen.