From e8f26a977a9ba4456765843c273c4734295e1932 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sun, 30 Jan 2022 14:58:16 -0800 Subject: [PATCH] Fixed chat to fill space then scroll Signed-off-by: James Ketrenos --- client/src/Board.css | 56 +++++++++++++++++++++++++----------- client/src/Board.js | 65 +++++++++++++++++++++--------------------- server/routes/games.js | 20 ++++++++----- 3 files changed, 84 insertions(+), 57 deletions(-) diff --git a/client/src/Board.css b/client/src/Board.css index 127d4ad..9d2c2de 100755 --- a/client/src/Board.css +++ b/client/src/Board.css @@ -1,9 +1,10 @@ .Board { - display: inline-block; + display: flex; position: absolute; width: 100%; overflow: hidden; height: 100%; + justify-content: right; } .Display { @@ -67,45 +68,64 @@ display: inline-flex; flex-direction: column; box-sizing: border-box; - width: 20em; - opacity: 0.7; - z-index: 100; + width: 40vw; + max-height: 100vh; overflow: hidden; + min-width: 20em; + z-index: 100; + padding: 0.5em; } -.lobby { - width: calc(100vw - 1em); +.Game > * { + /* for Firefox */ + min-height: 0; } .Game > *:not(:last-child) { margin-bottom: 0.5em; } +.lobby { + width: calc(100vw - 1em); +} + .Chat { + display: flex; + flex-direction: column; + flex: 1; padding: 0.5em; } .Chat > * { - width: 100%; + /* for Firefox */ + min-height: 0; } -.Chat > :first-child { - max-height: 30vh; - overflow-y: scroll; +.Chat #ChatList { + flex: 1; + overflow: auto; + scroll-behavior: smooth; } .Players { padding: 0.5em; + user-select: none; +} + +.Players .PlayerSelector { + border: 1px solid rgba(0,0,0,0); + border-radius: 0.5em; +} + +.Players .PlayerSelector[data-selectable=true]:hover { + border-color: rgba(0,0,0,0.5); + cursor: pointer; } .PlayerName { padding: 0.5em; } -#ChatList { - scroll-behavior: smooth; -} - .Players > * { width: 100%; } @@ -166,13 +186,15 @@ .Action { display: flex; align-items: center; - justify-content: center; + justify-content: space-evenly; background-color: rgba(16, 16, 16, 0.25); + padding: 0.25em; } -.Action Button { +button { margin: 0.25em; background-color: white; + border: 1px solid black !important; } .Error { @@ -191,12 +213,12 @@ .Message { display: inline; - align-items: left; justify-content: left; background-color: rgba(224, 224, 224); text-align: left; font-size: 12pt; padding: 1em; + user-select: none; } .Message div { diff --git a/client/src/Board.js b/client/src/Board.js index c56bd33..84a1738 100755 --- a/client/src/Board.js +++ b/client/src/Board.js @@ -315,13 +315,19 @@ const Chat = ({ board, promoteGameState }) => { ); } -const Action = ({ board }) => { +const StartButton = ({ board }) => { const startClick = (event) => { board.setGameState("game-order").then((state) => { board.game.state = state; }); }; + return ( + + ); +}; + +const Action = ({ board }) => { const newBoardClick = (event) => { return board.shuffleBoard(); }; @@ -336,7 +342,7 @@ const Action = ({ board }) => { return ( { board.game.state === 'lobby' && <> - + } { board.game.state === 'game-order' && @@ -410,10 +416,13 @@ const Players = ({ board }) => { if (board.game.state !== "lobby" && item.status === 'Not active') { continue; } - const name = getPlayerName(board.game.sessions, color); + const name = getPlayerName(board.game.sessions, color), + selectable = item.status === 'Not active' || board.game.color === color; item.lastActive = item.lastActive > Date.now() ? Date.now() : item.lastActive; players.push(( - + { selectable && toggleSelected(color) }} className="PlayerSelector" key={`player-${color}`}> {color} @@ -422,10 +431,8 @@ const Players = ({ board }) => { { item.status + ' ' } { item.status !== 'Not active' && } )} /> - { (item.status === 'Not active' || board.game.color === color) && - toggleSelected(color)}/> + { selectable && + } )); @@ -1313,12 +1320,7 @@ class Board extends React.Component { const player = (this.game && this.game.color) ? this.game.players[this.game.color] : undefined, name = this.game ? this.game.name : ""; - let message = [], - key = 0; - const color = 'B'; - message=<>; - //message=<>{message}itallic; - // this.setState({ message: message}) + let message = <>; if (this.state.pickName || !name) { message = <>{message}Enter the name you would like to be known by, then press ENTER or select  SET.; } else { @@ -1332,9 +1334,9 @@ class Board extends React.Component { } message = <>{message}You can chat with other players below.; if (this.game.active < 2) { - message = <>{message}Once there are two or more players, you can select START GAME.; + message = <>{message}Once there are two or more players, you can select .; } else { - message = <>{message}There are enough players to start the game. Select START GAME when ready.; + message = <>{message}There are enough players to start the game. Select when ready.; } break; case 'game-order': @@ -1465,24 +1467,21 @@ class Board extends React.Component { return (
this.el = el}> this.canvas = el}> -
this.cards = el}> - { game && -
- { this.state.message } - {(this.state.pickName || !this.game.name) && } - {(!this.state.pickName && this.game.name) && - <> - - - - - } - { this.state.error &&
{this.state.error}
} -
- } - { + + { game &&
+ { this.state.message } + {(this.state.pickName || !this.game.name) && } + {(!this.state.pickName && this.game.name) && <> + + + + } + { this.state.error &&
{this.state.error}
} +
} +
this.cards = el}> + { game && game.state === "active" && - <> + <>
In hand
diff --git a/server/routes/games.js b/server/routes/games.js index cdb7a7f..96062db 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -97,34 +97,40 @@ for (let i = 0; i < 5; i++) { const games = {}; const roll = (game, session) => { - let message; + let message, error; const player = session.player, name = session.name ? session.name : "Unnamed"; switch (game.state) { case "lobby": - return `Rolling dice in the lobby is not allowed!`; + error = `Rolling dice in the lobby is not allowed!`; case "game-order": if (player.order) { - return `Player ${name} already rolled for order.`; + error = `Player ${name} already rolled for order.`; + break; } + game.dice = [ Math.ceil(Math.random() * 6) ]; player.order = game.dice[0]; message = `${name} rolled ${game.dice[0]} for play order.`; - game.chat.push({ date: Date.now(), message: message }); break; case "active": game.dice = [ Math.ceil(Math.random() * 6), Math.ceil(Math.random() * 6) ]; message = `${name} rolled ${game.dice[0] + game.dice[1]}.`; - game.chat.push({ date: Date.now(), message: message }); - return; + break; default: - return `Invalid game state (${game.state}) in roll.`; + error = `Invalid game state (${game.state}) in roll.`; + break; } + + if (!error && message) { + game.chat.push({ from: session.color, date: Date.now(), message: message }); + } + return error; }; const getPlayer = (game, color) => {