diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 1a0d0f6b..5f4ac59a 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -33,7 +33,6 @@ function CsComponent() { const modalQuestionParentContentId = useUiTools(state => state.modalQuestionParentContentId); const modalQuestionTargetContentId = useUiTools(state => state.modalQuestionTargetContentId); const trashQuestions = useQuestionsStore(state => state.questions); - const [isPanningCy, setIsPanningCy] = useState(false); const cyRef = useRef(null); const questions = useMemo(() => trashQuestions.filter( @@ -48,7 +47,7 @@ function CsComponent() { return storeToNodes(q); }, [questions]); - const { createPoppers, removeAllPoppers } = usePopper({ cyRef }); + const { recreatePoppers, removeAllPoppers } = usePopper({ cyRef }); const { removeNode } = useRemoveNode({ cyRef }); @@ -94,15 +93,13 @@ function CsComponent() { const onPointerDown = () => { isPointerDown = true; - cy.data("dragging", true); }; const onPointerUp = () => { + if (isPointerDown) recreatePoppers(); isPointerDown = false; - cy.data("dragging", false); - setIsPanningCy(false); }; const handleMove = () => { - setIsPanningCy(isPointerDown); + if (isPointerDown) removeAllPoppers(); }; cy.on("vmousedown", onPointerDown); @@ -114,21 +111,13 @@ function CsComponent() { cy.off("vmousemove", handleMove); document.removeEventListener("pointerup", onPointerUp); }; - }, []); - - useEffect(function poppersLifecycle() { - if (isPanningCy) { - removeAllPoppers(); - } else { - createPoppers(); - } - }, [isPanningCy, createPoppers]); + }, [recreatePoppers, removeAllPoppers]); useEffect(() => { cyRef.current?.layout(layoutOptions).run(); cyRef.current?.fit(undefined, 70); - createPoppers(); - }, [cyElements, createPoppers]); + recreatePoppers(); + }, [cyElements, recreatePoppers]); return ( <> diff --git a/src/pages/Questions/BranchingMap/hooks/usePopper.ts b/src/pages/Questions/BranchingMap/hooks/usePopper.ts index 7093fe13..52cc6fd0 100644 --- a/src/pages/Questions/BranchingMap/hooks/usePopper.ts +++ b/src/pages/Questions/BranchingMap/hooks/usePopper.ts @@ -44,7 +44,7 @@ export const usePopper = ({ popperContainerRef.current = null; }, []); - const createPoppers = useCallback(() => { + const recreatePoppers = useCallback(() => { removeAllPoppers(); const cy = cyRef.current; @@ -180,7 +180,6 @@ export const usePopper = ({ } const onZoom = (event: AbstractEventObject) => { - if (event.cy.data("dragging")) return; const zoom = event.cy.zoom(); crossesPopper.setOptions({ @@ -242,5 +241,5 @@ export const usePopper = ({ }); }, []); - return { removeAllPoppers, createPoppers }; + return { removeAllPoppers, recreatePoppers }; };