Skip to content

Commit

Permalink
Show error when clicking on image before mask (blakeblackshear#8547)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Nov 9, 2023
1 parent fa96ec6 commit 1b57f8c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions web/src/routes/CameraMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ ${Object.keys(objectMaskPoints)
snap={snap}
width={width}
height={height}
setError={setError}
/>
</div>
<div className="max-w-xs">
Expand Down Expand Up @@ -434,7 +435,7 @@ function boundedSize(value, maxValue, snap) {
return newValue;
}

function EditableMask({ onChange, points, scale, snap, width, height }) {
function EditableMask({ onChange, points, scale, snap, width, height, setError }) {
const boundingRef = useRef(null);

const handleMovePoint = useCallback(
Expand All @@ -455,6 +456,11 @@ function EditableMask({ onChange, points, scale, snap, width, height }) {
// Add a new point between the closest two other points
const handleAddPoint = useCallback(
(event) => {
if (!points) {
setError('You must choose an item to edit or add a new item before adding a point.');
return
}

const { offsetX, offsetY } = event;
const scaledX = boundedSize((offsetX - MaskInset) / scale, width, snap);
const scaledY = boundedSize((offsetY - MaskInset) / scale, height, snap);
Expand All @@ -474,7 +480,7 @@ function EditableMask({ onChange, points, scale, snap, width, height }) {
newPoints.splice(index, 0, newPoint);
onChange(newPoints);
},
[height, width, scale, points, onChange, snap]
[height, width, scale, points, onChange, snap, setError]
);

const handleRemovePoint = useCallback(
Expand Down

0 comments on commit 1b57f8c

Please sign in to comment.