Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions src/NotificationSystem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ class NotificationSystem extends React.Component {

_didNotificationRemoved(uid) {
var notification;
var notifications = this.state.notifications.filter(function(toCheck) {
if (toCheck.uid === uid) {
notification = toCheck;
return false;
}
return true;
});

if (this._isMounted) {
this.setState({ notifications: notifications });
}
this.setState(prevState => {
var notifications = prevState.notifications.filter(function(toCheck) {
if (toCheck.uid === uid) {
notification = toCheck;
return false;
}
return true;
});

if (notification && notification.onRemove) {
notification.onRemove(notification);
return { notifications };
}, () => {
if (notification && notification.onRemove) {
notification.onRemove(notification);
}
});
}
}

Expand Down Expand Up @@ -163,19 +165,16 @@ class NotificationSystem extends React.Component {
}
}

if (this.props.newOnTop) {
notifications.unshift(_notification);
} else {
notifications.push(_notification);
}


if (typeof _notification.onAdd === 'function') {
notification.onAdd(_notification);
}

this.setState({
notifications: notifications
this.setState(prevState => {
const otherNotifications = prevState.notifications.filter(item => item.uid !== _notification.uid);
return {
notifications:
this.props.newOnTop ? [_notification].concat(otherNotifications) : otherNotifications.concat([_notification])
};
}, () => {
if (typeof _notification.onAdd === 'function') {
notification.onAdd(_notification);
}
});

return _notification;
Expand Down