diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 3565ecbb8..ef1316675 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -13,7 +13,7 @@ class AppContext { constructor(layout) { this.layout = layout; this.tabManager = new TabManager(this); - this.components = [this.tabManager]; + this.components = []; } async start() { @@ -32,6 +32,7 @@ class AppContext { $("body").append(rootContainer.render()); this.components = [ + this.tabManager, rootContainer, new Entrypoints(this), new DialogEventComponent(this) @@ -112,7 +113,7 @@ $(window).on('hashchange', function() { if (isNotePathInAddress()) { const [notePath, tabId] = getHashValueFromAddress(); - appContext.switchToTab(tabId, notePath); + appContext.tabManager.switchToTab(tabId, notePath); } }); diff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.js index c7c1299bf..7adf1a66e 100644 --- a/src/public/javascripts/services/link_map.js +++ b/src/public/javascripts/services/link_map.js @@ -176,7 +176,7 @@ export default class LinkMap { .addClass('link-' + edge.target.id); } else { - console.debug(`connection not created for`, edge); + //console.debug(`connection not created for`, edge); } }); diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 3eced57d2..5a8ef60b5 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -20,7 +20,7 @@ class TabContext extends Component { this.tabId = state.tabId || utils.randomString(4); this.state = state; - this.trigger('tabOpened', {tabId: this.tabId}); + this.trigger('newTabOpened', {tabId: this.tabId}); } async setNote(inputNotePath) { diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js index 05819f8c2..2f38e07a8 100644 --- a/src/public/javascripts/services/tab_manager.js +++ b/src/public/javascripts/services/tab_manager.js @@ -201,10 +201,6 @@ export default class TabManager extends Component { this.trigger('activeTabChanged', { oldActiveTabId, newActiveTabId: tabId }); } - newTabListener() { - this.openAndActivateEmptyTab(); - } - async removeTab(tabId) { const tabContextToRemove = this.tabContexts.find(tc => tc.tabId === tabId); @@ -258,6 +254,10 @@ export default class TabManager extends Component { this.removeTab(this.activeTabId); } + beforeUnloadListener() { + this.tabsUpdate.updateNowIfNecessary(); + } + openNewTabListener() { this.openAndActivateEmptyTab(); } diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index ea796842e..798e62fd1 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -1,7 +1,6 @@ import TabAwareWidget from "./tab_aware_widget.js"; import utils from "../services/utils.js"; import protectedSessionHolder from "../services/protected_session_holder.js"; -import treeCache from "../services/tree_cache.js"; import server from "../services/server.js"; import SpacedUpdate from "../services/spaced_update.js"; @@ -40,7 +39,7 @@ export default class NoteTitleWidget extends TabAwareWidget { this.$widget = $(TPL); this.$noteTitle = this.$widget.find(".note-title"); - this.$noteTitle.on('input', () => this.titleChanged()); + this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate()); utils.bindElShortcut(this.$noteTitle, 'return', () => { this.trigger('focusOnDetail', {tabId: this.tabContext.tabId}); @@ -49,27 +48,6 @@ export default class NoteTitleWidget extends TabAwareWidget { return this.$widget; } - async titleChanged() { - const {note} = this.tabContext; - - if (!note) { - return; - } - - note.title = this.$noteTitle.val(); - - this.spacedUpdate.scheduleUpdate(); - - const noteFromCache = await treeCache.getNote(note.noteId); - noteFromCache.title = note.title; - - this.trigger(`noteTitleChanged`, { - tabId: this.tabContext.tabId, // used to identify that the event comes from this tab so we should not update this tab's input - title: note.title, - noteId: note.noteId - }); - } - async refreshWithNote(note) { this.$noteTitle.val(note.title); diff --git a/src/public/javascripts/widgets/protected_note_switch.js b/src/public/javascripts/widgets/protected_note_switch.js index 72e724b62..8fd7d7d6f 100644 --- a/src/public/javascripts/widgets/protected_note_switch.js +++ b/src/public/javascripts/widgets/protected_note_switch.js @@ -1,6 +1,7 @@ import BasicWidget from "./basic_widget.js"; import protectedSessionService from "../services/protected_session.js"; import protectedSessionHolder from "../services/protected_session_holder.js"; +import TabAwareWidget from "./tab_aware_widget.js"; const TPL = `
@@ -15,7 +16,7 @@ const TPL = `
`; -export default class ProtectedNoteSwitchWidget extends BasicWidget { +export default class ProtectedNoteSwitchWidget extends TabAwareWidget { doRender() { this.$widget = $(TPL); diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js index 62c14fac9..a8f6c9837 100644 --- a/src/public/javascripts/widgets/tab_caching_widget.js +++ b/src/public/javascripts/widgets/tab_caching_widget.js @@ -8,6 +8,10 @@ export default class TabCachingWidget extends TabAwareWidget { this.widgets = {}; } + async isEnabled() { + return this.tabContext.isActive(); + } + doRender() { this.$widget = $(`