mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 08:58:58 +01:00
chore(react/type_widget): save direction upon button press
This commit is contained in:
parent
143e6a556c
commit
3417e37f16
@ -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: 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 (
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user