From df9d481a935c2090760047f5ae4e01fd089bf6d5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 4 Oct 2025 19:17:13 +0300 Subject: [PATCH] refactor(mindmap): use proper way to detect direction See https://github.com/SSShooter/mind-elixir-core/issues/150. --- apps/client/src/widgets/type_widgets/MindMap.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsx index a20c3bf86..6f4bb5fe7 100644 --- a/apps/client/src/widgets/type_widgets/MindMap.tsx +++ b/apps/client/src/widgets/type_widgets/MindMap.tsx @@ -136,22 +136,21 @@ function MindElixir({ content, containerProps, apiRef: externalApiRef, onChange, // On change listener. useEffect(() => { - if (!onChange) return; + const bus = apiRef.current?.bus; + if (!onChange || !bus) return; - const listener = (operation: Operation) => { + const operationListener = (operation: Operation) => { if (operation.name !== "beginEdit") { onChange(); } } - apiRef.current?.bus.addListener("operation", listener); - // Direction change buttons don't report change, so we have to hook in manually. - const $container = refToJQuerySelector(containerRef); - $container.on("click", ".mind-elixir-toolbar.lt", onChange); + bus.addListener("operation", operationListener); + bus.addListener("changeDirection", onChange); return () => { - $container.off("click", ".mind-elixir-toolbar.lt", onChange); - apiRef.current?.bus?.removeListener("operation", listener); + bus.removeListener("operation", operationListener); + bus.removeListener("changeDirection", onChange); }; }, [ onChange ]);