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.

101 lines
2.4 KiB

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