featured_tags.js 961 B

12345678910111213141516171819202122232425262728293031323334
  1. import api from '../api';
  2. export const FEATURED_TAGS_FETCH_REQUEST = 'FEATURED_TAGS_FETCH_REQUEST';
  3. export const FEATURED_TAGS_FETCH_SUCCESS = 'FEATURED_TAGS_FETCH_SUCCESS';
  4. export const FEATURED_TAGS_FETCH_FAIL = 'FEATURED_TAGS_FETCH_FAIL';
  5. export const fetchFeaturedTags = (id) => (dispatch, getState) => {
  6. if (getState().getIn(['user_lists', 'featured_tags', id, 'items'])) {
  7. return;
  8. }
  9. dispatch(fetchFeaturedTagsRequest(id));
  10. api(getState).get(`/api/v1/accounts/${id}/featured_tags`)
  11. .then(({ data }) => dispatch(fetchFeaturedTagsSuccess(id, data)))
  12. .catch(err => dispatch(fetchFeaturedTagsFail(id, err)));
  13. };
  14. export const fetchFeaturedTagsRequest = (id) => ({
  15. type: FEATURED_TAGS_FETCH_REQUEST,
  16. id,
  17. });
  18. export const fetchFeaturedTagsSuccess = (id, tags) => ({
  19. type: FEATURED_TAGS_FETCH_SUCCESS,
  20. id,
  21. tags,
  22. });
  23. export const fetchFeaturedTagsFail = (id, error) => ({
  24. type: FEATURED_TAGS_FETCH_FAIL,
  25. id,
  26. error,
  27. });