1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-30 15:58:28 +09:00
YuruToot/app/assets/javascripts/components/actions/follow.jsx

49 lines
1.1 KiB
React
Raw Normal View History

2016-09-01 22:13:02 +09:00
import api from '../api'
export const FOLLOW_CHANGE = 'FOLLOW_CHANGE';
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) {
2016-09-01 22:13:02 +09:00
return {
type: FOLLOW_CHANGE,
text: text
};
};
2016-09-01 22:13:02 +09:00
export function submitFollow(router) {
2016-09-01 22:13:02 +09:00
return function (dispatch, getState) {
dispatch(submitFollowRequest());
2016-09-01 22:13:02 +09:00
2016-09-27 23:58:23 +09:00
api(getState).post('/api/v1/follows', {
2016-09-01 22:13:02 +09:00
uri: getState().getIn(['follow', 'text'])
}).then(function (response) {
dispatch(submitFollowSuccess(response.data));
router.push(`/accounts/${response.data.id}`);
2016-09-01 22:13:02 +09:00
}).catch(function (error) {
dispatch(submitFollowFail(error));
2016-09-01 22:13:02 +09:00
});
};
};
2016-09-01 22:13:02 +09:00
export function submitFollowRequest() {
2016-09-01 22:13:02 +09:00
return {
type: FOLLOW_SUBMIT_REQUEST
};
};
2016-09-01 22:13:02 +09:00
export function submitFollowSuccess(account) {
2016-09-01 22:13:02 +09:00
return {
type: FOLLOW_SUBMIT_SUCCESS,
account: account
};
};
2016-09-01 22:13:02 +09:00
export function submitFollowFail(error) {
2016-09-01 22:13:02 +09:00
return {
type: FOLLOW_SUBMIT_FAIL,
error: error
};
};