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.

44 lines
1.0 KiB

  1. import api from '../api';
  2. import axios from 'axios';
  3. export const STATUS_FETCH = 'STATUS_FETCH';
  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 function fetchStatusRequest(id) {
  8. return {
  9. type: STATUS_FETCH_REQUEST,
  10. id: id
  11. };
  12. };
  13. export function fetchStatus(id) {
  14. return (dispatch, getState) => {
  15. const boundApi = api(getState);
  16. dispatch(fetchStatusRequest(id));
  17. axios.all([boundApi.get(`/api/statuses/${id}`), boundApi.get(`/api/statuses/${id}/context`)]).then(values => {
  18. dispatch(fetchStatusSuccess(values[0].data, values[1].data));
  19. }).catch(error => {
  20. dispatch(fetchStatusFail(id, error));
  21. });
  22. };
  23. };
  24. export function fetchStatusSuccess(status, context) {
  25. return {
  26. type: STATUS_FETCH_SUCCESS,
  27. status: status,
  28. context: context
  29. };
  30. };
  31. export function fetchStatusFail(id, error) {
  32. return {
  33. type: STATUS_FETCH_FAIL,
  34. id: id,
  35. error: error
  36. };
  37. };