From 6295a1825d8f4bb6acf097bebc26475a19d4ef1c Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 18 Mar 2020 10:08:16 +0100 Subject: [PATCH] fixes in setting/opening tabs --- src/public/javascripts/services/entrypoints.js | 10 +++++----- src/public/javascripts/services/tab_context.js | 2 +- src/public/javascripts/services/tab_manager.js | 4 ++-- src/public/javascripts/services/ws.js | 4 ++-- src/public/javascripts/widgets/note_detail.js | 4 ++-- src/public/javascripts/widgets/note_title.js | 4 ++-- src/public/javascripts/widgets/note_tree.js | 4 +++- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index ba6605a6a..2f74de641 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -66,16 +66,16 @@ export default class Entrypoints extends Component { async createNoteIntoDayNoteCommand() { const todayNote = await dateNoteService.getTodayNote(); - const {note} = await noteCreateService.createNote(todayNote.noteId, { - isProtected: todayNote.isProtected, - type: 'text', + const {note} = await server.post(`notes/${todayNote.noteId}/children?target=into`, { title: 'new note', - content: '' + content: '', + type: 'text', + isProtected: todayNote.isProtected }); await ws.waitForMaxKnownSyncId(); - await appContext.tabManager.openTabWithNote(note.noteId, false); + await appContext.tabManager.openTabWithNote(note.noteId, true); appContext.triggerEvent('focusAndSelectTitle'); } diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 297459721..602a0fc7e 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -40,7 +40,7 @@ class TabContext extends Component { return; // note is outside of hoisted subtree and user chose not to unhoist } - await this.triggerEvent('beforeNoteSwitch', {tabId: this.tabId}); + await this.triggerEvent('beforeNoteSwitch', {tabContext: this}); utils.closeActiveDialog(); diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js index 683f64d93..c2931bc92 100644 --- a/src/public/javascripts/services/tab_manager.js +++ b/src/public/javascripts/services/tab_manager.js @@ -196,7 +196,7 @@ export default class TabManager extends Component { this.triggerEvent('tabNoteSwitchedAndActivated', { tabContext, - notePath + notePath: tabContext.notePath // resolved note path }); } } @@ -211,7 +211,7 @@ export default class TabManager extends Component { // if no tab with this note has been found we'll create new tab - await this.openTabWithNote(noteId); + await this.openTabWithNote(noteId, true); } activateTab(tabId, triggerEvent = true) { diff --git a/src/public/javascripts/services/ws.js b/src/public/javascripts/services/ws.js index 5dc771427..321220c75 100644 --- a/src/public/javascripts/services/ws.js +++ b/src/public/javascripts/services/ws.js @@ -90,7 +90,7 @@ function waitForSyncId(desiredSyncId) { return Promise.resolve(); } - console.log("Waiting for", desiredSyncId, 'current is', lastProcessedSyncId); + console.debug("Waiting for", desiredSyncId, 'current is', lastProcessedSyncId); return new Promise((res, rej) => { syncIdReachedListeners.push({ @@ -335,7 +335,7 @@ async function processSyncRows(syncRows) { if (!loadResults.isEmpty()) { const appContext = (await import("./app_context.js")).default; - appContext.triggerEvent('entitiesReloaded', {loadResults}); + await appContext.triggerEvent('entitiesReloaded', {loadResults}); } } diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index 18515aff4..031970573 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -188,8 +188,8 @@ export default class NoteDetailWidget extends TabAwareWidget { } } - async beforeNoteSwitchEvent({tabId}) { - if (this.isTab(tabId)) { + async beforeNoteSwitchEvent({tabContext}) { + if (this.isTab(tabContext.tabId)) { await this.spacedUpdate.updateNowIfNecessary(); } } diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index 305a3b672..074d01ca2 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -52,8 +52,8 @@ export default class NoteTitleWidget extends TabAwareWidget { this.$noteTitle.prop("readonly", note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()); } - async beforeNoteSwitchEvent({tabId}) { - if (this.isTab(tabId)) { + async beforeNoteSwitchEvent({tabContext}) { + if (this.isTab(tabContext.tabId)) { await this.spacedUpdate.updateNowIfNecessary(); } } diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 161633d8f..69a7ca581 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -554,7 +554,9 @@ export default class NoteTreeWidget extends TabAwareWidget { } if (activeNotePath) { - appContext.tabManager.getActiveTabContext().setNote(activeNotePath); + const node = await this.expandToNote(activeNotePath); + + node.setActive(true, {noEvents: true}); } }