From 3417e37f16cd8fde07040f049c0edfe56871d3c1 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 21 Sep 2025 09:16:54 +0300 Subject: [PATCH] chore(react/type_widget): save direction upon button press --- .../src/widgets/type_widgets/MindMap.tsx | 22 +++++++++++-------- .../src/widgets/type_widgets_old/mind_map.ts | 9 -------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsx index 433bd80d4..0883325c9 100644 --- a/apps/client/src/widgets/type_widgets/MindMap.tsx +++ b/apps/client/src/widgets/type_widgets/MindMap.tsx @@ -8,13 +8,10 @@ import "mind-elixir/style"; import "@mind-elixir/node-menu/dist/style.css"; import "./MindMap.css"; import { useEditorSpacedUpdate } from "../react/hooks"; +import { refToJQuerySelector } from "../react/react_utils"; const NEW_TOPIC_NAME = ""; -interface MindmapModel extends MindElixirData { - direction: number; -} - interface MindElixirProps { apiRef?: RefObject; direction: number; @@ -33,7 +30,7 @@ export default function MindMap({ note }: TypeWidgetProps) { let newContent: MindElixirData; if (content) { try { - newContent = JSON.parse(content) as MindmapModel; + newContent = JSON.parse(content) as MindElixirData; } catch (e) { console.warn(e); console.debug("Wrong JSON content: ", content); @@ -76,7 +73,7 @@ export default function MindMap({ note }: TypeWidgetProps) { ) } -function MindElixir({ content, containerProps, direction, apiRef: externalApiRef, onChange }: MindElixirProps) { +function MindElixir({ content, containerProps, apiRef: externalApiRef, onChange }: MindElixirProps) { const containerRef = useRef(null); const apiRef = useRef(null); @@ -84,8 +81,7 @@ function MindElixir({ content, containerProps, direction, apiRef: externalApiRef if (!containerRef.current) return; const mind = new VanillaMindElixir({ - el: containerRef.current, - direction + el: containerRef.current }); mind.install(nodeMenu); @@ -109,7 +105,15 @@ function MindElixir({ content, containerProps, direction, apiRef: externalApiRef } } apiRef.current?.bus.addListener("operation", listener); - return () => apiRef.current?.bus?.removeListener("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); + + return () => { + $container.off("click", ".mind-elixir-toolbar.lt", onChange); + apiRef.current?.bus?.removeListener("operation", listener); + }; }, [ onChange ]); return ( diff --git a/apps/client/src/widgets/type_widgets_old/mind_map.ts b/apps/client/src/widgets/type_widgets_old/mind_map.ts index 85d6f4f04..c06ec2313 100644 --- a/apps/client/src/widgets/type_widgets_old/mind_map.ts +++ b/apps/client/src/widgets/type_widgets_old/mind_map.ts @@ -15,15 +15,6 @@ export default class MindMapWidget extends TypeWidget { return "mindMap"; } - doRender() { - // Save the mind map if the user changes the layout direction. - this.$content.on("click", ".mind-elixir-toolbar.lt", () => { - this.spacedUpdate.scheduleUpdate(); - }); - - super.doRender(); - } - async doRefresh(note: FNote) { if (this.triggeredByUserOperation) { this.triggeredByUserOperation = false;