fix(ui): memoize event handlers on bounding box

This commit is contained in:
psychedelicious 2023-09-27 17:08:14 +10:00
parent 53eb23b8b6
commit ba4aaea45b

View File

@ -213,45 +213,45 @@ const IAICanvasBoundingBox = (props: IAICanvasBoundingBoxPreviewProps) => {
[scaledStep] [scaledStep]
); );
const handleStartedTransforming = () => { const handleStartedTransforming = useCallback(() => {
dispatch(setIsTransformingBoundingBox(true)); dispatch(setIsTransformingBoundingBox(true));
}; }, [dispatch]);
const handleEndedTransforming = () => { const handleEndedTransforming = useCallback(() => {
dispatch(setIsTransformingBoundingBox(false)); dispatch(setIsTransformingBoundingBox(false));
dispatch(setIsMovingBoundingBox(false)); dispatch(setIsMovingBoundingBox(false));
dispatch(setIsMouseOverBoundingBox(false)); dispatch(setIsMouseOverBoundingBox(false));
setIsMouseOverBoundingBoxOutline(false); setIsMouseOverBoundingBoxOutline(false);
}; }, [dispatch]);
const handleStartedMoving = () => { const handleStartedMoving = useCallback(() => {
dispatch(setIsMovingBoundingBox(true)); dispatch(setIsMovingBoundingBox(true));
}; }, [dispatch]);
const handleEndedModifying = () => { const handleEndedModifying = useCallback(() => {
dispatch(setIsTransformingBoundingBox(false)); dispatch(setIsTransformingBoundingBox(false));
dispatch(setIsMovingBoundingBox(false)); dispatch(setIsMovingBoundingBox(false));
dispatch(setIsMouseOverBoundingBox(false)); dispatch(setIsMouseOverBoundingBox(false));
setIsMouseOverBoundingBoxOutline(false); setIsMouseOverBoundingBoxOutline(false);
}; }, [dispatch]);
const handleMouseOver = () => { const handleMouseOver = useCallback(() => {
setIsMouseOverBoundingBoxOutline(true); setIsMouseOverBoundingBoxOutline(true);
}; }, []);
const handleMouseOut = () => { const handleMouseOut = useCallback(() => {
!isTransformingBoundingBox && !isTransformingBoundingBox &&
!isMovingBoundingBox && !isMovingBoundingBox &&
setIsMouseOverBoundingBoxOutline(false); setIsMouseOverBoundingBoxOutline(false);
}; }, [isMovingBoundingBox, isTransformingBoundingBox]);
const handleMouseEnterBoundingBox = () => { const handleMouseEnterBoundingBox = useCallback(() => {
dispatch(setIsMouseOverBoundingBox(true)); dispatch(setIsMouseOverBoundingBox(true));
}; }, [dispatch]);
const handleMouseLeaveBoundingBox = () => { const handleMouseLeaveBoundingBox = useCallback(() => {
dispatch(setIsMouseOverBoundingBox(false)); dispatch(setIsMouseOverBoundingBox(false));
}; }, [dispatch]);
return ( return (
<Group {...rest}> <Group {...rest}>