gengitkan/client/src/store/reducers/projects.ts

40 lines
959 B
TypeScript
Raw Normal View History

2021-03-19 18:15:40 +01:00
import { FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_MILESTONES_SUCCESS } from "../actions/projects";
2019-12-01 22:12:13 +01:00
export const defaultState = {
byName: {},
2021-03-20 00:58:20 +01:00
milestones: {}
2019-12-01 22:12:13 +01:00
};
2020-04-30 13:02:56 +02:00
export function projectsReducer(state = defaultState, action: any) {
2021-03-19 18:15:40 +01:00
switch (action.type) {
2019-12-01 22:12:13 +01:00
case FETCH_PROJECTS_SUCCESS:
return handleFetchProjectsSuccess(state, action);
2021-03-19 18:15:40 +01:00
case FETCH_PROJECT_MILESTONES_SUCCESS:
return handleFetchProjectMilestonesSuccess(state, action);
2019-12-01 22:12:13 +01:00
default:
return state;
}
}
2020-04-30 13:02:56 +02:00
function handleFetchProjectsSuccess(state: any, action: any) {
const projectsByName = action.projects.reduce((byName: any, project: any) => {
2019-12-01 22:12:13 +01:00
byName[project.full_name] = project;
return byName;
}, {});
return {
...state,
byName: {
...projectsByName,
}
};
2021-03-19 18:15:40 +01:00
}
function handleFetchProjectMilestonesSuccess(state: any, action: any) {
2021-03-20 00:58:20 +01:00
console.log(action.milestones);
2021-03-19 18:15:40 +01:00
return {
...state,
milestones: action.milestones,
};
2019-12-01 22:12:13 +01:00
}