about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/actions/trends.js
blob: 1b0ce2b5b16caba7eb6231c358bc5292ff62b3d1 (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
import api from 'flavours/glitch/util/api';

export const TRENDS_FETCH_REQUEST = 'TRENDS_FETCH_REQUEST';
export const TRENDS_FETCH_SUCCESS = 'TRENDS_FETCH_SUCCESS';
export const TRENDS_FETCH_FAIL    = 'TRENDS_FETCH_FAIL';

export const fetchTrends = () => (dispatch, getState) => {
  dispatch(fetchTrendsRequest());

  api(getState)
    .get('/api/v1/trends')
    .then(({ data }) => dispatch(fetchTrendsSuccess(data)))
    .catch(err => dispatch(fetchTrendsFail(err)));
};

export const fetchTrendsRequest = () => ({
  type: TRENDS_FETCH_REQUEST,
  skipLoading: true,
});

export const fetchTrendsSuccess = trends => ({
  type: TRENDS_FETCH_SUCCESS,
  trends,
  skipLoading: true,
});

export const fetchTrendsFail = error => ({
  type: TRENDS_FETCH_FAIL,
  error,
  skipLoading: true,
  skipAlert: true,
});