Base générale d'UI
This commit is contained in:
41
client/src/store/reducers/boards.js
Normal file
41
client/src/store/reducers/boards.js
Normal file
@ -0,0 +1,41 @@
|
||||
import { SAVE_BOARD_SUCCESS, FETCH_BOARDS_SUCCESS } from "../actions/boards";
|
||||
|
||||
export const defaultState = {
|
||||
byID: {},
|
||||
};
|
||||
|
||||
export function boardsReducer(state = defaultState, action) {
|
||||
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, action) {
|
||||
return {
|
||||
...state,
|
||||
byID: {
|
||||
...state.byID,
|
||||
[action.board.id.toString()]: {
|
||||
...action.board,
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function handleFetchBoardsSuccess(state, action) {
|
||||
const boardsByID = action.boards.reduce((byID, board) => {
|
||||
byID[board.id] = board;
|
||||
return byID;
|
||||
}, {});
|
||||
return {
|
||||
...state,
|
||||
byID: {
|
||||
...boardsByID,
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user