diff --git a/front/assets/icon/remove.svg b/front/assets/icon/remove.svg new file mode 100644 index 0000000..6886097 --- /dev/null +++ b/front/assets/icon/remove.svg @@ -0,0 +1,5 @@ + + + + diff --git a/front/components/editor/BasketCourt.tsx b/front/components/editor/BasketCourt.tsx index 394f403..c54224c 100644 --- a/front/components/editor/BasketCourt.tsx +++ b/front/components/editor/BasketCourt.tsx @@ -1,6 +1,6 @@ import CourtSvg from '../../assets/basketball_court.svg'; import '../../style/basket_court.css'; -import React, {MouseEvent, ReactElement, useRef, useState} from "react"; +import React, {MouseEvent, ReactElement, useEffect, useRef, useState} from "react"; import Player from "./Player"; import Draggable from "react-draggable"; @@ -15,23 +15,38 @@ export function BasketCourt() { { - console.log(e.target) - let bounds = divRef.current!.getBoundingClientRect(); - let playerCount = players.length; + const bounds = divRef.current!.getBoundingClientRect(); - if (playerCount >= TEAM_MAX_PLAYER) { + if (players.length >= TEAM_MAX_PLAYER) { return; } + // find a valid number for the player to place. + let playerIndex = players.findIndex((v, i) => + v.key !== i.toString() + ); + + if (playerIndex == -1) { + playerIndex = players.length; + } + const player = ( - { + setPlayers(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) + }) + }} /> ); - setPlayers([...players, player]) + setPlayers(players => players.toSpliced(playerIndex, 0, player)) }}/> {players} diff --git a/front/components/editor/Player.tsx b/front/components/editor/Player.tsx index c77f0b4..8d3f1ff 100644 --- a/front/components/editor/Player.tsx +++ b/front/components/editor/Player.tsx @@ -1,33 +1,50 @@ -import React, {useEffect, useRef} from "react"; +import React, {useRef} from "react"; import "../../style/player.css"; +import RemoveIcon from "../../assets/icon/remove.svg"; import Draggable, {DraggableBounds} from "react-draggable"; -export default function Player({id, x, y, bounds}: { +export interface PlayerOptions { id: number, x: number, y: number, - bounds: DraggableBounds -}) { + bounds: DraggableBounds, + onRemove: () => void +} - const ref = useRef(null); - useEffect(() => { - const playerRect = ref.current!.getBoundingClientRect(); - bounds.bottom! -= playerRect.height / 2; - bounds.right! -= playerRect.width / 2; - }, [ref]) +export default function Player({id, x, y, bounds, onRemove}: PlayerOptions) { + const ref = useRef(null); return ( + defaultPosition={{x: x, y: y}} + >
-

{id}

+ +
{ + if (e.key == "Delete") + onRemove() + }}> +
+ onRemove()}/> +
+
+

{id}

+
+
+
) diff --git a/front/style/colors.css b/front/style/colors.css index 68ccdaa..f3287cb 100644 --- a/front/style/colors.css +++ b/front/style/colors.css @@ -6,8 +6,8 @@ --background-color: #d2cdd3; - - --selected-team-primarycolor: #ffffff; --selected-team-secondarycolor: #000000; + + --selection-color: #3f7fc4 } \ No newline at end of file diff --git a/front/style/player.css b/front/style/player.css index 4450dec..8fbf487 100644 --- a/front/style/player.css +++ b/front/style/player.css @@ -1,10 +1,32 @@ +/** +as the .player div content is translated, +the real .player div position is not were the user can expect. +Disable pointer events to this div as it may overlap on other components +on the court. +*/ .player { + pointer-events: none; +} + +.player-content { + /*apply a translation to center the player piece when placed*/ + transform: translate(-50%, -75%); + + display: flex; + flex-direction: column; + align-content: center; + align-items: center; + outline: none; + +} + +.player-piece { font-family: monospace; + pointer-events: all; background-color: var(--selected-team-primarycolor); color: var(--selected-team-secondarycolor); - border-width: 2px; border-radius: 100px; border-style: solid; @@ -17,8 +39,41 @@ align-items: center; justify-content: center; - /*apply a translation to */ - transform: translate(-50%, -50%); - user-select: none; +} + +.player-selection-tab { + display: flex; + margin-bottom: 10%; + justify-content: center; + visibility: hidden; +} + +.player-selection-tab-remove { + pointer-events: all; + width: 25%; + height: 25%; +} + +.player-selection-tab-remove * { + stroke: red; + fill: white; +} + +.player-selection-tab-remove:hover * { + fill: #f1dbdb; + stroke: #ff331a; + cursor: pointer; +} + +.player:focus-within .player-selection-tab { + visibility: visible; +} + +.player:focus-within .player-piece { + color: var(--selection-color); +} + +.player:focus-within { + z-index: 1000; } \ No newline at end of file