Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react/type_widget): save direction upon button press
Elian Doran3417e37f16cd
diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsxindex 433bd80d45..0883325c9b 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<MindElixirInstance>;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<HTMLDivElement>(null);const apiRef = useRef<MindElixirInstance>(null);@@ -84,8 +81,7 @@ function MindElixir({ content, containerProps, direction, apiRef: externalApiRefif (!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.tsindex 85d6f4f046..c06ec2313f 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;