A
A
A
useEffect(() => {
console.log(window.innerHeight);
}, []);
if (isFinished) {
return;
}
if (isMouseOverStartPoint && points.length >= 3) {
setIsFinished(true);
} else {
setPoints((prevPoints) => [...prevPoints, mousePos]);
}
};
return (
<Stage
width={window.innerWidth}
height={window.innerHeight}
onMouseDown={handleClick}
onMouseMove={handleMouseMove}
>
<Layer>
<Line
points={flattenedPoints}
stroke="black"
strokeWidth={1}
closed={isFinished}
/>
{points.map((point, index) => {
const width = 6;
const x = point[0] - width / 2;
const y = point[1] - width / 2;
const startPointAttr =
index === 0
? {
hitStrokeWidth: 12,
onMouseOver: handleMouseOverStartPoint,
onMouseOut: handleMouseOutStartPoint,
}
: null;
return (
<Rect
key={index}
x={x}
y={y}
width={width}
height={width}
fill="white"
stroke="black"
strokeWidth={1}
onDragMove={handleDragMovePoint}
draggable
{...startPointAttr}
/>
);
})}
</Layer>
</Stage>
);
};