diff --git a/webapp/src/components/Game/GameBoard.jsx b/webapp/src/components/Game/GameBoard.jsx index 1e758d6..9af7ef8 100644 --- a/webapp/src/components/Game/GameBoard.jsx +++ b/webapp/src/components/Game/GameBoard.jsx @@ -1,19 +1,20 @@ import './GameBoard.css' -import React, { useState } from 'react' +import React from 'react' import Board from './GameBoard/Board' import { WHITE, BLACK } from './Stone' import { Player } from './Player' +import { AppContext } from '../../context/app' + export default function GameBoard() { - const [whiteName] = useState(''); - const [blackName] = useState(''); + const [ctx] = React.useContext(AppContext) return (
- + - +
) } diff --git a/webapp/src/components/Game/NewGame.css b/webapp/src/components/Game/NewGame.css index 8b9fe77..0f26667 100644 --- a/webapp/src/components/Game/NewGame.css +++ b/webapp/src/components/Game/NewGame.css @@ -1,14 +1,14 @@ .new-game { - margin-top: 70px; + margin-top: 60px; } .new-game * { width: 230px; } -.new-game .container { - margin-top: 40px; - margin-bottom: 40px; +.new-game div { + margin-top: 25px; + margin-bottom: 25px; } .new-game .stone { diff --git a/webapp/src/components/Game/NewGame.jsx b/webapp/src/components/Game/NewGame.jsx index d6804e1..9ed3a5a 100644 --- a/webapp/src/components/Game/NewGame.jsx +++ b/webapp/src/components/Game/NewGame.jsx @@ -1,18 +1,15 @@ import './NewGame.css'; import React from 'react'; import { AppData } from '../../context/data' +import { AppContext } from '../../context/app' import { useLocation, matchPath } from "react-router"; import { SelectPlayer } from './Player'; import { WhiteStone, BlackStone } from './Stone'; -// import { AppContext } from '../../context/app' export default function NewGame() { - // const [ctx, dispatchCtx] = React.useContext(AppContext) + const [ctx, dispatchCtx] = React.useContext(AppContext) const [data] = React.useContext(AppData) - const [whiteName, setWhiteName] = React.useState(''); - const [blackName, setBlackName] = React.useState(''); - const { pathname } = useLocation(); const isMyPath = matchPath("/game/new", pathname); @@ -32,15 +29,24 @@ export default function NewGame() { const blackOptions = Array(nameOptions) blackOptions.push() + const setWhitePlayer = (name) => { + dispatchCtx({ component: "new-game", whitePlayer: name }) + } + + const setBlackPlayer = (name) => { + dispatchCtx({ component: "new-game", blackPlayer: name }) + } + return (
-
- player - +
+ +
-
- - player +
- vs -
+
+ +
) diff --git a/webapp/src/context/app/reducer.js b/webapp/src/context/app/reducer.js index 38b8775..287af2e 100644 --- a/webapp/src/context/app/reducer.js +++ b/webapp/src/context/app/reducer.js @@ -5,6 +5,9 @@ export const reducer = (state, action) => { case "game-selector": return GameSelector_update(state, action) + case "new-game": + return NewGame_update(state, action) + default: console.warn("Unknown action.component", action.component) return state @@ -15,12 +18,18 @@ export const initialState = { gameSelector: { selectedGameProposal: null, selectedActiveGame: null, - selectedArchiveGame: null - } + selectedArchiveGame: null, + }, + + newGame: { + whitePlayer: '', + blackPlayer: '', + }, + } function GameSelector_update(state, action) { - if (Object.hasOwn(action, 'selectedGameProposal')) + if (Object.hasOwn(action, 'selectedGameProposal')) { return { ...state, gameSelector: { @@ -28,8 +37,9 @@ function GameSelector_update(state, action) { selectedGameProposal: action.selectedGameProposal } } + } - if (Object.hasOwn(action, 'selectedActiveGame')) + if (Object.hasOwn(action, 'selectedActiveGame')) { return { ...state, gameSelector: { @@ -37,8 +47,9 @@ function GameSelector_update(state, action) { selectedActiveGame: action.selectedActiveGame } } + } - if (Object.hasOwn(action, 'selectedArchiveGame')) + if (Object.hasOwn(action, 'selectedArchiveGame')) { return { ...state, gameSelector: { @@ -46,6 +57,31 @@ function GameSelector_update(state, action) { selectedArchiveGame: action.selectedArchiveGame } } + } - console.warn(action.component, "- bad property") + console.warn(action.component, "- bad property") } + +function NewGame_update(state, action) { + if (Object.hasOwn(action, 'whitePlayer')) { + return { + ...state, + newGame: { + ...state.newGame, + whitePlayer: action.whitePlayer + } + } + } + + if (Object.hasOwn(action, 'blackPlayer')) { + return { + ...state, + newGame: { + ...state.newGame, + blackPlayer: action.blackPlayer + } + } + } + + console.warn(action.component, "- bad property") +} \ No newline at end of file