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.

99 lines
2.4 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. dispatch(refreshTimelineFail(timeline, error));
  43. });
  44. };
  45. };
  46. export function refreshTimelineFail(timeline, error) {
  47. return {
  48. type: TIMELINE_REFRESH_FAIL,
  49. timeline: timeline,
  50. error: error
  51. };
  52. };
  53. export function expandTimeline(timeline) {
  54. return (dispatch, getState) => {
  55. const lastId = getState().getIn(['timelines', timeline]).last();
  56. dispatch(expandTimelineRequest(timeline));
  57. api(getState).get(`/api/v1/statuses/${timeline}?max_id=${lastId}`).then(response => {
  58. dispatch(expandTimelineSuccess(timeline, response.data));
  59. }).catch(error => {
  60. dispatch(expandTimelineFail(timeline, error));
  61. });
  62. };
  63. };
  64. export function expandTimelineRequest(timeline) {
  65. return {
  66. type: TIMELINE_EXPAND_REQUEST,
  67. timeline: timeline
  68. };
  69. };
  70. export function expandTimelineSuccess(timeline, statuses) {
  71. return {
  72. type: TIMELINE_EXPAND_SUCCESS,
  73. timeline: timeline,
  74. statuses: statuses
  75. };
  76. };
  77. export function expandTimelineFail(timeline, error) {
  78. return {
  79. type: TIMELINE_EXPAND_FAIL,
  80. timeline: timeline,
  81. error: error
  82. };
  83. };