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.

48 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. dispatch(submitFollowFail(error));
  22. });
  23. };
  24. };
  25. export function submitFollowRequest() {
  26. return {
  27. type: FOLLOW_SUBMIT_REQUEST
  28. };
  29. };
  30. export function submitFollowSuccess(account) {
  31. return {
  32. type: FOLLOW_SUBMIT_SUCCESS,
  33. account: account
  34. };
  35. };
  36. export function submitFollowFail(error) {
  37. return {
  38. type: FOLLOW_SUBMIT_FAIL,
  39. error: error
  40. };
  41. };