front: NewGame: Create action button enable/disable

This commit is contained in:
djmil 2023-10-28 15:16:26 +02:00
parent 2777718cda
commit 04c4550e21
4 changed files with 39 additions and 46 deletions

View File

@ -26,7 +26,7 @@
background-color:#00b0ff60; background-color:#00b0ff60;
} }
.game-action.create:active { .game-action.create.enabled:active {
background-color:#00b0ffa0; background-color:#00b0ffa0;
} }
@ -48,26 +48,6 @@
background-color:#00af0080; background-color:#00af0080;
} }
/* .game-header a { .game-action.disabled {
color:darkgrey; color: gray;
text-decoration: none;
transition: .25s ease;
margin-left: 5px;
margin-right: 5px;
} }
.game-action .active {
color: white;
border-radius: 2px;
background-color: cadetblue;
opacity: 80%;
padding-top: 8px;
padding-bottom: 8px;
}
.game-header a:hover:not(.active) {
color: cadetblue;
box-shadow: 0 1.5px 0 0 currentColor;
}
*/

View File

@ -1,22 +1,36 @@
import React/*, {useState}*/ from 'react'; import React from 'react';
import { AppContext } from '../../../context/app'
import { AppData } from '../../../context/data'
export default function Create() { export default function Create() {
// const [pending, setPending] = useState([]) const [ctx] = React.useContext(AppContext)
const [data] = React.useContext(AppData)
// for (const [key, value] of Object.entries(pending)) const hasPlayers = ctx.newGame.whitePlayer !== ctx.newGame.blackPlayer
// console.log("pending ", key, value); && ctx.newGame.blackPlayer !== ''
&& ctx.newGame.whitePlayer !== ''
// function sendRequest(reject_uuid) { const hasCurrentUser = data.isCurrentUser(ctx.newGame.blackPlayer)
// setPending( // Replace the old array || data.isCurrentUser(ctx.newGame.whitePlayer)
// [ // with a new array consisting of:
// ...pending, // - all the old items const isEnabled = hasPlayers && hasCurrentUser
// { uuid: reject_uuid } // - and a new item at the end
// ]
// )
// }
// return <button className="action" onClick={() => sendRequest(uuid) }> const onClick = () => {
// Reject if (!hasPlayers)
// </button> return alert("Choose both black and white players");
return <button className='game-action create'>Create</button>
if (!hasCurrentUser)
return alert("You must be one of the players");
console.log("TODO: send GameCreateRequest to the server!")
}
return (
<button
className={'game-action create' + (isEnabled ? ' enabled' : ' disabled')}
onClick={onClick}
>
Create
</button>
)
} }

View File

@ -19,12 +19,11 @@ export default function NewGame() {
/* /*
* Name options * Name options
*/ */
const nameOptions = data.leaderboard const nameOptions = data.leaderboard ? Object.keys(data.leaderboard).map(playerName =>
? Object.keys(data.leaderboard).map(playerName => { <option key={playerName} value={playerName}>
const displayName = data.isCurrentUser(playerName) ? 'You' : playerName {data.isCurrentUser(playerName) ? 'You' : playerName}
return <option key={playerName} value={playerName}>{displayName}</option> </option>)
}) : [<option key='loading' value='…'>loading</option>]
: []
const whiteOptions = Array(nameOptions) const whiteOptions = Array(nameOptions)
whiteOptions.push(<option key='default' value=''>{'white player …'}</option>) whiteOptions.push(<option key='default' value=''>{'white player …'}</option>)

View File

@ -15,7 +15,7 @@ export default function Header() {
</h1> </h1>
<OnlineToggle /> <OnlineToggle />
<nav> <nav>
<NavLink to="/about" className={""}> <NavLink to="/about">
About About
</NavLink> </NavLink>
<NavLink to="/game" className={data.gamesFetching && "woble"}> <NavLink to="/game" className={data.gamesFetching && "woble"}>