logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

alerts.js (646B)


  1. import {
  2. ALERT_SHOW,
  3. ALERT_DISMISS,
  4. ALERT_CLEAR,
  5. } from '../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. };