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.2 KiB

  1. import api from '../api'
  2. export const COMPOSE_CHANGE = 'COMPOSE_CHANGE';
  3. export const COMPOSE_SUBMIT = 'COMPOSE_SUBMIT';
  4. export const COMPOSE_SUBMIT_REQUEST = 'COMPOSE_SUBMIT_REQUEST';
  5. export const COMPOSE_SUBMIT_SUCCESS = 'COMPOSE_SUBMIT_SUCCESS';
  6. export const COMPOSE_SUBMIT_FAIL = 'COMPOSE_SUBMIT_FAIL';
  7. export function changeCompose(text) {
  8. return {
  9. type: COMPOSE_CHANGE,
  10. text: text
  11. };
  12. }
  13. export function submitCompose() {
  14. return function (dispatch, getState) {
  15. dispatch(submitComposeRequest());
  16. api(getState).post('/api/statuses', {
  17. status: getState().getIn(['compose', 'text'], ''),
  18. in_reply_to_id: getState().getIn(['compose', 'in_reply_to_id'], null)
  19. }).then(function (response) {
  20. dispatch(submitComposeSuccess(response.data));
  21. }).catch(function (error) {
  22. dispatch(submitComposeFail(error));
  23. });
  24. };
  25. }
  26. export function submitComposeRequest() {
  27. return {
  28. type: COMPOSE_SUBMIT_REQUEST
  29. };
  30. }
  31. export function submitComposeSuccess(response) {
  32. return {
  33. type: COMPOSE_SUBMIT_SUCCESS
  34. };
  35. }
  36. export function submitComposeFail(error) {
  37. return {
  38. type: COMPOSE_SUBMIT_FAIL,
  39. error: error
  40. };
  41. }