From 30911b53955c1c132350b7fcd97093ff4985bafb Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Thu, 10 Mar 2016 13:41:36 +0100 Subject: [PATCH] Make notification fetching dependent on if the current user is available --- js/components/header.js | 2 +- js/components/header_notification.js | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/js/components/header.js b/js/components/header.js index 181e14c0..487b3f20 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -218,7 +218,7 @@ let Header = React.createClass({ {account} {signup} - + {navRoutesLinks} diff --git a/js/components/header_notification.js b/js/components/header_notification.js index 3ec50fa3..8672f1db 100644 --- a/js/components/header_notification.js +++ b/js/components/header_notification.js @@ -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 (
@@ -107,8 +124,8 @@ let HeaderNotifications = React.createClass({ } 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 })} );