You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. import api from '../api'
  2. export const FOLLOW_CHANGE = 'FOLLOW_CHANGE';
  3. export const FOLLOW_SUBMIT_REQUEST = 'FOLLOW_SUBMIT_REQUEST';
  4. export const FOLLOW_SUBMIT_SUCCESS = 'FOLLOW_SUBMIT_SUCCESS';
  5. export const FOLLOW_SUBMIT_FAIL = 'FOLLOW_SUBMIT_FAIL';
  6. export function changeFollow(text) {
  7. return {
  8. type: FOLLOW_CHANGE,
  9. text: text
  10. };
  11. };
  12. export function submitFollow(router) {
  13. return function (dispatch, getState) {
  14. dispatch(submitFollowRequest());
  15. api(getState).post('/api/v1/follows', {
  16. uri: getState().getIn(['follow', 'text'])
  17. }).then(function (response) {
  18. dispatch(submitFollowSuccess(response.data));
  19. router.push(`/accounts/${response.data.id}`);
  20. }).catch(function (error) {
  21. console.error(error);
  22. dispatch(submitFollowFail(error));
  23. });
  24. };
  25. };
  26. export function submitFollowRequest() {
  27. return {
  28. type: FOLLOW_SUBMIT_REQUEST
  29. };
  30. };
  31. export function submitFollowSuccess(account) {
  32. return {
  33. type: FOLLOW_SUBMIT_SUCCESS,
  34. account: account
  35. };
  36. };
  37. export function submitFollowFail(error) {
  38. return {
  39. type: FOLLOW_SUBMIT_FAIL,
  40. error: error
  41. };
  42. };