Updated group_lists reducer booleans

• Updated:
- group_lists reducer booleans to be isLoading, isFetched
This commit is contained in:
mgabdev 2020-06-04 18:52:26 -04:00
parent ed9433c303
commit 9c67882cf1
2 changed files with 15 additions and 15 deletions

View File

@ -136,8 +136,8 @@ export const fetchGroups = (tab) => (dispatch, getState) => {
if (!me) return if (!me) return
// Don't refetch or fetch when loading // Don't refetch or fetch when loading
const isLoading = getState().getIn(['group_lists', tab, 'loading']) const isLoading = getState().getIn(['group_lists', tab, 'isLoading'])
const isFetched = getState().getIn(['group_lists', tab, 'fetched']) const isFetched = getState().getIn(['group_lists', tab, 'isFetched'])
if (isLoading || isFetched) return if (isLoading || isFetched) return

View File

@ -9,23 +9,23 @@ const tabs = ['new', 'featured', 'member', 'admin']
const initialState = ImmutableMap({ const initialState = ImmutableMap({
new: ImmutableMap({ new: ImmutableMap({
fetched: false, isFetched: false,
loading: false, isLoading: false,
items: ImmutableList(), items: ImmutableList(),
}), }),
featured: ImmutableMap({ featured: ImmutableMap({
fetched: false, isFetched: false,
loading: false, isLoading: false,
items: ImmutableList(), items: ImmutableList(),
}), }),
member: ImmutableMap({ member: ImmutableMap({
fetched: false, isFetched: false,
loading: false, isLoading: false,
items: ImmutableList(), items: ImmutableList(),
}), }),
admin: ImmutableMap({ admin: ImmutableMap({
fetched: false, isFetched: false,
loading: false, isLoading: false,
items: ImmutableList(), items: ImmutableList(),
}), }),
}) })
@ -36,19 +36,19 @@ export default function groupLists(state = initialState, action) {
switch(action.type) { switch(action.type) {
case GROUPS_FETCH_REQUEST: case GROUPS_FETCH_REQUEST:
return state.withMutations((mutable) => { return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'loading'], true) mutable.setIn([action.tab, 'isLoading'], true)
}); });
case GROUPS_FETCH_SUCCESS: case GROUPS_FETCH_SUCCESS:
return state.withMutations((mutable) => { return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'items'], ImmutableList(action.groups.map(item => item.id))) mutable.setIn([action.tab, 'items'], ImmutableList(action.groups.map(item => item.id)))
mutable.setIn([action.tab, 'loading'], false) mutable.setIn([action.tab, 'isLoading'], false)
mutable.setIn([action.tab, 'fetched'], true) mutable.setIn([action.tab, 'isFetched'], true)
}) })
case GROUPS_FETCH_FAIL: case GROUPS_FETCH_FAIL:
return state.withMutations((mutable) => { return state.withMutations((mutable) => {
mutable.setIn([action.tab, 'items'], ImmutableList()) mutable.setIn([action.tab, 'items'], ImmutableList())
mutable.setIn([action.tab, 'loading'], false) mutable.setIn([action.tab, 'isLoading'], false)
mutable.setIn([action.tab, 'fetched'], true) mutable.setIn([action.tab, 'isFetched'], true)
}) })
default: default:
return state return state