Updated Gab Trends api, redux, panel

• Updated:
- Gab Trends api, redux, panel
- GabTrendsController takes in query string for feed type
This commit is contained in:
mgabdev
2020-06-08 22:10:51 -04:00
parent 24ad9b6ff4
commit 4a23c62ec8
4 changed files with 77 additions and 44 deletions

View File

@@ -6,30 +6,41 @@ import {
import {
Map as ImmutableMap,
List as ImmutableList,
fromJS
fromJS,
} from 'immutable'
const initialState = ImmutableMap({
items: ImmutableList(),
loading: false,
error: false,
feed: ImmutableMap({
items: ImmutableList(),
isLoading: false,
isError: false,
}),
})
const normalizeList = (state, type, items) => {
return state.set(type, ImmutableMap({
items: fromJS(items),
isLoading: false,
isError: false,
}))
}
const setListFailed = (state, type) => {
return state.set(type, ImmutableMap({
items: ImmutableList(),
isLoading: false,
isError: true,
}))
}
export default function (state = initialState, action) {
switch (action.type) {
case GAB_TRENDS_RESULTS_FETCH_REQUEST:
return state.set('loading', true)
return state.setIn([action.feedType, 'isLoading'], true);
case GAB_TRENDS_RESULTS_FETCH_SUCCESS:
return state.withMutations(map => {
map.set('items', fromJS(action.items));
map.set('error', false);
map.set('loading', false);
});
return normalizeList(state, action.feedType, action.items)
case GAB_TRENDS_RESULTS_FETCH_FAIL:
return state.withMutations(map => {
map.set('error', !!action.error);
map.set('loading', false);
});
return setListFailed(state, action.feedType)
default:
return state
}