From 7cf719e7cbba46cdc821beb50f14d91408da6f70 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Fri, 10 Nov 2023 08:58:08 +0100 Subject: [PATCH] add possibility to place back players to their racks --- front/components/editor/BasketCourt.tsx | 9 ++----- front/data/Player.ts | 5 ++++ front/style/editor.css | 2 +- front/views/Editor.tsx | 32 ++++++++++++++++++++----- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index feb4637..f76032b 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -4,7 +4,7 @@ import {MouseEvent, ReactElement, useEffect, useRef, useState} from "react"; import CourtPlayer from "./CourtPlayer"; import {Player} from "../../data/Player"; -export function BasketCourt({players}: { players: Player[] }) { +export function BasketCourt({players, onPlayerRemove}: { players: Player[], onPlayerRemove: (Player) => void }) { const [courtPlayers, setCourtPlayers] = useState([]) const divRef = useRef(null); @@ -18,12 +18,7 @@ export function BasketCourt({players}: { players: Player[] }) { y={(bounds.height * player.bottom_percentage)} bounds={{bottom: bounds.height, top: 0, left: 0, right: bounds.width}} onRemove={() => { - // setCourtPlayers(players => { - // // recompute the player's index as it may have been moved if - // // previous players were removed and added. - // const playerCurrentIndex = players.findIndex(p => p.key === playerIndex.toString()) - // return players.toSpliced(playerCurrentIndex, 1) - // }) + onPlayerRemove(player) }} /> ) diff --git a/front/data/Player.ts b/front/data/Player.ts index da66ae3..a27e643 100644 --- a/front/data/Player.ts +++ b/front/data/Player.ts @@ -5,6 +5,11 @@ export interface Player { */ id: number, + /** + * the player's team + * */ + team: "allies" | "opponents", + /** * player's position * */ diff --git a/front/style/editor.css b/front/style/editor.css index 15bf69f..c13ac99 100644 --- a/front/style/editor.css +++ b/front/style/editor.css @@ -31,7 +31,7 @@ height: 100%; } -#team-rack .player-piece , #opponent-rack .player-piece { +#allies-rack .player-piece , #opponent-rack .player-piece { margin-left: 5px; } diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx index 89858f0..60cc8fd 100644 --- a/front/views/Editor.tsx +++ b/front/views/Editor.tsx @@ -16,11 +16,11 @@ export default function Editor({id, name}: { id: number, name: string }) { const [style, setStyle] = useState({}); const positions = ["PG", "SG", "SF", "PF", "C"] - const [team, setTeams] = useState( - positions.map(pos => ) + const [allies, setAllies] = useState( + positions.map(pos => ) ) const [opponents, setOpponents] = useState( - positions.map(pos => ) + positions.map(pos => ) ) const [players, setPlayers] = useState([]); @@ -52,6 +52,7 @@ export default function Editor({id, name}: { id: number, name: string }) { setPlayers(players => { return [...players, { id: players.length, + team: element.props.team, position: element.props.text, right_percentage: xPercent, bottom_percentage: yPercent @@ -85,8 +86,8 @@ export default function Editor({id, name}: { id: number, name: string }) {
-
- + { + setPlayers(players => { + const idx = players.indexOf(player) + return players.toSpliced(idx, 1) + }) + const piece = + switch (player.team) { + case "opponents": + setOpponents(opponents => ( + [...opponents, piece] + )) + break + case "allies": + setAllies(allies => ( + [...allies, piece] + )) + } + }}/>