Skip to content

Build your personal knowledge base with Trilium Notes

fixes to delete notifications

zadam82bbf4173b56
diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js
index 72bc6091a5..7e07c1fec9 100644
--- a/src/public/javascripts/services/branches.js
+++ b/src/public/javascripts/services/branches.js
@@ -108,14 +108,21 @@ async function deleteNodes(nodes) {
const taskId = utils.randomString(10);
+ let counter = 0;
+
for (const node of nodes) {
+ counter++;
+
+ const last = counter === nodes.length;
+ const query = `?taskId=${taskId}&last=${last ? 'true' : 'false'}`;
+
if (deleteClones) {
- await server.remove('notes/' + node.data.noteId + '?taskId=' + taskId);
+ await server.remove(`notes/${node.data.noteId}` + query);
noteDetailService.noteDeleted(node.data.noteId);
}
else {
- const {noteDeleted} = await server.remove('branches/' + node.data.branchId + '?taskId=' + taskId);
+ const {noteDeleted} = await server.remove(`branches/${node.data.branchId}` + query);
if (noteDeleted) {
noteDetailService.noteDeleted(node.data.noteId);
@@ -167,8 +174,6 @@ async function deleteNodes(nodes) {
node.setFocus(true);
}
- infoService.showMessage("Note(s) has been deleted.");
-
return true;
}
diff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.js
index a67dd08f20..7c3c907839 100644
--- a/src/public/javascripts/services/import.js
+++ b/src/public/javascripts/services/import.js
@@ -65,8 +65,8 @@ ws.subscribeToMessages(async message => {
await treeService.reloadNote(message.parentNoteId);
- if (message.importedNoteId) {
- const node = await treeService.activateNote(message.importedNoteId);
+ if (message.result.importedNoteId) {
+ const node = await treeService.activateNote(message.result.importedNoteId);
node.setExpanded(true);
}
diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js
index 43079bd383..971b6aaff3 100644
--- a/src/public/javascripts/services/tree.js
+++ b/src/public/javascripts/services/tree.js
@@ -98,7 +98,14 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
const hoistedNoteId = await hoistedNoteService.getHoistedNoteId();
let parentNode = null;
- for (const childNoteId of await getRunPath(notePath)) {
+ const runPath = await getRunPath(notePath);
+
+ if (!runPath) {
+ console.error("Could not find run path for notePath:", notePath);
+ return;
+ }
+
+ for (const childNoteId of runPath) {
if (childNoteId === hoistedNoteId) {
// there must be exactly one node with given hoistedNoteId
parentNode = getNodesByNoteId(childNoteId)[0];
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index 7dba739920..9b1a9c3160 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -864,4 +864,14 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href
width: 100%;
top: 20px;
z-index: 10000;
+}
+
+.toast {
+ background-color: var(--accented-background-color) !important;
+ color: var(--main-text-color) !important;
+}
+
+.toast-header {
+ background-color: var(--more-accented-background-color) !important;
+ color: var(--main-text-color) !important;
}
\ No newline at end of file
diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js
index 6160f65858..2c638f1e95 100644
--- a/src/routes/api/branches.js
+++ b/src/routes/api/branches.js
@@ -101,11 +101,18 @@ async function setExpanded(req) {
}
async function deleteBranch(req) {
+ const last = req.query.last === 'true';
const branch = await repository.getBranch(req.params.branchId);
const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes');
+ const noteDeleted = await notes.deleteBranch(branch, taskContext);
+
+ if (last) {
+ taskContext.taskSucceeded();
+ }
+
return {
- noteDeleted: await notes.deleteBranch(branch, taskContext)
+ noteDeleted: noteDeleted
};
}
diff --git a/src/routes/api/import.js b/src/routes/api/import.js
index 65b4e0a7ec..81833bf176 100644
--- a/src/routes/api/import.js
+++ b/src/routes/api/import.js
@@ -67,7 +67,10 @@ async function importToBranch(req) {
if (last === "true") {
// small timeout to avoid race condition (message is received before the transaction is committed)
- setTimeout(() => taskContext.taskSucceeded(parentNoteId, note.noteId), 1000);
+ setTimeout(() => taskContext.taskSucceeded({
+ parentNoteId: parentNoteId,
+ importedNoteId: note.noteId
+ }), 1000);
}
// import has deactivated note events so note cache is not updated
diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js
index 1d1c6632c9..6a2f7862ba 100644
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@ -75,14 +75,20 @@ async function updateNote(req) {
async function deleteNote(req) {
const noteId = req.params.noteId;
+ const taskId = req.query.taskId;
+ const last = req.query.last === 'true';
const note = await repository.getNote(noteId);
- const taskContext = TaskContext.getInstance(req.query.taskId, 'delete-notes');
+ const taskContext = TaskContext.getInstance(taskId, 'delete-notes');
for (const branch of await note.getBranches()) {
await noteService.deleteBranch(branch, taskContext);
}
+
+ if (last) {
+ await taskContext.taskSucceeded();
+ }
}
async function sortNotes(req) {
diff --git a/src/services/task_context.js b/src/services/task_context.js
index 2b7f1dbb0d..018f9f5aa8 100644
--- a/src/services/task_context.js
+++ b/src/services/task_context.js
@@ -40,7 +40,6 @@ class TaskContext {
}
}
- // must remaing non-static
async reportError(message) {
await ws.sendMessageToAllClients({
type: 'task-error',
@@ -50,14 +49,12 @@ class TaskContext {
});
}
- // must remaing non-static
- async taskSucceeded(parentNoteId, importedNoteId) {
+ async taskSucceeded(result) {
await ws.sendMessageToAllClients({
type: 'task-succeeded',
taskId: this.taskId,
taskType: this.taskType,
- parentNoteId: parentNoteId,
- importedNoteId: importedNoteId
+ result: result
});
}
}