Skip to content

Build your personal knowledge base with Trilium Notes

more refactoring ...

zadam17e2627a345d
diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js
index ce659ee40a..6b7724df14 100644
--- a/src/public/javascripts/services/app_context.js
+++ b/src/public/javascripts/services/app_context.js
@@ -8,6 +8,7 @@ import TabContext from "./tab_context.js";
import server from "./server.js";
import keyboardActionService from "./keyboard_actions.js";
import TabRowWidget from "./tab_row.js";
+import NoteTitleWidget from "../widgets/note_title.js";
class AppContext {
constructor() {
@@ -27,6 +28,9 @@ class AppContext {
$("#global-menu-wrapper").after(contents);
+ this.noteTitleWidget = new NoteTitleWidget(this);
+ $("#center-pane").prepend(this.noteTitleWidget.render());
+
this.noteTreeWidget = new NoteTreeWidget(this);
this.widgets = [
@@ -41,14 +45,26 @@ class AppContext {
$leftPane.append($widget);
}
+
+ this.widgets.push(this.noteTitleWidget);
}
trigger(name, data) {
+ this.eventReceived(name, data);
+
for (const widget of this.widgets) {
widget.eventReceived(name, data);
}
}
+ eventReceived(name, data) {
+ const fun = this[name + 'Listener'];
+
+ if (typeof fun === 'function') {
+ fun.call(this, data);
+ }
+ }
+
/** @return {TabContext[]} */
getTabContexts() {
return this.tabContexts;
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index ad28fe30a0..ffef9b76ed 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -118,7 +118,7 @@ async function loadNoteDetail(origNotePath, options = {}) {
const loadPromise = loadNoteDetailToContext(ctx, loadedNote, notePath).then(() => {
if (activate) {
- appContext.activateTab(ctx);
+ return appContext.activateTab(ctx);
}
else {
return Promise.resolve();
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 8cee17575a..20ae3fc8c1 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -138,6 +138,8 @@ class TabContext {
// after loading new note make sure editor is scrolled to the top
this.getComponent().scrollToTop();
+
+ appContext.trigger('activeNoteChanged');
}
async show() {
@@ -175,9 +177,6 @@ class TabContext {
this.$noteDetailComponents.hide();
- this.$noteTitle.show(); // this can be hidden by empty detail
- this.$noteTitle.removeAttr("readonly"); // this can be set by protected session service
-
this.getComponent().show();
await this.getComponent().render();
}
diff --git a/src/public/javascripts/services/tab_row.js b/src/public/javascripts/services/tab_row.js
index 06793970d8..5d6d7ab6e2 100644
--- a/src/public/javascripts/services/tab_row.js
+++ b/src/public/javascripts/services/tab_row.js
@@ -380,8 +380,6 @@ export default class TabRowWidget extends BasicWidget {
}
addTab(tabId) {
- console.log("Adding tab", tabId);
-
const div = document.createElement('div');
div.innerHTML = TAB_TPL;
const tabEl = div.firstElementChild;
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index 0ddcd1cd08..41cf1658cb 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -271,8 +271,6 @@ async function treeInitialized() {
filteredTabs[0].active = true;
}
- console.log("filteredTabs", filteredTabs);
-
for (const tab of filteredTabs) {
await noteDetailService.loadNoteDetail(tab.notePath, {
state: tab,
diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js
index 251210a3a2..8d8fb8d716 100644
--- a/src/public/javascripts/widgets/note_title.js
+++ b/src/public/javascripts/widgets/note_title.js
@@ -101,18 +101,18 @@ export default class NoteTitleWidget extends TabAwareWidget {
doRender() {
const $widget = $(TPL);
- this.$noteTitle = this.$tabContent.find(".note-title");
- this.$noteTitleRow = this.$tabContent.find(".note-title-row");
- this.$notePathList = this.$tabContent.find(".note-path-list");
- this.$notePathCount = this.$tabContent.find(".note-path-count");
+ this.$noteTitle = $widget.find(".note-title");
+ this.$noteTitleRow = $widget.find(".note-title-row");
+ this.$notePathList = $widget.find(".note-path-list");
+ this.$notePathCount = $widget.find(".note-path-count");
- this.$protectButton = this.$tabContent.find(".protect-button");
+ this.$protectButton = $widget.find(".protect-button");
this.$protectButton.on('click', protectedSessionService.protectNoteAndSendToServer);
- this.$unprotectButton = this.$tabContent.find(".unprotect-button");
+ this.$unprotectButton = $widget.find(".unprotect-button");
this.$unprotectButton.on('click', protectedSessionService.unprotectNoteAndSendToServer);
- this.$savedIndicator = this.$tabContent.find(".saved-indicator");
+ this.$savedIndicator = $widget.find(".saved-indicator");
this.noteType = new NoteTypeWidget(this);
@@ -147,7 +147,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
async activeTabChanged() {
const note = this.tabContext.note;
- this.$noteTitle.val(this.note.title);
+ this.$noteTitle.val(note.title);
this.$protectButton.toggleClass("active", note.isProtected);
this.$protectButton.prop("disabled", note.isProtected);