Compare commits

..

No commits in common. "142129a37656c00cbb828ed8eb8d0ec1bb159d7d" and "eb4a255a9082ee17feb0d1c65e368bd14bf67e23" have entirely different histories.

3 changed files with 29 additions and 24 deletions

View File

@ -6,7 +6,7 @@
width: 230px; width: 230px;
} }
.new-game>div { /* first level childs only*/ .new-game div {
margin-top: 25px; margin-top: 25px;
margin-bottom: 25px; margin-bottom: 25px;
} }

View File

@ -24,17 +24,17 @@ export default function NewGame() {
: [] : []
const whiteOptions = Array(nameOptions) const whiteOptions = Array(nameOptions)
whiteOptions.push(<option key='default' value=''>{'white player …'}</option>) whiteOptions.push(<option key='default' value=''>{'select …'}</option>)
const blackOptions = Array(nameOptions) const blackOptions = Array(nameOptions)
blackOptions.push(<option key='default' value=''>{'black player …'}</option>) blackOptions.push(<option key='default' value=''>{'select …'}</option>)
const setWhitePlayer = (name) => { const setWhitePlayer = (name) => {
dispatchCtx({ update: "newGame", whitePlayer: name }) dispatchCtx({ component: "new-game", whitePlayer: name })
} }
const setBlackPlayer = (name) => { const setBlackPlayer = (name) => {
dispatchCtx({ update: "newGame", blackPlayer: name }) dispatchCtx({ component: "new-game", blackPlayer: name })
} }
return ( return (

View File

@ -1,12 +1,12 @@
export const reducer = (state, action) => { export const reducer = (state, action) => {
switch (action.update) { switch (action.component) {
case "game-selector": case "game-selector":
return GameSelector_update(state, action) return GameSelector_update(state, action)
case "newGame": case "new-game":
return updateNewGame(state, action) return NewGame_update(state, action)
default: default:
console.warn("Unknown action.component", action.component) console.warn("Unknown action.component", action.component)
@ -62,21 +62,26 @@ function GameSelector_update(state, action) {
console.warn(action.component, "- bad property") console.warn(action.component, "- bad property")
} }
function updateNewGame(state, action) { function NewGame_update(state, action) {
const newGame = {...state.newGame} if (Object.hasOwn(action, 'whitePlayer')) {
return {
Object.keys(action) ...state,
.slice(1) // skip 'update' property newGame: {
.forEach(actionKey => { ...state.newGame,
if (Object.hasOwn(newGame, actionKey)) { whitePlayer: action.whitePlayer
newGame[actionKey] = action[actionKey] }
} else {
console.warn("NewGame update: bad action property\n", actionKey + ":", action[actionKey])
} }
})
return {
...state,
newGame
} }
}
if (Object.hasOwn(action, 'blackPlayer')) {
return {
...state,
newGame: {
...state.newGame,
blackPlayer: action.blackPlayer
}
}
}
console.warn(action.component, "- bad property")
}