Migration du client sur Typescript
This commit is contained in:
27
client/src/store/reducers/projects.ts
Normal file
27
client/src/store/reducers/projects.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { FETCH_PROJECTS_SUCCESS } from "../actions/projects";
|
||||
|
||||
export const defaultState = {
|
||||
byName: {},
|
||||
};
|
||||
|
||||
export function projectsReducer(state = defaultState, action: any) {
|
||||
switch(action.type) {
|
||||
case FETCH_PROJECTS_SUCCESS:
|
||||
return handleFetchProjectsSuccess(state, action);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
function handleFetchProjectsSuccess(state: any, action: any) {
|
||||
const projectsByName = action.projects.reduce((byName: any, project: any) => {
|
||||
byName[project.full_name] = project;
|
||||
return byName;
|
||||
}, {});
|
||||
return {
|
||||
...state,
|
||||
byName: {
|
||||
...projectsByName,
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user