1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Make notification fetching dependent on if the current user is available

This commit is contained in:
Brett Sun 2016-03-10 13:41:36 +01:00
parent 114129588e
commit 30911b5395
2 changed files with 23 additions and 6 deletions

View File

@ -218,7 +218,7 @@ let Header = React.createClass({
{account}
{signup}
</Nav>
<HeaderNotifications />
<HeaderNotifications currentUser={currentUser} />
{navRoutesLinks}
</CollapsibleNav>
</Navbar>

View File

@ -15,14 +15,26 @@ import { getLangText } from '../utils/lang_utils';
let HeaderNotifications = React.createClass({
propTypes: {
currentUser: React.PropTypes.object.isRequired
},
getInitialState() {
return NotificationStore.getState();
},
componentDidMount() {
NotificationStore.listen(this.onChange);
NotificationActions.fetchPieceListNotifications();
NotificationActions.fetchEditionListNotifications();
if (this.props.currentUser.email) {
this.refreshNotifications();
}
},
componentWillReceiveProps(nextProps) {
if (nextProps.currentUser && nextProps.currentUser.email !== this.props.currentUser.email) {
this.refreshNotifications();
}
},
componentWillUnmount() {
@ -58,7 +70,12 @@ let HeaderNotifications = React.createClass({
this.refs.dropdownbutton.setDropdownState(false);
},
getNotifications({ notifications, isPiece }) {
refreshNotifications() {
NotificationActions.fetchPieceListNotifications();
NotificationActions.fetchEditionListNotifications();
},
renderNotifications({ notifications, isPiece }) {
if (notifications.length) {
return (
<div>
@ -107,8 +124,8 @@ let HeaderNotifications = React.createClass({
</span>
}
className="notification-menu">
{this.getNotifications({ notifications: pieceListNotifications, isPiece: true })}
{this.getNotifications({ notifications: editionListNotifications, isPiece: false })}
{this.renderNotifications({ notifications: pieceListNotifications, isPiece: true })}
{this.renderNotifications({ notifications: editionListNotifications, isPiece: false })}
</DropdownButton>
</Nav>
);