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.

83 lines
2.0 KiB

7 years ago
  1. import api from '../api'
  2. export const REBLOG = 'REBLOG';
  3. export const REBLOG_REQUEST = 'REBLOG_REQUEST';
  4. export const REBLOG_SUCCESS = 'REBLOG_SUCCESS';
  5. export const REBLOG_FAIL = 'REBLOG_FAIL';
  6. export const FAVOURITE = 'FAVOURITE';
  7. export const FAVOURITE_REQUEST = 'FAVOURITE_REQUEST';
  8. export const FAVOURITE_SUCCESS = 'FAVOURITE_SUCCESS';
  9. export const FAVOURITE_FAIL = 'FAVOURITE_FAIL';
  10. export function reblog(status) {
  11. return function (dispatch, getState) {
  12. dispatch(reblogRequest(status));
  13. api(getState).post(`/api/statuses/${status.get('id')}/reblog`).then(function (response) {
  14. // The reblog API method returns a new status wrapped around the original. In this case we are only
  15. // interested in how the original is modified, hence passing it skipping the wrapper
  16. dispatch(reblogSuccess(status, response.data.reblog));
  17. }).catch(function (error) {
  18. dispatch(reblogFail(status, error));
  19. });
  20. };
  21. }
  22. export function reblogRequest(status) {
  23. return {
  24. type: REBLOG_REQUEST,
  25. status: status
  26. };
  27. }
  28. export function reblogSuccess(status, response) {
  29. return {
  30. type: REBLOG_SUCCESS,
  31. status: status,
  32. response: response
  33. };
  34. }
  35. export function reblogFail(status, error) {
  36. return {
  37. type: REBLOG_FAIL,
  38. status: status,
  39. error: error
  40. };
  41. }
  42. export function favourite(status) {
  43. return function (dispatch, getState) {
  44. dispatch(favouriteRequest(status));
  45. api(getState).post(`/api/statuses/${status.get('id')}/favourite`).then(function (response) {
  46. dispatch(favouriteSuccess(status, response.data));
  47. }).catch(function (error) {
  48. dispatch(favouriteFail(status, error));
  49. });
  50. };
  51. }
  52. export function favouriteRequest(status) {
  53. return {
  54. type: FAVOURITE_REQUEST,
  55. status: status
  56. };
  57. }
  58. export function favouriteSuccess(status, response) {
  59. return {
  60. type: FAVOURITE_SUCCESS,
  61. status: status,
  62. response: response
  63. };
  64. }
  65. export function favouriteFail(status, error) {
  66. return {
  67. type: FAVOURITE_FAIL,
  68. status: status,
  69. error: error
  70. };
  71. }