* feat(notifications): implement a react/redux notification system * squash into impl explicit timeout, style * ref(notifications): convert toastr notifications to use react * ref(toastr): remove library * squash into conversion: pass timeout * squash into clean remove from debian patch
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import { ReducerRegistry } from '../base/redux';
|
|
|
|
import {
|
|
HIDE_NOTIFICATION,
|
|
SHOW_NOTIFICATION
|
|
} from './actionTypes';
|
|
|
|
/**
|
|
* The initial state of the feature notifications.
|
|
*
|
|
* @type {array}
|
|
*/
|
|
const DEFAULT_STATE = [];
|
|
|
|
/**
|
|
* 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:
|
|
return state.filter(
|
|
notification => notification.uid !== action.uid);
|
|
|
|
case SHOW_NOTIFICATION:
|
|
return [
|
|
...state,
|
|
{
|
|
component: action.component,
|
|
props: action.props,
|
|
timeout: action.timeout,
|
|
uid: action.uid
|
|
}
|
|
];
|
|
}
|
|
|
|
return state;
|
|
});
|