Dismiss notifications on route change
parent
b879dbf968
commit
dab0527bfe
|
@ -5,6 +5,7 @@ import SideNavContainer from 'src/side_nav';
|
||||||
import {
|
import {
|
||||||
publishNotification as publishNotificationAction,
|
publishNotification as publishNotificationAction,
|
||||||
dismissNotification as dismissNotificationAction,
|
dismissNotification as dismissNotificationAction,
|
||||||
|
dismissAllNotifications as dismissAllNotificationsAction,
|
||||||
} from 'src/shared/actions/notifications';
|
} from 'src/shared/actions/notifications';
|
||||||
|
|
||||||
const App = React.createClass({
|
const App = React.createClass({
|
||||||
|
@ -18,6 +19,7 @@ const App = React.createClass({
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
publishNotification: PropTypes.func.isRequired,
|
publishNotification: PropTypes.func.isRequired,
|
||||||
dismissNotification: PropTypes.func.isRequired,
|
dismissNotification: PropTypes.func.isRequired,
|
||||||
|
dismissAllNotifications: PropTypes.func.isRequired,
|
||||||
notifications: PropTypes.shape({
|
notifications: PropTypes.shape({
|
||||||
success: PropTypes.string,
|
success: PropTypes.string,
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
|
@ -33,6 +35,12 @@ const App = React.createClass({
|
||||||
this.props.dismissNotification(type);
|
this.props.dismissNotification(type);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (nextProps.location.pathname !== this.props.location.pathname) {
|
||||||
|
this.props.dismissAllNotifications();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {sourceID} = this.props.params;
|
const {sourceID} = this.props.params;
|
||||||
|
|
||||||
|
@ -95,4 +103,5 @@ function mapStateToProps(state) {
|
||||||
export default connect(mapStateToProps, {
|
export default connect(mapStateToProps, {
|
||||||
publishNotification: publishNotificationAction,
|
publishNotification: publishNotificationAction,
|
||||||
dismissNotification: dismissNotificationAction,
|
dismissNotification: dismissNotificationAction,
|
||||||
|
dismissAllNotifications: dismissAllNotificationsAction,
|
||||||
})(App);
|
})(App);
|
||||||
|
|
|
@ -16,3 +16,9 @@ export function dismissNotification(type) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function dismissAllNotifications() {
|
||||||
|
return {
|
||||||
|
type: 'ALL_NOTIFICATIONS_DISMISSED',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import u from 'updeep';
|
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) {
|
switch (action.type) {
|
||||||
case 'NOTIFICATION_RECEIVED': {
|
case 'NOTIFICATION_RECEIVED': {
|
||||||
const {type, message} = action.payload;
|
const {type, message} = action.payload;
|
||||||
|
@ -10,6 +15,9 @@ export default function notifications(state = {}, action) {
|
||||||
const {type} = action.payload;
|
const {type} = action.payload;
|
||||||
return u(u.omit(type), state);
|
return u(u.omit(type), state);
|
||||||
}
|
}
|
||||||
|
case 'ALL_NOTIFICATIONS_DISMISSED': {
|
||||||
|
return getInitialState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in New Issue