-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathnotifications.ts
46 lines (41 loc) · 1.17 KB
/
notifications.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Reducer } from 'redux';
import {
SHOW_NOTIFICATION,
ShowNotificationAction,
HIDE_NOTIFICATION,
HideNotificationAction,
RESET_NOTIFICATION,
ResetNotificationAction,
NotificationPayload,
} from '../../actions/notificationActions';
import { UNDO, UndoAction } from '../../actions/undoActions';
type ActionTypes =
| ShowNotificationAction
| HideNotificationAction
| ResetNotificationAction
| UndoAction
| { type: 'OTHER_TYPE' };
type State = NotificationPayload[];
const initialState = [];
const notificationsReducer: Reducer<State> = (
previousState = initialState,
action: ActionTypes
) => {
switch (action.type) {
case SHOW_NOTIFICATION:
return previousState.concat(action.payload);
case HIDE_NOTIFICATION:
case UNDO:
return previousState.slice(1);
case RESET_NOTIFICATION:
return initialState;
default:
return previousState;
}
};
export default notificationsReducer;
/**
* Returns the first available notification to show
* @param {Object} state - Redux state
*/
export const getNotification = state => state.admin.notifications[0];