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.

65 lines
1.5 KiB

  1. import api from '../api'
  2. export const TIMELINE_SET = 'TIMELINE_SET';
  3. export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
  4. export const TIMELINE_DELETE = 'TIMELINE_DELETE';
  5. export const TIMELINE_REFRESH_REQUEST = 'TIMELINE_REFRESH_REQUEST';
  6. export const TIMELINE_REFRESH_SUCCESS = 'TIMELINE_REFRESH_SUCCESS';
  7. export const TIMELINE_REFRESH_FAIL = 'TIMELINE_REFRESH_FAIL';
  8. export function setTimeline(timeline, statuses) {
  9. return {
  10. type: TIMELINE_SET,
  11. timeline: timeline,
  12. statuses: statuses
  13. };
  14. }
  15. export function updateTimeline(timeline, status) {
  16. return {
  17. type: TIMELINE_UPDATE,
  18. timeline: timeline,
  19. status: status
  20. };
  21. }
  22. export function deleteFromTimelines(id) {
  23. return {
  24. type: TIMELINE_DELETE,
  25. id: id
  26. };
  27. }
  28. export function refreshTimelineRequest(timeline) {
  29. return {
  30. type: TIMELINE_REFRESH_REQUEST,
  31. timeline: timeline
  32. };
  33. }
  34. export function refreshTimeline(timeline) {
  35. return function (dispatch, getState) {
  36. dispatch(refreshTimelineRequest(timeline));
  37. api(getState).get(`/api/statuses/${timeline}`).then(function (response) {
  38. dispatch(refreshTimelineSuccess(timeline, response.data));
  39. }).catch(function (error) {
  40. dispatch(refreshTimelineFail(timeline, error));
  41. });
  42. };
  43. }
  44. export function refreshTimelineSuccess(timeline, statuses) {
  45. return function (dispatch) {
  46. dispatch(setTimeline(timeline, statuses));
  47. };
  48. }
  49. export function refreshTimelineFail(timeline, error) {
  50. return {
  51. type: TIMELINE_REFRESH_FAIL,
  52. timeline: timeline,
  53. error: error
  54. };
  55. }