diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 5cb52bf2b..3565ecbb8 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -33,7 +33,7 @@ class AppContext { this.components = [ rootContainer, - new Entrypoints(), + new Entrypoints(this), new DialogEventComponent(this) ]; diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js index 67931cccb..b9e2f5154 100644 --- a/src/public/javascripts/widgets/component.js +++ b/src/public/javascripts/widgets/component.js @@ -4,7 +4,10 @@ export default class Component { /** @param {AppContext} appContext */ constructor(appContext) { this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6); + /** @type AppContext */ this.appContext = appContext; + /** @type TabManager */ + this.tabManager = appContext.tabManager; /** @type Component[] */ this.children = []; this.initialized = Promise.resolve(); diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 28230c0db..d284fbf4e 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -54,7 +54,7 @@ export default class NoteDetailWidget extends TabAwareWidget { this.$widget.on("dragleave", e => e.preventDefault()); this.$widget.on("drop", async e => { - const activeNote = this.appContext.tabManager.getActiveTabNote(); + const activeNote = this.tabManager.getActiveTabNote(); if (!activeNote) { return; diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 1e73e65cb..87d1257f7 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -62,7 +62,7 @@ export default class NoteTreeWidget extends TabAwareWidget { } }); - treeBuilder.prepareTree().then(treeData => this.initFancyTree($tree, treeData)); + this.initialized = treeBuilder.prepareTree().then(treeData => this.initFancyTree($tree, treeData)); return $widget; } @@ -106,7 +106,7 @@ export default class NoteTreeWidget extends TabAwareWidget { const notePath = await treeService.getNotePath(data.node); - const activeTabContext = this.appContext.tabManager.getActiveTabContext(); + const activeTabContext = this.tabManager.getActiveTabContext(); await activeTabContext.setNote(notePath); }, expand: (event, data) => this.setExpandedToServer(data.node.data.branchId, true), diff --git a/src/public/javascripts/widgets/tab_aware_widget.js b/src/public/javascripts/widgets/tab_aware_widget.js index 4e4c5ee1a..32b87259b 100644 --- a/src/public/javascripts/widgets/tab_aware_widget.js +++ b/src/public/javascripts/widgets/tab_aware_widget.js @@ -68,7 +68,7 @@ export default class TabAwareWidget extends BasicWidget { refreshWithNote(note, notePath) {} activeTabChangedListener() { - this.tabContext = this.appContext.tabManager.getActiveTabContext(); + this.tabContext = this.tabManager.getActiveTabContext(); this.activeTabChanged(); } @@ -79,7 +79,7 @@ export default class TabAwareWidget extends BasicWidget { lazyLoadedListener() { if (!this.tabContext) { // has not been loaded yet - this.tabContext = this.appContext.tabManager.getActiveTabContext(); + this.tabContext = this.tabManager.getActiveTabContext(); } this.refresh(); diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.js index b4b447d62..ac452b0ad 100644 --- a/src/public/javascripts/widgets/tab_row.js +++ b/src/public/javascripts/widgets/tab_row.js @@ -490,7 +490,7 @@ export default class TabRowWidget extends BasicWidget { this.draggabillies.push(draggabilly); draggabilly.on('pointerDown', _ => { - this.appContext.tabManager.activateTab(tabEl.getAttribute('data-tab-id')); + this.tabManager.activateTab(tabEl.getAttribute('data-tab-id')); }); draggabilly.on('dragStart', _ => { @@ -585,7 +585,7 @@ export default class TabRowWidget extends BasicWidget { tabNoteSwitchedListener({tabId}) { const $tab = this.getTabById(tabId); - const {note} = this.appContext.tabManager.getTabContextById(tabId); + const {note} = this.tabManager.getTabContextById(tabId); this.updateTab($tab, note); } @@ -609,7 +609,7 @@ export default class TabRowWidget extends BasicWidget { } async entitiesReloadedListener({loadResults}) { - for (const tabContext of this.appContext.tabManager.getTabContexts()) { + for (const tabContext of this.tabManager.getTabContexts()) { if (loadResults.isNoteReloaded(tabContext.noteId)) { const $tab = this.getTabById(tabContext.tabId); @@ -619,7 +619,7 @@ export default class TabRowWidget extends BasicWidget { } treeCacheReloadedListener() { - for (const tabContext of this.appContext.tabManager.getTabContexts()) { + for (const tabContext of this.tabManager.getTabContexts()) { const $tab = this.getTabById(tabContext.tabId); this.updateTab($tab, tabContext.note);