Skip to content

Commit

Permalink
Merge pull request #485 from zalando-stups/484-check-for-removing-not…
Browse files Browse the repository at this point in the history
…ifications-should-not-always-run

#484 check for notifications only if there are notification are present
  • Loading branch information
neremic authored Jul 21, 2016
2 parents 4365229 + 72b523c commit 9bbe1c5
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions client/lib/yourturn/src/notification-bar/notification-bar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,44 @@ 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) {
this.startInterval();
} else if (this.state.interval && notifications.length == 0) {
this.stopInterval();
}
}

componentDidMount() {
/**
* Continually dismiss old notifications.
*/
let interval = setInterval(() => {
const { notifications = [] } = this.props;
if (notifications.length > 0) {
this.startInterval();
}
}

componentWillUnmount() {
this.stopInterval();
}

startInterval() {
const interval = setInterval(() => {
this.props.dispatch(Actions.removeNotificationsOlderThan(5000));
}, 5000);
this.setState({
interval
});
}

componentWillUnmount() {
stopInterval() {
this.setState({
interval: false
});
clearInterval(this.state.interval);
}

Expand Down

0 comments on commit 9bbe1c5

Please sign in to comment.