mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
23 lines
554 B
JavaScript
23 lines
554 B
JavaScript
import defaultState from "store/default-state";
|
|
import movePiece from "reducers/move-piece";
|
|
|
|
const chessBoardReducer = (state = defaultState, action) => {
|
|
switch (action.type) {
|
|
case "MOVE_PIECE":
|
|
const newState = {
|
|
board: movePiece(state.board, action.from, action.to),
|
|
selectedSquare: null
|
|
}
|
|
|
|
return Object.assign({}, state, newState);
|
|
|
|
case "SELECT_PIECE":
|
|
return Object.assign({}, state, { selectedSquare: action.coords });
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default chessBoardReducer;
|