diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js index 1d4089c7b..a761f5b3a 100644 --- a/src/public/javascripts/services/branches.js +++ b/src/public/javascripts/services/branches.js @@ -4,6 +4,7 @@ import server from './server.js'; import infoService from "./info.js"; import treeCache from "./tree_cache.js"; import hoistedNoteService from "./hoisted_note.js"; +import noteDetailService from "./note_detail.js"; async function moveBeforeNode(nodesToMove, beforeNode) { nodesToMove = await filterRootNote(nodesToMove); @@ -85,7 +86,11 @@ async function deleteNodes(nodes) { } for (const node of nodes) { - await server.remove('branches/' + node.data.branchId); + const {noteDeleted} = await server.remove('branches/' + node.data.branchId); + + if (noteDeleted) { + noteDetailService.noteDeleted(node.data.noteId); + } } // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 20eaa889c..5a119d799 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -267,7 +267,7 @@ async function loadNote(noteId) { async function filterTabs(noteId) { for (const tc of tabContexts) { if (tc.notePath && !tc.notePath.split("/").includes(noteId)) { - await tabRow.removeTab(tc.tab); + await tabRow.removeTab(tc.$tab[0]); } } @@ -281,6 +281,14 @@ async function filterTabs(noteId) { await saveOpenTabs(); } +async function noteDeleted(noteId) { + for (const tc of tabContexts) { + if (tc.notePath && tc.notePath.split("/").includes(noteId)) { + await tabRow.removeTab(tc.$tab[0]); + } + } +} + function focusOnTitle() { getActiveTabContext().$noteTitle.focus(); } @@ -496,5 +504,6 @@ export default { activateTabContext, clearOpenTabsTask, filterTabs, - openEmptyTab + openEmptyTab, + noteDeleted }; \ No newline at end of file diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index 9e8e6ef13..90bd0eb25 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -853,7 +853,6 @@ export default { loadTree, treeInitialized, setExpandedToServer, - getHashValueFromAddress, getNodesByNoteId, checkFolderStatus, reloadNote, diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 9bd8fefca..1c5162a47 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -102,7 +102,9 @@ async function setExpanded(req) { async function deleteBranch(req) { const branch = await repository.getBranch(req.params.branchId); - await notes.deleteNote(branch); + return { + noteDeleted: await notes.deleteNote(branch) + }; } async function setPrefix(req) { diff --git a/src/services/notes.js b/src/services/notes.js index 0518d8334..02b8ed77c 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -373,9 +373,10 @@ async function updateNote(noteId, noteUpdates) { await protectNoteRevisions(note); } +/** @return {boolean} - true if note has been deleted, false otherwise */ async function deleteNote(branch) { if (!branch || branch.isDeleted) { - return; + return false; } if (branch.branchId === 'root' @@ -418,6 +419,11 @@ async function deleteNote(branch) { link.isDeleted = true; await link.save(); } + + return true; + } + else { + return false; } }