diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js index bf19a284c..191866aaa 100644 --- a/src/public/app/services/entrypoints.js +++ b/src/public/app/services/entrypoints.js @@ -224,7 +224,7 @@ export default class Entrypoints extends Component { this.hideAllTooltips(); } - activeTabChangedEvent() { + activeContextChangedEvent() { this.hideAllTooltips(); } } diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 2868608c0..2c4e0c4b7 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -285,7 +285,7 @@ export default class TabManager extends Component { this.activeNtxId = ntxId; if (triggerEvent) { - this.triggerEvent('activeTabChanged', { + this.triggerEvent('activeContextChanged', { noteContext: this.getNoteContextById(ntxId) }); } diff --git a/src/public/app/widgets/containers/pane_container.js b/src/public/app/widgets/containers/pane_container.js index 168a0f025..35e800cb1 100644 --- a/src/public/app/widgets/containers/pane_container.js +++ b/src/public/app/widgets/containers/pane_container.js @@ -5,8 +5,6 @@ export default class PaneContainer extends FlexContainer { constructor(widgetFactory) { super('row'); - this.counter = 0; - this.widgetFactory = widgetFactory; this.widgets = {}; @@ -25,13 +23,13 @@ export default class PaneContainer extends FlexContainer { this.$widget.append($renderedWidget); + widget.toggleExt(false); + this.widgets[noteContext.ntxId] = widget; await widget.handleEvent('setNoteContext', { noteContext }); this.child(widget); - - this.refresh(); } async openNewPaneCommand() { @@ -42,6 +40,14 @@ export default class PaneContainer extends FlexContainer { await noteContext.setEmpty(); } + activeContextChangedEvent() { + this.refresh(); + } + + noteSwitchedAndActivatedEvent() { + this.refresh(); + } + async refresh() { this.toggleExt(true); } @@ -57,10 +63,6 @@ export default class PaneContainer extends FlexContainer { const widget = this.widgets[ntxId]; widget.toggleExt(show && activeNtxId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeNtxId)); - - if (!widget.hasBeenAlreadyShown) { - widget.handleEvent('activeTabChanged', {noteContext}); - } } } @@ -78,58 +80,42 @@ export default class PaneContainer extends FlexContainer { return Promise.resolve(); } - const promises = []; + if (widget.hasBeenAlreadyShown + || name === 'noteSwitchedAndActivated' + || appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext() + ) { + widget.hasBeenAlreadyShown = true; - if (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) { - promises.push(widget.handleEvent('activeTabChanged', data)); + return [ + widget.handleEvent('noteSwitched', data), + this.refreshNotShown(data) + ]; } - - for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) { - const subWidget = this.widgets[subNoteContext.ntxId]; - - if (!subWidget) { - continue; - } - - if (subNoteContext !== data.noteContext && !subWidget.hasBeenAlreadyShown) { - promises.push(widget.handleEvent('activeTabChanged', {noteContext: subNoteContext})); - continue; - } - - if (subNoteContext === data.noteContext && (subWidget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) { - subWidget.hasBeenAlreadyShown = true; - - promises.push(widget.handleEvent('noteSwitched', data)); - } + else { + return Promise.resolve(); } - - if (name === 'noteSwitchedAndActivated') { - this.toggleExt(true); - } - - return Promise.all(promises); } - if (name === 'activeTabChanged') { - const promises = []; - - for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) { - console.log("subNoteContext", subNoteContext); - - const widget = this.widgets[subNoteContext.ntxId]; - - if (!widget.hasBeenAlreadyShown) { - widget.hasBeenAlreadyShown = true; - - promises.push(widget.handleEvent(name, {noteContext: subNoteContext})); - } - } - - this.toggleExt(true); - - return Promise.all(promises); + if (name === 'activeContextChanged') { + return this.refreshNotShown(data); } else { return super.handleEventInChildren(name, data); } } + + refreshNotShown(data) { + const promises = []; + + for (const subContext of data.noteContext.getMainContext().getSubContexts()) { + const widget = this.widgets[subContext.ntxId]; + + if (!widget.hasBeenAlreadyShown) { + widget.hasBeenAlreadyShown = true; + + promises.push(widget.handleEvent('activeContextChanged', {noteContext: subContext})); + } + } + + return Promise.all(promises); + } } diff --git a/src/public/app/widgets/containers/root_container.js b/src/public/app/widgets/containers/root_container.js index e2c353e8a..04f2f1390 100644 --- a/src/public/app/widgets/containers/root_container.js +++ b/src/public/app/widgets/containers/root_container.js @@ -45,7 +45,7 @@ export default class RootContainer extends FlexContainer { this.refresh(); } - activeTabChangedEvent() { + activeContextChangedEvent() { this.refresh(); } diff --git a/src/public/app/widgets/note_context_aware_widget.js b/src/public/app/widgets/note_context_aware_widget.js index a11e581ac..5d9ec83b2 100644 --- a/src/public/app/widgets/note_context_aware_widget.js +++ b/src/public/app/widgets/note_context_aware_widget.js @@ -66,13 +66,13 @@ export default class NoteContextAwareWidget extends BasicWidget { await this.refresh(); } - async activeTabChangedEvent({noteContext}) { + async activeContextChangedEvent({noteContext}) { this.noteContext = noteContext; - await this.activeTabChanged(); + await this.activeContextChanged(); } - async activeTabChanged() { + async activeContextChanged() { await this.refresh(); } diff --git a/src/public/app/widgets/note_context_caching_widget.js b/src/public/app/widgets/note_context_caching_widget.js index d91a77614..e95e0fb8a 100644 --- a/src/public/app/widgets/note_context_caching_widget.js +++ b/src/public/app/widgets/note_context_caching_widget.js @@ -67,11 +67,7 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget { handleEventInChildren(name, data) { if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) { // this event is propagated only to the widgets of a particular tab - let widget = this.widgets[data.noteContext.ntxId]; - - if (!widget) { - widget = this.widgets[data.noteContext.mainNtxId]; - } + const widget = this.widgets[data.noteContext.ntxId]; if (widget && (widget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) { widget.hasBeenAlreadyShown = true; @@ -83,12 +79,8 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget { } } - if (name === 'activeTabChanged') { - let widget = this.widgets[data.noteContext.ntxId]; - - if (!widget) { - widget = this.widgets[data.noteContext.mainNtxId]; - } + if (name === 'activeContextChanged') { + const widget = this.widgets[data.noteContext.ntxId]; if (widget.hasBeenAlreadyShown) { return Promise.resolve(); diff --git a/src/public/app/widgets/tab_row.js b/src/public/app/widgets/tab_row.js index 6fd35c1f5..7a6ad4ed9 100644 --- a/src/public/app/widgets/tab_row.js +++ b/src/public/app/widgets/tab_row.js @@ -426,7 +426,7 @@ export default class TabRowWidget extends BasicWidget { return this.$widget.find('.note-tab[active]')[0]; } - activeTabChangedEvent() { + activeContextChangedEvent() { let activeNoteContext = appContext.tabManager.getActiveContext(); if (!activeNoteContext) { @@ -612,7 +612,7 @@ export default class TabRowWidget extends BasicWidget { }; noteSwitchedAndActivatedEvent({noteContext}) { - this.activeTabChangedEvent(); + this.activeContextChangedEvent(); this.updateTabById(noteContext.mainNtxId || noteContext.ntxId); }