Migration du client sur Typescript
This commit is contained in:
42
client/src/store/reducers/boards.ts
Normal file
42
client/src/store/reducers/boards.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { SAVE_BOARD_SUCCESS, FETCH_BOARDS_SUCCESS } from "../actions/boards";
|
||||
|
||||
export const defaultState = {
|
||||
byID: {},
|
||||
};
|
||||
|
||||
export function boardsReducer(state = defaultState, action: any) {
|
||||
switch(action.type) {
|
||||
case SAVE_BOARD_SUCCESS:
|
||||
return handleSaveBoardSuccess(state, action);
|
||||
case FETCH_BOARDS_SUCCESS:
|
||||
return handleFetchBoardsSuccess(state, action);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
function handleSaveBoardSuccess(state: any, action: any) {
|
||||
const { board } = action;
|
||||
return {
|
||||
...state,
|
||||
byID: {
|
||||
...state.byID,
|
||||
[board.id]: {
|
||||
...board,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function handleFetchBoardsSuccess(state: any, action: any) {
|
||||
const boardsByID = action.boards.reduce((byID: any, board: any) => {
|
||||
byID[board.id] = board;
|
||||
return byID;
|
||||
}, {});
|
||||
return {
|
||||
...state,
|
||||
byID: {
|
||||
...boardsByID,
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user