client: Fix first show in mindmap

This commit is contained in:
Elian Doran 2024-09-01 16:13:20 +03:00
parent ff3d01f2c7
commit 1b08487ee9
No known key found for this signature in database

View File

@ -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) {