From 2ffca5a1881752d22119bb7ef1709ef4b4c2e1e8 Mon Sep 17 00:00:00 2001 From: "maxime.batista" Date: Thu, 4 Jan 2024 17:34:40 +0100 Subject: [PATCH] apply suggestions --- .gitignore | 1 + front/components/arrows/BendableArrow.tsx | 23 +++++++++-------------- front/components/editor/CourtPlayer.tsx | 4 ++-- sql/.guard | 0 4 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 sql/.guard diff --git a/.gitignore b/.gitignore index 61df6e7..a02dfdf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ vendor composer.lock *.phar /dist +.guard # sqlite database files *.sqlite diff --git a/front/components/arrows/BendableArrow.tsx b/front/components/arrows/BendableArrow.tsx index c69a653..5d8c314 100644 --- a/front/components/arrows/BendableArrow.tsx +++ b/front/components/arrows/BendableArrow.tsx @@ -7,6 +7,7 @@ import { useLayoutEffect, useRef, useState, + MouseEvent as ReactMouseEvent, } from "react" import { add, @@ -398,14 +399,12 @@ export default function BendableArrow({ } }, [update, containerRef]) - // Inserts a segment where the mouse double clicks on the arrow - useEffect(() => { - if (forceStraight) return - - const addSegment = (e: MouseEvent) => { + const addSegment = useCallback( + (e: ReactMouseEvent) => { + if (forceStraight) return const parentBase = area.current!.getBoundingClientRect() - const clickAbsolutePos: Pos = { x: e.x, y: e.y } + const clickAbsolutePos: Pos = { x: e.pageX, y: e.pageY } const clickPosBaseRatio = ratioWithinBase( clickAbsolutePos, parentBase, @@ -473,14 +472,9 @@ export default function BendableArrow({ }, ), ) - } - - pathRef?.current?.addEventListener("dblclick", addSegment) - - return () => { - pathRef?.current?.removeEventListener("dblclick", addSegment) - } - }, [pathRef, segments, onSegmentsChanges]) + }, + [area, forceStraight, onSegmentsChanges, segments, startPos], + ) return (
{ if (onDeleteRequested && e.key == "Delete") onDeleteRequested() diff --git a/front/components/editor/CourtPlayer.tsx b/front/components/editor/CourtPlayer.tsx index aa120b2..3d5ffde 100644 --- a/front/components/editor/CourtPlayer.tsx +++ b/front/components/editor/CourtPlayer.tsx @@ -17,7 +17,7 @@ export interface PlayerProps { /** * A player that is placed on the court, which can be selected, and moved in the associated bounds * */ -export default function CourtPlayer({ +export default function CourtPlayer({ player, onDrag, onChange, @@ -50,7 +50,7 @@ export default function CourtPlayer({ team: player.team, role: player.role, hasBall: player.hasBall, - } as Player) + }) }}>