闭社主体 forked from https://github.com/tootsuite/mastodon
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.

57 lines
1.7 KiB

  1. import {
  2. REPORT_INIT,
  3. REPORT_SUBMIT_REQUEST,
  4. REPORT_SUBMIT_SUCCESS,
  5. REPORT_SUBMIT_FAIL,
  6. REPORT_CANCEL,
  7. REPORT_STATUS_TOGGLE
  8. } from '../actions/reports';
  9. import Immutable from 'immutable';
  10. const initialState = Immutable.Map({
  11. new: Immutable.Map({
  12. isSubmitting: false,
  13. account_id: null,
  14. status_ids: Immutable.Set(),
  15. comment: ''
  16. })
  17. });
  18. export default function reports(state = initialState, action) {
  19. switch(action.type) {
  20. case REPORT_INIT:
  21. return state.withMutations(map => {
  22. map.setIn(['new', 'isSubmitting'], false);
  23. map.setIn(['new', 'account_id'], action.account.get('id'));
  24. if (state.getIn(['new', 'account_id']) !== action.account.get('id')) {
  25. map.setIn(['new', 'status_ids'], action.status ? Immutable.Set([action.status.get('id')]) : Immutable.Set());
  26. map.setIn(['new', 'comment'], '');
  27. } else {
  28. map.updateIn(['new', 'status_ids'], Immutable.Set(), set => set.add(action.status.get('id')));
  29. }
  30. });
  31. case REPORT_STATUS_TOGGLE:
  32. return state.updateIn(['new', 'status_ids'], Immutable.Set(), set => {
  33. if (action.checked) {
  34. return set.add(action.statusId);
  35. }
  36. return set.remove(action.statusId);
  37. });
  38. case REPORT_SUBMIT_REQUEST:
  39. return state.setIn(['new', 'isSubmitting'], true);
  40. case REPORT_SUBMIT_FAIL:
  41. return state.setIn(['new', 'isSubmitting'], false);
  42. case REPORT_CANCEL:
  43. case REPORT_SUBMIT_SUCCESS:
  44. return state.withMutations(map => {
  45. map.setIn(['new', 'account_id'], null);
  46. map.setIn(['new', 'status_ids'], Immutable.Set());
  47. map.setIn(['new', 'comment'], '');
  48. map.setIn(['new', 'isSubmitting'], false);
  49. });
  50. default:
  51. return state;
  52. }
  53. };