about summary refs log tree commit diff
path: root/app/assets/javascripts/components/actions/follow.jsx
blob: a09aded8375eb13a72d3f5ff1f2f981416b726eb (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import api from '../api'

export const FOLLOW_CHANGE         = 'FOLLOW_CHANGE';
export const FOLLOW_SUBMIT         = 'FOLLOW_SUBMIT';
export const FOLLOW_SUBMIT_REQUEST = 'FOLLOW_SUBMIT_REQUEST';
export const FOLLOW_SUBMIT_SUCCESS = 'FOLLOW_SUBMIT_SUCCESS';
export const FOLLOW_SUBMIT_FAIL    = 'FOLLOW_SUBMIT_FAIL';

export function changeFollow(text) {
  return {
    type: FOLLOW_CHANGE,
    text: text
  };
}

export function submitFollow() {
  return function (dispatch, getState) {
    dispatch(submitFollowRequest());

    api(getState).post('/api/follows', {
      uri: getState().getIn(['follow', 'text'])
    }).then(function (response) {
      dispatch(submitFollowSuccess(response.data));
    }).catch(function (error) {
      dispatch(submitFollowFail(error));
    });
  };
}

export function submitFollowRequest() {
  return {
    type: FOLLOW_SUBMIT_REQUEST
  };
}

export function submitFollowSuccess(account) {
  return {
    type: FOLLOW_SUBMIT_SUCCESS,
    account: account
  };
}

export function submitFollowFail(error) {
  return {
    type: FOLLOW_SUBMIT_FAIL,
    error: error
  };
}