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.5 KiB

  1. import api from '../api'
  2. export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
  3. export const TIMELINE_DELETE = 'TIMELINE_DELETE';
  4. export const TIMELINE_REFRESH_REQUEST = 'TIMELINE_REFRESH_REQUEST';
  5. export const TIMELINE_REFRESH_SUCCESS = 'TIMELINE_REFRESH_SUCCESS';
  6. export const TIMELINE_REFRESH_FAIL = 'TIMELINE_REFRESH_FAIL';
  7. export const TIMELINE_EXPAND_REQUEST = 'TIMELINE_EXPAND_REQUEST';
  8. export const TIMELINE_EXPAND_SUCCESS = 'TIMELINE_EXPAND_SUCCESS';
  9. export const TIMELINE_EXPAND_FAIL = 'TIMELINE_EXPAND_FAIL';
  10. export function refreshTimelineSuccess(timeline, statuses) {
  11. return {
  12. type: TIMELINE_REFRESH_SUCCESS,
  13. timeline: timeline,
  14. statuses: statuses
  15. };
  16. };
  17. export function updateTimeline(timeline, status) {
  18. return {
  19. type: TIMELINE_UPDATE,
  20. timeline: timeline,
  21. status: status
  22. };
  23. };
  24. export function deleteFromTimelines(id) {
  25. return {
  26. type: TIMELINE_DELETE,
  27. id: id
  28. };
  29. };
  30. export function refreshTimelineRequest(timeline) {
  31. return {
  32. type: TIMELINE_REFRESH_REQUEST,
  33. timeline: timeline
  34. };
  35. };
  36. export function refreshTimeline(timeline) {
  37. return function (dispatch, getState) {
  38. dispatch(refreshTimelineRequest(timeline));
  39. api(getState).get(`/api/v1/statuses/${timeline}`).then(function (response) {
  40. dispatch(refreshTimelineSuccess(timeline, response.data));
  41. }).catch(function (error) {
  42. console.error(error);
  43. dispatch(refreshTimelineFail(timeline, error));
  44. });
  45. };
  46. };
  47. export function refreshTimelineFail(timeline, error) {
  48. return {
  49. type: TIMELINE_REFRESH_FAIL,
  50. timeline: timeline,
  51. error: error
  52. };
  53. };
  54. export function expandTimeline(timeline) {
  55. return (dispatch, getState) => {
  56. const lastId = getState().getIn(['timelines', timeline]).last();
  57. dispatch(expandTimelineRequest(timeline));
  58. api(getState).get(`/api/v1/statuses/${timeline}?max_id=${lastId}`).then(response => {
  59. dispatch(expandTimelineSuccess(timeline, response.data));
  60. }).catch(error => {
  61. console.error(error);
  62. dispatch(expandTimelineFail(timeline, error));
  63. });
  64. };
  65. };
  66. export function expandTimelineRequest(timeline) {
  67. return {
  68. type: TIMELINE_EXPAND_REQUEST,
  69. timeline: timeline
  70. };
  71. };
  72. export function expandTimelineSuccess(timeline, statuses) {
  73. return {
  74. type: TIMELINE_EXPAND_SUCCESS,
  75. timeline: timeline,
  76. statuses: statuses
  77. };
  78. };
  79. export function expandTimelineFail(timeline, error) {
  80. return {
  81. type: TIMELINE_EXPAND_FAIL,
  82. timeline: timeline,
  83. error: error
  84. };
  85. };