2017-07-28 17:56:49 +00:00
|
|
|
import { ReducerRegistry } from '../base/redux';
|
|
|
|
|
|
|
|
import {
|
|
|
|
HIDE_NOTIFICATION,
|
2017-08-02 18:15:55 +00:00
|
|
|
SET_NOTIFICATIONS_ENABLED,
|
2017-07-28 17:56:49 +00:00
|
|
|
SHOW_NOTIFICATION
|
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The initial state of the feature notifications.
|
|
|
|
*
|
|
|
|
* @type {array}
|
|
|
|
*/
|
2017-08-02 18:15:55 +00:00
|
|
|
const DEFAULT_STATE = {
|
|
|
|
enabled: true,
|
|
|
|
notifications: []
|
|
|
|
};
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reduces redux actions which affect the display of notifications.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The current redux state.
|
|
|
|
* @param {Object} action - The redux action to reduce.
|
|
|
|
* @returns {Object} The next redux state which is the result of reducing the
|
|
|
|
* specified {@code action}.
|
|
|
|
*/
|
|
|
|
ReducerRegistry.register('features/notifications',
|
|
|
|
(state = DEFAULT_STATE, action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case HIDE_NOTIFICATION:
|
2017-08-02 18:15:55 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
notifications: state.notifications.filter(
|
|
|
|
notification => notification.uid !== action.uid)
|
|
|
|
};
|
|
|
|
|
|
|
|
case SET_NOTIFICATIONS_ENABLED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
enabled: action.enabled
|
|
|
|
};
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
case SHOW_NOTIFICATION:
|
2017-08-02 18:15:55 +00:00
|
|
|
return {
|
2017-07-28 17:56:49 +00:00
|
|
|
...state,
|
2017-08-02 18:15:55 +00:00
|
|
|
notifications: [
|
|
|
|
...state.notifications,
|
|
|
|
{
|
|
|
|
component: action.component,
|
|
|
|
props: action.props,
|
|
|
|
timeout: action.timeout,
|
|
|
|
uid: action.uid
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2017-07-28 17:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|