Dismiss notifications on route change

pull/278/head
Will Piers 2016-10-25 11:11:44 -07:00
parent b879dbf968
commit dab0527bfe
3 changed files with 24 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import SideNavContainer from 'src/side_nav';
import {
publishNotification as publishNotificationAction,
dismissNotification as dismissNotificationAction,
dismissAllNotifications as dismissAllNotificationsAction,
} from 'src/shared/actions/notifications';
const App = React.createClass({
@ -18,6 +19,7 @@ const App = React.createClass({
}).isRequired,
publishNotification: PropTypes.func.isRequired,
dismissNotification: PropTypes.func.isRequired,
dismissAllNotifications: PropTypes.func.isRequired,
notifications: PropTypes.shape({
success: PropTypes.string,
error: PropTypes.string,
@ -33,6 +35,12 @@ const App = React.createClass({
this.props.dismissNotification(type);
},
componentWillReceiveProps(nextProps) {
if (nextProps.location.pathname !== this.props.location.pathname) {
this.props.dismissAllNotifications();
}
},
render() {
const {sourceID} = this.props.params;
@ -95,4 +103,5 @@ function mapStateToProps(state) {
export default connect(mapStateToProps, {
publishNotification: publishNotificationAction,
dismissNotification: dismissNotificationAction,
dismissAllNotifications: dismissAllNotificationsAction,
})(App);

View File

@ -16,3 +16,9 @@ export function dismissNotification(type) {
},
};
}
export function dismissAllNotifications() {
return {
type: 'ALL_NOTIFICATIONS_DISMISSED',
};
}

View File

@ -1,6 +1,11 @@
import u from 'updeep';
export default function notifications(state = {}, action) {
function getInitialState() {
return {};
}
const initialState = getInitialState();
export default function notifications(state = initialState, action) {
switch (action.type) {
case 'NOTIFICATION_RECEIVED': {
const {type, message} = action.payload;
@ -10,6 +15,9 @@ export default function notifications(state = {}, action) {
const {type} = action.payload;
return u(u.omit(type), state);
}
case 'ALL_NOTIFICATIONS_DISMISSED': {
return getInitialState();
}
}
return state;