Skip to content

Commit

Permalink
#484 check for notifications now only runs if there are notifications…
Browse files Browse the repository at this point in the history
… present
  • Loading branch information
Norman Eremic committed Jul 21, 2016
1 parent 4365229 commit aa1f496
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions client/lib/yourturn/src/notification-bar/notification-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Notification.displayName = 'Notification';
// ========

class NotificationBar extends React.Component {
constructor() {
super();
constructor(props) {
super(props);
this.state = {
interval: false
};
Expand All @@ -34,17 +34,38 @@ class NotificationBar extends React.Component {
dismiss(id) {
this.props.dispatch(Actions.removeNotification(id));
}

componentWillReceiveProps(nextProps) {
const { notifications = [] } = nextProps;

if (!this.state.interval && notifications.length > 0) {
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
} else if (this.state.interval && notifications.length == 0) {
clearInterval(this.state.interval);
this.setState({
interval: false
});
}
}

componentDidMount() {
/**
* Continually dismiss old notifications.
*/
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
const { notifications = [] } = this.props;
if (notifications.length > 0) {
let interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
}
}

componentWillUnmount() {
Expand Down

0 comments on commit aa1f496

Please sign in to comment.