about summary refs log tree commit diff
path: root/app/assets/javascripts/components/reducers/follow.jsx
blob: ed6e8e0efc82980926e87336ab9b625c613419ee (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
26
27
28
29
import {
  FOLLOW_CHANGE,
  FOLLOW_SUBMIT_REQUEST,
  FOLLOW_SUBMIT_SUCCESS,
  FOLLOW_SUBMIT_FAIL
} from '../actions/follow';
import Immutable from 'immutable';

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

export default function follow(state = initialState, action) {
  switch(action.type) {
    case FOLLOW_CHANGE:
      return state.set('text', action.text);
    case FOLLOW_SUBMIT_REQUEST:
      return state.set('is_submitting', true);
    case FOLLOW_SUBMIT_SUCCESS:
      return state.withMutations(map => {
        map.set('text', '').set('is_submitting', false);
      });
    case FOLLOW_SUBMIT_FAIL:
      return state.set('is_submitting', false);
    default:
      return state;
  }
};