about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/featured_tags.js
blob: 18bb615394571c23599b4f072fa2a842158f547b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import api from '../api';

export const FEATURED_TAGS_FETCH_REQUEST = 'FEATURED_TAGS_FETCH_REQUEST';
export const FEATURED_TAGS_FETCH_SUCCESS = 'FEATURED_TAGS_FETCH_SUCCESS';
export const FEATURED_TAGS_FETCH_FAIL    = 'FEATURED_TAGS_FETCH_FAIL';

export const fetchFeaturedTags = (id) => (dispatch, getState) => {
  if (getState().getIn(['user_lists', 'featured_tags', id, 'items'])) {
    return;
  }

  dispatch(fetchFeaturedTagsRequest(id));

  api(getState).get(`/api/v1/accounts/${id}/featured_tags`)
    .then(({ data }) => dispatch(fetchFeaturedTagsSuccess(id, data)))
    .catch(err => dispatch(fetchFeaturedTagsFail(id, err)));
};

export const fetchFeaturedTagsRequest = (id) => ({
  type: FEATURED_TAGS_FETCH_REQUEST,
  id,
});

export const fetchFeaturedTagsSuccess = (id, tags) => ({
  type: FEATURED_TAGS_FETCH_SUCCESS,
  id,
  tags,
});

export const fetchFeaturedTagsFail = (id, error) => ({
  type: FEATURED_TAGS_FETCH_FAIL,
  id,
  error,
});