Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug 1486511: Add user notifications (#1253)
- Loading branch information
Showing
15 changed files
with
708 additions
and
19 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
.user-notification { | ||
border-top: 1px solid #333941; | ||
cursor: default; | ||
padding: 0; | ||
} | ||
|
||
.user-notification:first-child { | ||
border-color: #272a2f; | ||
} | ||
|
||
.user-notification:first-child:hover { | ||
border-color: #333941; | ||
} | ||
|
||
.user-notification.unread { | ||
background: #3F4752; | ||
} | ||
|
||
.user-notification.read { | ||
animation-duration: 2s; | ||
animation-name: fadeout-background; | ||
} | ||
|
||
@keyframes fadeout-background { | ||
0% { | ||
background: #3F4752; | ||
} | ||
|
||
50% { | ||
background: #3F4752; | ||
} | ||
|
||
100% { | ||
background: #272a2f; | ||
} | ||
} | ||
|
||
.user-notification .item-content { | ||
display: block; | ||
padding: 10px; | ||
} | ||
|
||
.user-notification span { | ||
float: none; | ||
} | ||
|
||
.user-notification a { | ||
color: #F36; | ||
display: inline; | ||
} | ||
|
||
.user-notification .verb { | ||
color: #EBEBEB; | ||
padding: 0 3px; | ||
} | ||
|
||
.user-notification .message { | ||
padding: 10px; | ||
} | ||
|
||
.user-notification .message { | ||
padding: 10px; | ||
} | ||
|
||
/* Users can include HTML tags in their messages */ | ||
.user-notification .message h1, | ||
.user-notification .message h2, | ||
.user-notification .message h3, | ||
.user-notification .message h4, | ||
.user-notification .message h5, | ||
.user-notification .message h6 { | ||
color: #EBEBEB; | ||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: bold; | ||
letter-spacing: 0; | ||
text-transform: none; | ||
} | ||
|
||
.user-notification .message h1 { | ||
font-size: 18px; | ||
} | ||
|
||
.user-notification .message h2 { | ||
font-size: 16px; | ||
} | ||
|
||
.user-notification .message p { | ||
padding: 5px 0; | ||
} | ||
|
||
.user-notification .message ol { | ||
margin-left: 1.2em; | ||
} | ||
|
||
.user-notification .message ul { | ||
list-style: inside; | ||
} | ||
/* End message styling */ | ||
|
||
.user-notification .timeago { | ||
color: #888888; | ||
display: block; | ||
font-size: 11px; | ||
font-weight: normal; | ||
margin-top: 8px; | ||
text-align: right; | ||
text-transform: uppercase; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* @flow */ | ||
|
||
import * as React from 'react'; | ||
import TimeAgo from 'react-timeago'; | ||
|
||
import './UserNotification.css'; | ||
|
||
|
||
type Props = { | ||
notification: Object, | ||
}; | ||
|
||
type State = {| | ||
markAsRead: boolean, | ||
|}; | ||
|
||
|
||
/** | ||
* Renders a single notification in the notifications menu. | ||
*/ | ||
export default class UserNotification extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
markAsRead: false, | ||
}; | ||
} | ||
|
||
componentDidUpdate(prevProps: Props) { | ||
if (prevProps.notification.unread && !this.props.notification.unread) { | ||
this.setState({ | ||
markAsRead: true, | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
const { notification } = this.props; | ||
|
||
let className = 'user-notification'; | ||
if (notification.unread) { | ||
className += ' unread'; | ||
} | ||
else if (this.state.markAsRead) { | ||
className += ' read'; | ||
} | ||
|
||
return <li | ||
className={ className } | ||
data-id={ notification.id } | ||
data-level={ notification.level } | ||
> | ||
<div className="item-content"> | ||
<span className="actor"> | ||
<a href={ notification.actor.url }> | ||
{ notification.actor.anchor } | ||
</a> | ||
</span> | ||
|
||
<span className="verb">{ notification.verb }</span> | ||
|
||
{ !notification.target ? null : | ||
<span className="target"> | ||
<a href={ notification.target.url }> | ||
{ notification.target.anchor } | ||
</a> | ||
</span> | ||
} | ||
|
||
<TimeAgo | ||
className="timeago" | ||
date={ notification.date_iso } | ||
title={ `${notification.date} UTC` } | ||
/> | ||
|
||
{ !notification.description ? null : | ||
<div | ||
className="message" | ||
// We can safely use notification.description as it is either generated | ||
// by the code or sanitized when coming from the DB. See: | ||
// - pontoon.projects.forms.NotificationsForm() | ||
// - pontoon.base.forms.HtmlField() | ||
dangerouslySetInnerHTML={{ __html: notification.description }} | ||
/> | ||
} | ||
</div> | ||
</li>; | ||
} | ||
} |
Oops, something went wrong.