2020-04-04 00:18:26 +01:00
|
|
|
import api from '../api';
|
|
|
|
import { me } from '../initial_state'
|
|
|
|
|
|
|
|
export const GAB_TRENDS_RESULTS_FETCH_REQUEST = 'GAB_TRENDS_RESULTS_FETCH_REQUEST'
|
|
|
|
export const GAB_TRENDS_RESULTS_FETCH_SUCCESS = 'GAB_TRENDS_RESULTS_FETCH_SUCCESS'
|
|
|
|
export const GAB_TRENDS_RESULTS_FETCH_FAIL = 'GAB_TRENDS_RESULTS_FETCH_FAIL'
|
|
|
|
|
2020-06-09 03:10:51 +01:00
|
|
|
export const fetchGabTrends = (feedType) => {
|
2020-04-04 00:18:26 +01:00
|
|
|
return function (dispatch, getState) {
|
2020-06-09 03:10:51 +01:00
|
|
|
dispatch(fetchGabTrendsRequest(feedType))
|
2020-04-04 00:18:26 +01:00
|
|
|
|
2020-06-09 03:10:51 +01:00
|
|
|
api(getState).get(`/api/v1/gab_trends?type=${feedType}`).then(response => {
|
|
|
|
dispatch(fetchGabTrendsSuccess(response.data.items, feedType))
|
2020-04-04 00:18:26 +01:00
|
|
|
}).catch(function (error) {
|
2020-06-09 03:10:51 +01:00
|
|
|
dispatch(fetchGabTrendsFail(error, feedType))
|
2020-04-04 00:18:26 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:10:51 +01:00
|
|
|
function fetchGabTrendsRequest(feedType) {
|
2020-04-04 00:18:26 +01:00
|
|
|
return {
|
|
|
|
type: GAB_TRENDS_RESULTS_FETCH_REQUEST,
|
2020-06-09 03:10:51 +01:00
|
|
|
feedType,
|
2020-04-04 00:18:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:10:51 +01:00
|
|
|
function fetchGabTrendsSuccess(items, feedType) {
|
2020-04-04 00:18:26 +01:00
|
|
|
return {
|
|
|
|
type: GAB_TRENDS_RESULTS_FETCH_SUCCESS,
|
|
|
|
items,
|
2020-06-09 03:10:51 +01:00
|
|
|
feedType,
|
2020-04-04 00:18:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 03:10:51 +01:00
|
|
|
function fetchGabTrendsFail(error, feedType) {
|
2020-04-04 00:18:26 +01:00
|
|
|
return {
|
|
|
|
type: GAB_TRENDS_RESULTS_FETCH_FAIL,
|
|
|
|
error,
|
2020-06-09 03:10:51 +01:00
|
|
|
feedType,
|
2020-04-04 00:18:26 +01:00
|
|
|
}
|
|
|
|
}
|