2019-12-05 22:37:09 +01:00
|
|
|
import { FETCH_ISSUES_SUCCESS, CREATE_ISSUE_SUCCESS } from "../actions/issues";
|
2019-11-28 14:12:48 +01:00
|
|
|
|
2019-12-01 22:12:13 +01:00
|
|
|
const defaultState = {
|
|
|
|
byProject: {}
|
|
|
|
};
|
2019-11-28 14:12:48 +01:00
|
|
|
|
2020-04-30 13:02:56 +02:00
|
|
|
export function issuesReducer(state = defaultState, action: any) {
|
2019-12-01 22:12:13 +01:00
|
|
|
switch(action.type) {
|
|
|
|
case FETCH_ISSUES_SUCCESS:
|
|
|
|
return handleFetchIssuesSuccess(state, action);
|
2019-12-05 22:37:09 +01:00
|
|
|
case CREATE_ISSUE_SUCCESS:
|
|
|
|
return handleCreateIssueSuccess(state, action);
|
2019-12-01 22:12:13 +01:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-30 13:02:56 +02:00
|
|
|
function handleFetchIssuesSuccess(state: any, action: any) {
|
2019-12-01 22:12:13 +01:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
byProject: {
|
|
|
|
...state.byProject,
|
|
|
|
[action.project]: [
|
|
|
|
...action.issues,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 22:37:09 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 13:02:56 +02:00
|
|
|
function handleCreateIssueSuccess(state: any, action: any) {
|
2019-12-05 22:37:09 +01:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
byProject: {
|
|
|
|
...state.byProject,
|
|
|
|
[action.project]: [
|
|
|
|
...state.byProject[action.project],
|
|
|
|
action.issue
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2019-11-28 14:12:48 +01:00
|
|
|
}
|