logo

mastofe

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

reports.js (2109B)


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