You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.7 KiB
93 lines
2.7 KiB
import { Reducer } from 'redux'
|
|
|
|
import { GroupsActions } from '../actions/groups'
|
|
import { GroupsState } from '../types'
|
|
|
|
const initialState: GroupsState = {
|
|
items: [],
|
|
continuation: undefined,
|
|
admin: {
|
|
invitations: {
|
|
items: [],
|
|
continuation: undefined,
|
|
},
|
|
logs: {
|
|
items: [],
|
|
continuation: undefined,
|
|
}
|
|
}
|
|
}
|
|
|
|
const reducer: Reducer<GroupsState, GroupsActions> = (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case 'GROUPS_APPEND_GROUPS':
|
|
return {
|
|
...state,
|
|
items: [
|
|
...state.items,
|
|
...action.payload.items,
|
|
],
|
|
continuation: action.payload.continuation,
|
|
}
|
|
case 'GROUPS_CLEAR_GROUPS':
|
|
return {
|
|
...state,
|
|
items: [],
|
|
continuation: undefined,
|
|
}
|
|
case 'GROUPS_APPEND_LOGS':
|
|
return {
|
|
...state,
|
|
admin: {
|
|
...state.admin,
|
|
logs: {
|
|
items: [
|
|
...state.admin.logs.items,
|
|
...action.payload.items,
|
|
],
|
|
continuation: action.payload.continuation,
|
|
},
|
|
},
|
|
}
|
|
case 'GROUPS_CLEAR_LOGS':
|
|
return {
|
|
...state,
|
|
admin: {
|
|
...state.admin,
|
|
logs: {
|
|
items: [],
|
|
continuation: undefined,
|
|
},
|
|
},
|
|
}
|
|
case 'GROUPS_APPEND_INVITATIONS':
|
|
return {
|
|
...state,
|
|
admin: {
|
|
...state.admin,
|
|
invitations: {
|
|
items: [
|
|
...state.admin.logs.items,
|
|
...action.payload.items,
|
|
],
|
|
continuation: action.payload.continuation,
|
|
},
|
|
},
|
|
}
|
|
case 'GROUPS_CLEAR_INVITATIONS':
|
|
return {
|
|
...state,
|
|
admin: {
|
|
...state.admin,
|
|
invitations: {
|
|
items: [],
|
|
continuation: undefined,
|
|
},
|
|
},
|
|
}
|
|
default:
|
|
return state
|
|
}
|
|
}
|
|
|
|
export default reducer
|