42 lines
869 B
TypeScript
42 lines
869 B
TypeScript
import { FETCH_ISSUES_SUCCESS, CREATE_ISSUE_SUCCESS } from "../actions/issues";
|
|
|
|
const defaultState = {
|
|
byProject: {}
|
|
};
|
|
|
|
export function issuesReducer(state = defaultState, action: any) {
|
|
switch(action.type) {
|
|
case FETCH_ISSUES_SUCCESS:
|
|
return handleFetchIssuesSuccess(state, action);
|
|
case CREATE_ISSUE_SUCCESS:
|
|
return handleCreateIssueSuccess(state, action);
|
|
default:
|
|
return state;
|
|
}
|
|
|
|
}
|
|
|
|
function handleFetchIssuesSuccess(state: any, action: any) {
|
|
return {
|
|
...state,
|
|
byProject: {
|
|
...state.byProject,
|
|
[action.project]: [
|
|
...action.issues,
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleCreateIssueSuccess(state: any, action: any) {
|
|
return {
|
|
...state,
|
|
byProject: {
|
|
...state.byProject,
|
|
[action.project]: [
|
|
...state.byProject[action.project],
|
|
action.issue
|
|
]
|
|
}
|
|
}
|
|
} |