gab-social/app/javascript/gabsocial/reducers/group_lists.js

24 lines
658 B
JavaScript
Raw Normal View History

2020-05-04 19:44:37 +01:00
import { Map as ImmutableMap, List as ImmutableList } from 'immutable'
import { GROUPS_FETCH_SUCCESS } from '../actions/groups'
2019-07-15 14:47:05 +01:00
const initialState = ImmutableMap({
2020-04-29 23:32:49 +01:00
new: ImmutableList(),
2019-07-15 14:47:05 +01:00
featured: ImmutableList(),
member: ImmutableList(),
admin: ImmutableList(),
2020-05-04 19:44:37 +01:00
})
2019-07-15 14:47:05 +01:00
const normalizeList = (state, type, id, groups) => {
2020-05-04 19:44:37 +01:00
return state.set(type, ImmutableList(groups.map(item => item.id)))
}
2019-07-15 14:47:05 +01:00
export default function groupLists(state = initialState, action) {
switch(action.type) {
case GROUPS_FETCH_SUCCESS:
2020-05-04 19:44:37 +01:00
if (!action.tab) return state
return normalizeList(state, action.tab, action.id, action.groups)
2019-07-15 14:47:05 +01:00
default:
2020-05-04 19:44:37 +01:00
return state
2019-07-15 14:47:05 +01:00
}
2020-05-04 19:44:37 +01:00
}