The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

130 lines
3.0 KiB

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