~cytrogen/masto-fe

ref: b2d67fbe339d4852c97cd332a92a2c32b8835cdb masto-fe/app/javascript/flavours/glitch/reducers/account_notes.js -rw-r--r-- 1.3 KiB
b2d67fbe — Renaud Chaput [Glitch] Improve modals reducer types 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Map as ImmutableMap } from 'immutable';

import {
  ACCOUNT_NOTE_INIT_EDIT,
  ACCOUNT_NOTE_CANCEL,
  ACCOUNT_NOTE_CHANGE_COMMENT,
  ACCOUNT_NOTE_SUBMIT_REQUEST,
  ACCOUNT_NOTE_SUBMIT_FAIL,
  ACCOUNT_NOTE_SUBMIT_SUCCESS,
} from '../actions/account_notes';

const initialState = ImmutableMap({
  edit: ImmutableMap({
    isSubmitting: false,
    account_id: null,
    comment: null,
  }),
});

export default function account_notes(state = initialState, action) {
  switch (action.type) {
  case ACCOUNT_NOTE_INIT_EDIT:
    return state.withMutations((state) => {
      state.setIn(['edit', 'isSubmitting'], false);
      state.setIn(['edit', 'account_id'], action.account.get('id'));
      state.setIn(['edit', 'comment'], action.comment);
    });
  case ACCOUNT_NOTE_CHANGE_COMMENT:
    return state.setIn(['edit', 'comment'], action.comment);
  case ACCOUNT_NOTE_SUBMIT_REQUEST:
    return state.setIn(['edit', 'isSubmitting'], true);
  case ACCOUNT_NOTE_SUBMIT_FAIL:
    return state.setIn(['edit', 'isSubmitting'], false);
  case ACCOUNT_NOTE_SUBMIT_SUCCESS:
  case ACCOUNT_NOTE_CANCEL:
    return state.withMutations((state) => {
      state.setIn(['edit', 'isSubmitting'], false);
      state.setIn(['edit', 'account_id'], null);
      state.setIn(['edit', 'comment'], null);
    });
  default:
    return state;
  }
}