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.

123 lines
2.7 KiB

  1. import api from '../api';
  2. import { deleteFromTimelines } from './timelines';
  3. export const STATUS_FETCH_REQUEST = 'STATUS_FETCH_REQUEST';
  4. export const STATUS_FETCH_SUCCESS = 'STATUS_FETCH_SUCCESS';
  5. export const STATUS_FETCH_FAIL = 'STATUS_FETCH_FAIL';
  6. export const STATUS_DELETE_REQUEST = 'STATUS_DELETE_REQUEST';
  7. export const STATUS_DELETE_SUCCESS = 'STATUS_DELETE_SUCCESS';
  8. export const STATUS_DELETE_FAIL = 'STATUS_DELETE_FAIL';
  9. export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST';
  10. export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS';
  11. export const CONTEXT_FETCH_FAIL = 'CONTEXT_FETCH_FAIL';
  12. export function fetchStatusRequest(id) {
  13. return {
  14. type: STATUS_FETCH_REQUEST,
  15. id: id
  16. };
  17. };
  18. export function fetchStatus(id) {
  19. return (dispatch, getState) => {
  20. dispatch(fetchStatusRequest(id));
  21. api(getState).get(`/api/v1/statuses/${id}`).then(response => {
  22. dispatch(fetchStatusSuccess(response.data));
  23. dispatch(fetchContext(id));
  24. }).catch(error => {
  25. dispatch(fetchStatusFail(id, error));
  26. });
  27. };
  28. };
  29. export function fetchStatusSuccess(status, context) {
  30. return {
  31. type: STATUS_FETCH_SUCCESS,
  32. status: status,
  33. context: context
  34. };
  35. };
  36. export function fetchStatusFail(id, error) {
  37. return {
  38. type: STATUS_FETCH_FAIL,
  39. id: id,
  40. error: error
  41. };
  42. };
  43. export function deleteStatus(id) {
  44. return (dispatch, getState) => {
  45. dispatch(deleteStatusRequest(id));
  46. api(getState).delete(`/api/v1/statuses/${id}`).then(response => {
  47. dispatch(deleteStatusSuccess(id));
  48. dispatch(deleteFromTimelines(id));
  49. }).catch(error => {
  50. dispatch(deleteStatusFail(id, error));
  51. });
  52. };
  53. };
  54. export function deleteStatusRequest(id) {
  55. return {
  56. type: STATUS_DELETE_REQUEST,
  57. id: id
  58. };
  59. };
  60. export function deleteStatusSuccess(id) {
  61. return {
  62. type: STATUS_DELETE_SUCCESS,
  63. id: id
  64. };
  65. };
  66. export function deleteStatusFail(id, error) {
  67. return {
  68. type: STATUS_DELETE_FAIL,
  69. id: id,
  70. error: error
  71. };
  72. };
  73. export function fetchContext(id) {
  74. return (dispatch, getState) => {
  75. dispatch(fetchContextRequest(id));
  76. api(getState).get(`/api/v1/statuses/${id}/context`).then(response => {
  77. dispatch(fetchContextSuccess(id, response.data.ancestors, response.data.descendants));
  78. }).catch(error => {
  79. dispatch(fetchContextFail(id, error));
  80. });
  81. };
  82. };
  83. export function fetchContextRequest(id) {
  84. return {
  85. type: CONTEXT_FETCH_REQUEST,
  86. id
  87. };
  88. };
  89. export function fetchContextSuccess(id, ancestors, descendants) {
  90. return {
  91. type: CONTEXT_FETCH_SUCCESS,
  92. id,
  93. ancestors,
  94. descendants,
  95. statuses: ancestors.concat(descendants)
  96. };
  97. };
  98. export function fetchContextFail(id, error) {
  99. return {
  100. type: CONTEXT_FETCH_FAIL,
  101. id,
  102. error
  103. };
  104. };