about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/compose.jsx
blob: 93e0c7ebefad3fef8751a1e54fb1858f2b164e0d (plain) (blame)
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
import { COMPOSE_CHANGE, COMPOSE_SUBMIT_REQUEST, COMPOSE_SUBMIT_SUCCESS, COMPOSE_SUBMIT_FAIL } from '../actions/compose';
import Immutable                                                                               from 'immutable';

const initialState = Immutable.Map({
  text: '',
  in_reply_to_id: null,
  isSubmitting: false
});

export default function compose(state = initialState, action) {
  switch(action.type) {
    case COMPOSE_CHANGE:
      return state.set('text', action.text);
    case COMPOSE_SUBMIT_REQUEST:
      return state.set('isSubmitting', true);
    case COMPOSE_SUBMIT_SUCCESS:
      return state.withMutations(map => {
        map.set('text', '').set('isSubmitting', false);
      });
    case COMPOSE_SUBMIT_FAIL:
      return state.set('isSubmitting', false);
    default:
      return state;
  }
}