File size: 581 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const initialState = {
  toasts: [],
};

/*
Payload shape:

payload: {
  kind: 'error' | 'success',
  message: string
}
*/
export default function toasts(state = initialState, action) {
  switch (action.type) {
    case 'ADD_TOAST': {
      return Object.assign({}, state, {
        toasts: [...state.toasts, action.payload],
      });
    }
    case 'REMOVE_TOAST': {
      const toasts = state.toasts.filter(toast => {
        return toast.id !== action.id;
      });
      return Object.assign({}, state, {
        toasts,
      });
    }
    default:
      return state;
  }
}