gab-social/app/javascript/gabsocial/reducers/group_lists.js
mgabdev 9c67882cf1 Updated group_lists reducer booleans
• Updated:
- group_lists reducer booleans to be isLoading, isFetched
2020-06-04 18:52:26 -04:00

57 lines
1.5 KiB
JavaScript

import { Map as ImmutableMap, List as ImmutableList } from 'immutable'
import {
GROUPS_FETCH_REQUEST,
GROUPS_FETCH_SUCCESS,
GROUPS_FETCH_FAIL,
} from '../actions/groups'
const tabs = ['new', 'featured', 'member', 'admin']
const initialState = ImmutableMap({
new: ImmutableMap({
isFetched: false,
isLoading: false,
items: ImmutableList(),
}),
featured: ImmutableMap({
isFetched: false,
isLoading: false,
items: ImmutableList(),
}),
member: ImmutableMap({
isFetched: false,
isLoading: false,
items: ImmutableList(),
}),
admin: ImmutableMap({
isFetched: false,
isLoading: false,
items: ImmutableList(),
}),
})
export default function groupLists(state = initialState, action) {
if (tabs.indexOf(action.tab) === -1) return state
switch(action.type) {
case GROUPS_FETCH_REQUEST:
return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'isLoading'], true)
});
case GROUPS_FETCH_SUCCESS:
return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'items'], ImmutableList(action.groups.map(item => item.id)))
mutable.setIn([action.tab, 'isLoading'], false)
mutable.setIn([action.tab, 'isFetched'], true)
})
case GROUPS_FETCH_FAIL:
return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'items'], ImmutableList())
mutable.setIn([action.tab, 'isLoading'], false)
mutable.setIn([action.tab, 'isFetched'], true)
})
default:
return state
}
}