From 5f883e35cd81001954133591157e00304cf1875d Mon Sep 17 00:00:00 2001 From: dwelle <5153846+dwelle@users.noreply.github.com> Date: Wed, 30 Apr 2025 15:46:46 +0200 Subject: [PATCH] refactor --- .../components/ConvertElementTypePopup.tsx | 96 ++++++++++--------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/packages/excalidraw/components/ConvertElementTypePopup.tsx b/packages/excalidraw/components/ConvertElementTypePopup.tsx index 973d9d523..141df4f85 100644 --- a/packages/excalidraw/components/ConvertElementTypePopup.tsx +++ b/packages/excalidraw/components/ConvertElementTypePopup.tsx @@ -192,25 +192,29 @@ const Panel = ({ elements: ExcalidrawElement[]; }) => { const conversionType = getConversionTypeFromElements(elements); - const generic = conversionType === "generic"; - const linear = conversionType === "linear"; const genericElements = useMemo(() => { - return generic ? filterGenericConvetibleElements(elements) : []; - }, [generic, elements]); + return conversionType === "generic" + ? filterGenericConvetibleElements(elements) + : []; + }, [conversionType, elements]); const linearElements = useMemo(() => { - return linear ? filterLinearConvertibleElements(elements) : []; - }, [linear, elements]); + return conversionType === "linear" + ? filterLinearConvertibleElements(elements) + : []; + }, [conversionType, elements]); - const sameType = generic - ? genericElements.every( - (element) => element.type === genericElements[0].type, - ) - : linear - ? linearElements.every( - (element) => getArrowType(element) === getArrowType(linearElements[0]), - ) - : false; + const sameType = + conversionType === "generic" + ? genericElements.every( + (element) => element.type === genericElements[0].type, + ) + : conversionType === "linear" + ? linearElements.every( + (element) => + getArrowType(element) === getArrowType(linearElements[0]), + ) + : false; const [panelPosition, setPanelPosition] = useState({ x: 0, y: 0 }); const positionRef = useRef(""); @@ -306,20 +310,21 @@ const Panel = ({ } }, [genericElements, app.scene]); - const SHAPES: [string, ReactNode][] = linear - ? [ - ["line", LineIcon], - ["sharpArrow", sharpArrowIcon], - ["curvedArrow", roundArrowIcon], - ["elbowArrow", elbowArrowIcon], - ] - : generic - ? [ - ["rectangle", RectangleIcon], - ["diamond", DiamondIcon], - ["ellipse", EllipseIcon], - ] - : []; + const SHAPES: [string, ReactNode][] = + conversionType === "linear" + ? [ + ["line", LineIcon], + ["sharpArrow", sharpArrowIcon], + ["curvedArrow", roundArrowIcon], + ["elbowArrow", elbowArrowIcon], + ] + : conversionType === "generic" + ? [ + ["rectangle", RectangleIcon], + ["diamond", DiamondIcon], + ["ellipse", EllipseIcon], + ] + : []; return (