From 15920a666d384c783f33247ee6a60ea6f4279287 Mon Sep 17 00:00:00 2001 From: djmil Date: Thu, 26 Oct 2023 20:34:10 +0200 Subject: [PATCH] front: selectable player names for GameBoard - bugfix keys for ProposalSelector - css fix for Selectable title --- webapp/src/components/Game/GameAction.css | 2 +- webapp/src/components/Game/GameBoard.jsx | 32 +++++++++++++++++-- .../Game/GameSelector/GameProposal.jsx | 4 +-- .../Game/GameSelector/Selectable.css | 10 +++--- .../Game/GameSelector/Selectable.jsx | 10 +++--- webapp/src/components/Game/Player.css | 17 ++++++++++ webapp/src/components/Game/Player.jsx | 20 ++++++++++-- webapp/src/context/data/index.jsx | 2 +- 8 files changed, 79 insertions(+), 18 deletions(-) diff --git a/webapp/src/components/Game/GameAction.css b/webapp/src/components/Game/GameAction.css index 0e84cf4..f4a27ed 100644 --- a/webapp/src/components/Game/GameAction.css +++ b/webapp/src/components/Game/GameAction.css @@ -17,7 +17,7 @@ padding: 8px; padding-left: 15px; padding-right: 15px; - border-radius: 10px; + border-radius: 5px; border: 0.5px solid darkgrey; margin: 2px; } diff --git a/webapp/src/components/Game/GameBoard.jsx b/webapp/src/components/Game/GameBoard.jsx index 2dcc0fa..84fa5a5 100644 --- a/webapp/src/components/Game/GameBoard.jsx +++ b/webapp/src/components/Game/GameBoard.jsx @@ -1,13 +1,39 @@ -import './GameBoard.css'; -import React from 'react'; - +import './GameBoard.css' +import React, { useState } from 'react' +import { AppData } from '../../context/data' import Board from './GameBoard/Board' +import { SelectPlayer } from './Player' +// import { WHITE, BLACK, WhiteStone, BlackStone } from './Stone' export default function GameBoard() { + const [data] = React.useContext(AppData) + + const [whiteName, setWhiteName] = useState(''); + const [blackName, setBlackName] = useState(''); + + + const nameOptions = data.leaderboard + ? Object.keys(data.leaderboard).map(playerName => { + const displayName = data.isCurrentUser(playerName) ? 'You' : playerName + return + }) + : [] + + const whiteOptions = Array(nameOptions) + whiteOptions.push() + + const blackOptions = Array(nameOptions) + blackOptions.push() + + return (
+ + {/* */} + {/* */} +
) } diff --git a/webapp/src/components/Game/GameSelector/GameProposal.jsx b/webapp/src/components/Game/GameSelector/GameProposal.jsx index 322c547..8a9c8a9 100644 --- a/webapp/src/components/Game/GameSelector/GameProposal.jsx +++ b/webapp/src/components/Game/GameSelector/GameProposal.jsx @@ -5,11 +5,11 @@ export default function ProposalSelector({ games }) { const waitForYou = games .filter(game => game.status === Status.WaitForYou) - .map(game => ) + .map(game => ) const WaitForOpponent = games .filter(game => game.status === Status.WaitForOpponent) - .map(game => ) + .map(game => ) return (
diff --git a/webapp/src/components/Game/GameSelector/Selectable.css b/webapp/src/components/Game/GameSelector/Selectable.css index abc3ec4..c93e7b8 100644 --- a/webapp/src/components/Game/GameSelector/Selectable.css +++ b/webapp/src/components/Game/GameSelector/Selectable.css @@ -31,7 +31,9 @@ margin-bottom: 7px; } -.stone { - vertical-align: -3px; - margin: 3px 3px; -} +.selectable .title { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} diff --git a/webapp/src/components/Game/GameSelector/Selectable.jsx b/webapp/src/components/Game/GameSelector/Selectable.jsx index b2ed7cd..8dceb2f 100644 --- a/webapp/src/components/Game/GameSelector/Selectable.jsx +++ b/webapp/src/components/Game/GameSelector/Selectable.jsx @@ -3,7 +3,7 @@ import React from 'react'; import { oppositeColor } from '../Stone'; import Player from '../Player'; -export default function Selectable({game}) { +export default function Selectable({ game }) { const myColor = game.myColor @@ -11,11 +11,11 @@ export default function Selectable({game}) { const opponentName = game.opponentName return ( -
-
- +
+
+ vs - +
{game.message}
diff --git a/webapp/src/components/Game/Player.css b/webapp/src/components/Game/Player.css index e69de29..7e79ced 100644 --- a/webapp/src/components/Game/Player.css +++ b/webapp/src/components/Game/Player.css @@ -0,0 +1,17 @@ +.player { + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; +} + +.player select { + border-radius: 5px; + border: 0.5px solid darkgrey; + + margin: 4px; +} + +.player select:hover { + background: lightgray; +} \ No newline at end of file diff --git a/webapp/src/components/Game/Player.jsx b/webapp/src/components/Game/Player.jsx index 113879f..d4855f3 100644 --- a/webapp/src/components/Game/Player.jsx +++ b/webapp/src/components/Game/Player.jsx @@ -5,9 +5,25 @@ import { Stone } from './Stone' export default function Player({ color, name }) { return ( - +
{name} - +
+ ) +} + +export function SelectPlayer({ name, setName, nameOptions }) { + const handleSelectChange = (event) => { + setName(event.target.value) + } + + return ( +
+
+ +
+
) } diff --git a/webapp/src/context/data/index.jsx b/webapp/src/context/data/index.jsx index b2579b0..e7fa95e 100644 --- a/webapp/src/context/data/index.jsx +++ b/webapp/src/context/data/index.jsx @@ -14,7 +14,7 @@ export const AppDataProvider = ({ children }) => { const [games, gamesFetching ] = Poll('/api/gamestate' , 30, data.offlineMode) const [leaderboard, leaderboardFetching ] = Poll('/api/leaderboard', 60, data.offlineMode) - const [user] = Poll('api/user') // once + const [user] = Poll('/api/user') // once data.games = games data.gamesFetching = gamesFetching