Rev 1120 | Rev 1126 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import { TOPIC_ACTIONS } from './topics.types'
const initialState = {
topicsAllIds: [],
topicById: {},
capsulesAllIds: [],
capsuleById: {}
}
const topicsReducer = (state = initialState, { type, payload }) => {
switch (type) {
case TOPIC_ACTIONS.ADD_TOPIC: {
const { uuid, ...topic } = payload
return {
...state,
topicById: {
...state.topicById,
[uuid]: { ...topic, uuid }
},
topicsAllIds: [...state.topicsAllIds, uuid]
}
}
case TOPIC_ACTIONS.ADD_CAPSULE: {
const { topicId, capsule } = payload
return {
...state,
capsuleById: {
...state.capsuleById,
[capsule.uuid]: { ...capsule, topicId }
},
capsulesAllIds: [...state.capsulesAllIds, capsule.uuid]
}
}
default:
return state
}
}
export default topicsReducer