From 1b08487ee954905da0d52e4d9c96b81186664d52 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 1 Sep 2024 16:13:20 +0300 Subject: [PATCH] client: Fix first show in mindmap --- .../app/widgets/type_widgets/mind_map.js | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/public/app/widgets/type_widgets/mind_map.js b/src/public/app/widgets/type_widgets/mind_map.js index ee12415d5..e9f5e0640 100644 --- a/src/public/app/widgets/type_widgets/mind_map.js +++ b/src/public/app/widgets/type_widgets/mind_map.js @@ -24,39 +24,51 @@ export default class MindMapWidget extends TypeWidget { doRender() { this.$widget = $(TPL); - this.$content = this.$widget.find(".mind-map-container"); - - libraryLoader - .requireLibrary(libraryLoader.MIND_ELIXIR) - .then(() => { - this.#onLibraryLoaded(); - }); + this.$content = this.$widget.find(".mind-map-container"); super.doRender(); } - #onLibraryLoaded() { + async doRefresh(note) { + if (this.triggeredByUserOperation) { + this.triggeredByUserOperation = false; + return; + } + + if (!window.MindElixir) { + await libraryLoader.requireLibrary(libraryLoader.MIND_ELIXIR); + this.#initLibrary(); + } + + await this.#loadData(note); + } + + cleanup() { + this.triggeredByUserOperation = false; + } + + async #loadData(note) { + const blob = await note.getBlob(); + const content = blob.getJsonContent(); + this.mind.refresh(content); + } + + #initLibrary() { const mind = new MindElixir({ el: this.$content[0], direction: MindElixir.LEFT }); + this.mind = mind; mind.init(MindElixir.new()); mind.bus.addListener("operation", (operation) => { - this.spacedUpdate.scheduleUpdate(); + this.triggeredByUserOperation = true; + if (operation.name !== "startEdit") { + this.spacedUpdate.scheduleUpdate(); + } }); } - async doRefresh(note) { - if (!this.mind) { - return; - } - - const blob = await note.getBlob(); - const content = blob.getJsonContent(); - this.mind.refresh(content); - } - async getData() { const mind = this.mind; if (!mind) {