Skip to content

Build your personal knowledge base with Trilium Notes

refactored TabContext => NoteContext

zadam5b220adc31e6
diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js
index bf19a284cd..191866aaae 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 2868608c08..2c4e0c4b72 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 168a0f025c..35e800cb17 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 (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) {
- promises.push(widget.handleEvent('activeTabChanged', data));
- }
-
- for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
- const subWidget = this.widgets[subNoteContext.ntxId];
+ if (widget.hasBeenAlreadyShown
+ || name === 'noteSwitchedAndActivated'
+ || appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()
+ ) {
+ widget.hasBeenAlreadyShown = true;
- 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));
- }
+ return [
+ widget.handleEvent('noteSwitched', data),
+ this.refreshNotShown(data)
+ ];
}
-
- if (name === 'noteSwitchedAndActivated') {
- this.toggleExt(true);
+ else {
+ return Promise.resolve();
}
-
- return Promise.all(promises);
}
- if (name === 'activeTabChanged') {
- const promises = [];
+ if (name === 'activeContextChanged') {
+ return this.refreshNotShown(data);
+ } else {
+ return super.handleEventInChildren(name, data);
+ }
+ }
- for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
- console.log("subNoteContext", subNoteContext);
+ refreshNotShown(data) {
+ const promises = [];
- const widget = this.widgets[subNoteContext.ntxId];
+ for (const subContext of data.noteContext.getMainContext().getSubContexts()) {
+ const widget = this.widgets[subContext.ntxId];
- if (!widget.hasBeenAlreadyShown) {
- widget.hasBeenAlreadyShown = true;
+ if (!widget.hasBeenAlreadyShown) {
+ widget.hasBeenAlreadyShown = true;
- promises.push(widget.handleEvent(name, {noteContext: subNoteContext}));
- }
+ promises.push(widget.handleEvent('activeContextChanged', {noteContext: subContext}));
}
-
- this.toggleExt(true);
-
- return Promise.all(promises);
- } else {
- return super.handleEventInChildren(name, data);
}
+
+ 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 e2c353e8a4..04f2f13909 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 a11e581ace..5d9ec83b2a 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 d91a776145..e95e0fb8ad 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 6fd35c1f52..7a6ad4ed90 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);
}