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' import axios from 'axios'
export const GAB_TRENDS_RESULTS_FETCH_REQUEST = 'GAB_TRENDS_RESULTS_FETCH_REQUEST' 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_SUCCESS = 'GAB_TRENDS_RESULTS_FETCH_SUCCESS'
export const GAB_TRENDS_RESULTS_FETCH_FAIL = 'GAB_TRENDS_RESULTS_FETCH_FAIL' 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) => { export const fetchGabTrends = (feedType) => {
return function (dispatch, getState) { return function (dispatch, getState) {
dispatch(fetchGabTrendsRequest(feedType)) dispatch(fetchGabTrendsRequest(feedType))
@ -40,3 +45,35 @@ function fetchGabTrendsFail(error, feedType) {
feedType, 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 { injectIntl, defineMessages } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import { fetchGabTrends } from '../../actions/gab_trends' import { fetchGabTrends } from '../../actions/gab'
import PanelLayout from './panel_layout' import PanelLayout from './panel_layout'
import ScrollableList from '../scrollable_list' import ScrollableList from '../scrollable_list'
import TrendsItem from '../trends_item' import TrendsItem from '../trends_item'
@ -97,9 +97,9 @@ const messages = defineMessages({
}) })
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
isError: state.getIn(['gab_trends', 'feed', 'isError']), isError: state.getIn(['gab', 'feed', 'isError']),
isLoading: state.getIn(['gab_trends', 'feed', 'isLoading']), isLoading: state.getIn(['gab', 'feed', 'isLoading']),
items: state.getIn(['gab_trends', 'feed', 'items']), items: state.getIn(['gab', 'feed', 'items']),
}) })
const mapDispatchToProps = (dispatch) => ({ const mapDispatchToProps = (dispatch) => ({

View File

@ -1,8 +1,11 @@
import { import {
GAB_TRENDS_RESULTS_FETCH_REQUEST, GAB_TRENDS_RESULTS_FETCH_REQUEST,
GAB_TRENDS_RESULTS_FETCH_SUCCESS, GAB_TRENDS_RESULTS_FETCH_SUCCESS,
GAB_TRENDS_RESULTS_FETCH_FAIL GAB_TRENDS_RESULTS_FETCH_FAIL,
} from '../actions/gab_trends' GAB_NEWS_RESULTS_FETCH_REQUEST,
GAB_NEWS_RESULTS_FETCH_SUCCESS,
GAB_NEWS_RESULTS_FETCH_FAIL,
} from '../actions/gab'
import { import {
Map as ImmutableMap, Map as ImmutableMap,
List as ImmutableList, List as ImmutableList,
@ -20,6 +23,11 @@ const initialState = ImmutableMap({
isLoading: false, isLoading: false,
isError: false, isError: false,
}), }),
news: ImmutableMap({
items: {},
isLoading: false,
isError: false,
}),
}) })
const normalizeList = (state, type, items) => { const normalizeList = (state, type, items) => {
@ -56,6 +64,12 @@ export default function (state = initialState, action) {
return state return state
case GAB_TRENDS_RESULTS_FETCH_FAIL: case GAB_TRENDS_RESULTS_FETCH_FAIL:
return setListFailed(state, action.feedType) 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: default:
return state return state
} }

View File

@ -7,7 +7,7 @@ import contexts from './contexts'
import conversations from './conversations' import conversations from './conversations'
import custom_emojis from './custom_emojis' import custom_emojis from './custom_emojis'
import filters from './filters' import filters from './filters'
import gab_trends from './gab_trends' import gab from './gab'
import groups from './groups' import groups from './groups'
import group_categories from './group_categories' import group_categories from './group_categories'
import group_editor from './group_editor' import group_editor from './group_editor'
@ -50,7 +50,7 @@ const reducers = {
conversations, conversations,
custom_emojis, custom_emojis,
filters, filters,
gab_trends, gab,
groups, groups,
group_categories, group_categories,
group_editor, group_editor,