diff --git a/app/javascript/gabsocial/actions/gab_trends.js b/app/javascript/gabsocial/actions/gab.js similarity index 55% rename from app/javascript/gabsocial/actions/gab_trends.js rename to app/javascript/gabsocial/actions/gab.js index 93214ace..502aef3d 100644 --- a/app/javascript/gabsocial/actions/gab_trends.js +++ b/app/javascript/gabsocial/actions/gab.js @@ -1,9 +1,14 @@ +import api from '../api' import axios from 'axios' 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) => { return function (dispatch, getState) { dispatch(fetchGabTrendsRequest(feedType)) @@ -39,4 +44,36 @@ function fetchGabTrendsFail(error, feedType) { error, feedType, } +} + +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, + } } \ No newline at end of file diff --git a/app/javascript/gabsocial/components/panel/trends_panel.js b/app/javascript/gabsocial/components/panel/trends_panel.js index 4088a66f..a786a581 100644 --- a/app/javascript/gabsocial/components/panel/trends_panel.js +++ b/app/javascript/gabsocial/components/panel/trends_panel.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux' import { injectIntl, defineMessages } from 'react-intl' import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePropTypes from 'react-immutable-proptypes' -import { fetchGabTrends } from '../../actions/gab_trends' +import { fetchGabTrends } from '../../actions/gab' import PanelLayout from './panel_layout' import ScrollableList from '../scrollable_list' import TrendsItem from '../trends_item' @@ -97,9 +97,9 @@ const messages = defineMessages({ }) const mapStateToProps = (state) => ({ - isError: state.getIn(['gab_trends', 'feed', 'isError']), - isLoading: state.getIn(['gab_trends', 'feed', 'isLoading']), - items: state.getIn(['gab_trends', 'feed', 'items']), + isError: state.getIn(['gab', 'feed', 'isError']), + isLoading: state.getIn(['gab', 'feed', 'isLoading']), + items: state.getIn(['gab', 'feed', 'items']), }) const mapDispatchToProps = (dispatch) => ({ diff --git a/app/javascript/gabsocial/reducers/gab_trends.js b/app/javascript/gabsocial/reducers/gab.js similarity index 73% rename from app/javascript/gabsocial/reducers/gab_trends.js rename to app/javascript/gabsocial/reducers/gab.js index 58275d27..77e08128 100644 --- a/app/javascript/gabsocial/reducers/gab_trends.js +++ b/app/javascript/gabsocial/reducers/gab.js @@ -1,8 +1,11 @@ import { GAB_TRENDS_RESULTS_FETCH_REQUEST, GAB_TRENDS_RESULTS_FETCH_SUCCESS, - GAB_TRENDS_RESULTS_FETCH_FAIL -} from '../actions/gab_trends' + GAB_TRENDS_RESULTS_FETCH_FAIL, + GAB_NEWS_RESULTS_FETCH_REQUEST, + GAB_NEWS_RESULTS_FETCH_SUCCESS, + GAB_NEWS_RESULTS_FETCH_FAIL, +} from '../actions/gab' import { Map as ImmutableMap, List as ImmutableList, @@ -20,6 +23,11 @@ const initialState = ImmutableMap({ isLoading: false, isError: false, }), + news: ImmutableMap({ + items: {}, + isLoading: false, + isError: false, + }), }) const normalizeList = (state, type, items) => { @@ -56,6 +64,12 @@ export default function (state = initialState, action) { return state case GAB_TRENDS_RESULTS_FETCH_FAIL: return setListFailed(state, action.feedType) + case GAB_NEWS_RESULTS_FETCH_REQUEST: + return state.setIn(['news', 'isLoading'], true); + case GAB_NEWS_RESULTS_FETCH_SUCCESS: + return normalizeList(state, 'news', action.items) + case GAB_NEWS_RESULTS_FETCH_FAIL: + return setListFailed(state, 'news') default: return state } diff --git a/app/javascript/gabsocial/reducers/index.js b/app/javascript/gabsocial/reducers/index.js index 3b91a2ce..d4ff2a00 100644 --- a/app/javascript/gabsocial/reducers/index.js +++ b/app/javascript/gabsocial/reducers/index.js @@ -7,7 +7,7 @@ import contexts from './contexts' import conversations from './conversations' import custom_emojis from './custom_emojis' import filters from './filters' -import gab_trends from './gab_trends' +import gab from './gab' import groups from './groups' import group_categories from './group_categories' import group_editor from './group_editor' @@ -50,7 +50,7 @@ const reducers = { conversations, custom_emojis, filters, - gab_trends, + gab, groups, group_categories, group_editor,