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.

41 lines
1.3 KiB

  1. import { COMPOSE_SUBMIT_FAIL, COMPOSE_UPLOAD_FAIL } from '../actions/compose';
  2. import { FOLLOW_SUBMIT_FAIL } from '../actions/follow';
  3. import { REBLOG_FAIL, FAVOURITE_FAIL } from '../actions/interactions';
  4. import { TIMELINE_REFRESH_FAIL } from '../actions/timelines';
  5. import { NOTIFICATION_DISMISS } from '../actions/notifications';
  6. import Immutable from 'immutable';
  7. const initialState = Immutable.List();
  8. function notificationFromError(state, error) {
  9. let n = Immutable.Map({
  10. message: ''
  11. });
  12. if (error.response) {
  13. n = n.withMutations(map => {
  14. map.set('message', error.response.statusText);
  15. map.set('title', `${error.response.status}`);
  16. });
  17. } else {
  18. n = n.set('message', `${error}`);
  19. }
  20. return state.push(n);
  21. };
  22. export default function notifications(state = initialState, action) {
  23. switch(action.type) {
  24. case COMPOSE_SUBMIT_FAIL:
  25. case COMPOSE_UPLOAD_FAIL:
  26. case FOLLOW_SUBMIT_FAIL:
  27. case REBLOG_FAIL:
  28. case FAVOURITE_FAIL:
  29. case TIMELINE_REFRESH_FAIL:
  30. return notificationFromError(state, action.error);
  31. case NOTIFICATION_DISMISS:
  32. return state.clear();
  33. default:
  34. return state;
  35. }
  36. };