Skip to content

Commit 06ff6d9

Browse files
jbartkaAndrius Iljinych
andauthored
PLAN-195 Change Board Squares Design (#245)
* updated square design on hover and figure placement * removed display of board square, column letter, and row number after the game is over * removed popover functionality * isHovered controls the appearance of showPopover * removes unnecessary curly brackets and changes the if statement for game finish status * PLAN-195 added todo comment --------- Co-authored-by: Justas Bartka <> Co-authored-by: Andrius Iljinych <[email protected]>
1 parent 258255e commit 06ff6d9

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

services/app/src/components/chessBoard/Square.jsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useChessBoardContext } from '../../contexts/ChessBoardContext';
77
import UserAvatar from '../avatar/UserAvatar';
88
import { squareItemPropType } from '../../prop-types/chessboard';
99
import SquarePopUp from './SquarePopUp';
10+
import { GameState } from '../../constants/gameConstants'
1011

1112
const figures = PIECES.reduce((prev, curr) => ({ ...prev, [curr.name]: curr}), {});
1213

@@ -16,8 +17,8 @@ const Square = ({
1617
column,
1718
filled
1819
}) => {
19-
const { board, currentPlayerId } = useChessBoardContext();
20-
const [showPopover, setShowPopover] = useState(false);
20+
const { board, currentPlayerId, gameState } = useChessBoardContext();
21+
const [isHovered, setIsHovered] = useState(false);
2122

2223
const turnToShow = useMemo(() => {
2324
const myMove = items.find(figure => figure.playerId === currentPlayerId);
@@ -32,22 +33,17 @@ const Square = ({
3233
? 3
3334
: 2;
3435

35-
const updatePopover = bool => {
36-
if (items.length && bool || !bool) {
37-
setShowPopover(bool);
38-
}
39-
}
40-
4136
return (
4237
<div
4338
data-testid={`chess-tile-${row}-${column}`}
4439
className={classNames("square", {
4540
'is-empty-tile': !items.length && row !== board.length - 1 && column !== 0
4641
})}
47-
onMouseEnter={() => updatePopover(true)}
48-
onMouseLeave={() => updatePopover(false)}
42+
onMouseEnter={() => setIsHovered(true)}
43+
onMouseLeave={() => setIsHovered(false)}
4944
>
50-
{!!items.length && (
45+
{/* TODO: make it more prettier when fixing PLAN-205 */}
46+
{(isHovered && (!items.length && row !== board.length - 1 && column !== 0) && (gameState !== GameState.GAME_FINISHED)) && (
5147
<span
5248
className={classNames('number number-row', {
5349
'number-filled': filled
@@ -97,8 +93,9 @@ const Square = ({
9793
</div>
9894
)}
9995
</div>
100-
101-
{!!items.length && (
96+
97+
{/* TODO: make it more prettier when fixing PLAN-205 */}
98+
{(isHovered && (!items.length && row !== board.length - 1 && column !== 0) && (gameState !== GameState.GAME_FINISHED))&& (
10299
<span
103100
className={classNames('number number-column', {
104101
'number-filled': filled,
@@ -107,7 +104,7 @@ const Square = ({
107104
{board[board.length - 1][column].attribute}
108105
</span>
109106
)}
110-
{!!items.length && <SquarePopUp items={items} showPopover={showPopover} row={row} column={column} />}
107+
{!!items.length && <SquarePopUp items={items} showPopover={isHovered} row={row} column={column} />}
111108
</div>
112109
);
113110
};

0 commit comments

Comments
 (0)