You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
659 B

  1. import {
  2. ALERT_SHOW,
  3. ALERT_DISMISS,
  4. ALERT_CLEAR,
  5. } from 'flavours/glitch/actions/alerts';
  6. import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
  7. const initialState = ImmutableList([]);
  8. export default function alerts(state = initialState, action) {
  9. switch(action.type) {
  10. case ALERT_SHOW:
  11. return state.push(ImmutableMap({
  12. key: state.size > 0 ? state.last().get('key') + 1 : 0,
  13. title: action.title,
  14. message: action.message,
  15. }));
  16. case ALERT_DISMISS:
  17. return state.filterNot(item => item.get('key') === action.alert.key);
  18. case ALERT_CLEAR:
  19. return state.clear();
  20. default:
  21. return state;
  22. }
  23. };