闭社主体 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.

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