From 7767edd82fb2acc5b5b0cad845268c8705b00463 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 9 Feb 2020 22:31:52 +0100 Subject: [PATCH] fixes --- .../javascripts/services/app_context.js | 9 ++++++++- src/public/javascripts/services/branches.js | 4 ---- .../javascripts/services/tab_context.js | 20 +++++++++++-------- src/public/javascripts/services/tree.js | 2 +- src/public/javascripts/services/ws.js | 6 +++--- .../javascripts/widgets/basic_widget.js | 6 ------ src/public/javascripts/widgets/note_tree.js | 2 +- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index 94abda6a0..71f092beb 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -29,8 +29,15 @@ class AppContext { showWidgets() { const rootContainer = this.layout.getRootWidget(this); + const $renderedWidget = rootContainer.render(); - $("body").append(rootContainer.render()); + $("body").append($renderedWidget); + + $renderedWidget.on('click', "[data-trigger-event]", e => { + const eventName = $(e.target).attr('data-trigger-event'); + + this.trigger(eventName); + }); this.components = [ this.tabManager, diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js index 9f9a79c58..1e54e797a 100644 --- a/src/public/javascripts/services/branches.js +++ b/src/public/javascripts/services/branches.js @@ -1,11 +1,9 @@ -import treeService from './tree.js'; import utils from './utils.js'; import server from './server.js'; import toastService from "./toast.js"; import treeCache from "./tree_cache.js"; import hoistedNoteService from "./hoisted_note.js"; import ws from "./ws.js"; -import appContext from "./app_context.js"; async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { branchIdsToMove = await filterRootNote(branchIdsToMove); @@ -121,8 +119,6 @@ async function deleteNodes(branchIdsToDelete) { } } - const noteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId))); - return true; } diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index ee9169283..e755c5d5c 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -100,15 +100,19 @@ class TabContext extends Component { } } - noteDeletedListener({noteId}) { - if (this.noteId === noteId) { - this.noteId = null; - this.notePath = null; + async entitiesReloadedListener({loadResults}) { + if (loadResults.isNoteReloaded(this.noteId)) { + const note = await treeCache.getNote(this.noteId); - this.trigger('tabNoteSwitched', { - tabId: this.tabId, - notePath: this.notePath - }); + if (note.isDeleted) { + this.noteId = null; + this.notePath = null; + + this.trigger('tabNoteSwitched', { + tabId: this.tabId, + notePath: this.notePath + }); + } } } } diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 2df5d74bd..29f3b2e8c 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -86,7 +86,7 @@ async function getRunPath(notePath) { break; } else { - ws.logError("No parents, can't activate node."); + console.log("No parents so no run path."); return; } } diff --git a/src/public/javascripts/services/ws.js b/src/public/javascripts/services/ws.js index 714c9eaa1..3ac74abc9 100644 --- a/src/public/javascripts/services/ws.js +++ b/src/public/javascripts/services/ws.js @@ -218,6 +218,9 @@ async function processSyncRows(syncRows) { const parentNote = treeCache.notes[sync.entity.parentNoteId]; if (branch) { + branch.update(sync.entity); + loadResults.addBranch(sync.entityId, sync.sourceId); + if (sync.entity.isDeleted) { if (childNote) { childNote.parents = childNote.parents.filter(parentNoteId => parentNoteId !== sync.entity.parentNoteId); @@ -230,9 +233,6 @@ async function processSyncRows(syncRows) { } } else { - branch.update(sync.entity); - loadResults.addBranch(sync.entityId, sync.sourceId); - if (childNote) { childNote.addParent(branch.parentNoteId, branch.branchId); } diff --git a/src/public/javascripts/widgets/basic_widget.js b/src/public/javascripts/widgets/basic_widget.js index 006fc6a73..d694157f3 100644 --- a/src/public/javascripts/widgets/basic_widget.js +++ b/src/public/javascripts/widgets/basic_widget.js @@ -7,12 +7,6 @@ class BasicWidget extends Component { keyboardActionsService.updateDisplayedShortcuts($widget); - $widget.find("[data-trigger-event]").on('click', e => { - const eventName = $(e.target).attr('data-trigger-event'); - - this.appContext.trigger(eventName); - }); - this.toggle(this.isEnabled()); return $widget; diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index 23f272864..787b1464d 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -473,7 +473,7 @@ export default class NoteTreeWidget extends TabAwareWidget { this.tabManager.getActiveTabContext().setNote(notePath); } - node.remove(); + noteIdsToReload.add(branch.parentNoteId); } else { noteIdsToUpdate.add(branch.noteId);