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

42 lines
1.1 KiB
JavaScript
Raw Normal View History

import axios from 'axios'
2020-04-04 00:18:26 +01:00
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
const url = feedType === 'partner' ? 'https://trends.gab.com/partner' : 'https://trends.gab.com/trend-feed/json'
axios.get(url).then((response) => {
dispatch(fetchGabTrendsSuccess(response.data, 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
}
}