Updated redux gab_trends -> gab for our services

• Updated:
- redux gab_trends -> gab for our services
- TrendsPanel to use updated route
This commit is contained in:
mgabdev 2020-09-10 17:21:39 -05:00
parent 793f46253c
commit fb8c705ebf
4 changed files with 59 additions and 8 deletions

View File

@ -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,
}
}

View File

@ -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) => ({

View File

@ -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
}

View File

@ -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,