gab-social/app/javascript/gabsocial/actions/gab_trends.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

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'
export const fetchGabTrends = (feedType) => {
2020-04-04 00:18:26 +01:00
return function (dispatch, getState) {
dispatch(fetchGabTrendsRequest(feedType))
2020-04-04 00:18:26 +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) {
dispatch(fetchGabTrendsFail(error, feedType))
2020-04-04 00:18:26 +01:00
})
}
}
function fetchGabTrendsRequest(feedType) {
2020-04-04 00:18:26 +01:00
return {
type: GAB_TRENDS_RESULTS_FETCH_REQUEST,
feedType,
2020-04-04 00:18:26 +01:00
}
}
function fetchGabTrendsSuccess(items, feedType) {
2020-04-04 00:18:26 +01:00
return {
type: GAB_TRENDS_RESULTS_FETCH_SUCCESS,
items,
feedType,
2020-04-04 00:18:26 +01:00
}
}
function fetchGabTrendsFail(error, feedType) {
2020-04-04 00:18:26 +01:00
return {
type: GAB_TRENDS_RESULTS_FETCH_FAIL,
error,
feedType,
2020-04-04 00:18:26 +01:00
}
}