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

79 lines
1.9 KiB
JavaScript
Raw Normal View History

import api from '../api'
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 GAB_NEWS_RESULTS_FETCH_REQUEST = 'GAB_NEWS_RESULTS_FETCH_REQUEST'
export const GAB_NEWS_RESULTS_FETCH_SUCCESS = 'GAB_NEWS_RESULTS_FETCH_SUCCESS'
export const GAB_NEWS_RESULTS_FETCH_FAIL = 'GAB_NEWS_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
}
}
export const fetchGabNews = () => {
return function (dispatch) {
dispatch(fetchGabNewsRequest())
axios.get('https://news.gab.com/feed/json').then((response) => {
dispatch(fetchGabNewsSuccess(response.data))
}).catch(function (error) {
dispatch(fetchGabNewsFail(error))
})
}
}
function fetchGabNewsRequest() {
return {
type: GAB_NEWS_RESULTS_FETCH_REQUEST,
}
}
function fetchGabNewsSuccess(items) {
return {
type: GAB_NEWS_RESULTS_FETCH_SUCCESS,
items,
}
}
function fetchGabNewsFail(error) {
return {
type: GAB_NEWS_RESULTS_FETCH_FAIL,
error,
}
2020-04-04 00:18:26 +01:00
}