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.

65 lines
1.5 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 const COMPOSE_REPLY = 'COMPOSE_REPLY';
  8. export const COMPOSE_REPLY_CANCEL = 'COMPOSE_REPLY_CANCEL';
  9. export function changeCompose(text) {
  10. return {
  11. type: COMPOSE_CHANGE,
  12. text: text
  13. };
  14. }
  15. export function replyCompose(status) {
  16. return {
  17. type: COMPOSE_REPLY,
  18. status: status
  19. };
  20. }
  21. export function cancelReplyCompose() {
  22. return {
  23. type: COMPOSE_REPLY_CANCEL
  24. };
  25. }
  26. export function submitCompose() {
  27. return function (dispatch, getState) {
  28. dispatch(submitComposeRequest());
  29. api(getState).post('/api/statuses', {
  30. status: getState().getIn(['compose', 'text'], ''),
  31. in_reply_to_id: getState().getIn(['compose', 'in_reply_to', 'id'], null)
  32. }).then(function (response) {
  33. dispatch(submitComposeSuccess(response.data));
  34. }).catch(function (error) {
  35. dispatch(submitComposeFail(error));
  36. });
  37. };
  38. }
  39. export function submitComposeRequest() {
  40. return {
  41. type: COMPOSE_SUBMIT_REQUEST
  42. };
  43. }
  44. export function submitComposeSuccess(status) {
  45. return {
  46. type: COMPOSE_SUBMIT_SUCCESS,
  47. status: status
  48. };
  49. }
  50. export function submitComposeFail(error) {
  51. return {
  52. type: COMPOSE_SUBMIT_FAIL,
  53. error: error
  54. };
  55. }