dekk-app/react-mops

View on GitHub
packages/react-mops/src/hooks/listen.ts

Summary

Maintainability
A
2 hrs
Test Coverage
import React from "react";

export const listenRR = ({
    currentSize,
    currentPosition,
    currentRotation,
    loaded,
    isDown,
    isTopDown,
    isRightDown,
    isBottomDown,
    isLeftDown,
    isTopLeftDown,
    isTopRightDown,
    isBottomLeftDown,
    isBottomRightDown,
    handleDrag,
    handleResize,
    isRotationDown,
    handleRotate
}) =>
    React.useEffect(() => {
        if (loaded) {
            if (isDown) {
                handleDrag();
            } else if (
                [
                    isTopDown,
                    isRightDown,
                    isBottomDown,
                    isLeftDown,
                    isTopLeftDown,
                    isTopRightDown,
                    isBottomLeftDown,
                    isBottomRightDown
                ].filter(Boolean).length
            ) {
                handleResize();
            } else if (isRotationDown) {
                handleRotate();
            }
        }
    }, [currentSize, currentPosition, currentRotation]);