A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: delete and restore note.notebooks
thecodrr68f9f8116f65
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.jsindex bdfa4533a..25336cb2f 100644--- a/packages/core/collections/notes.js+++ b/packages/core/collections/notes.js@@ -10,6 +10,7 @@ import Note from "../models/note";import getId from "../utils/id";import { EV } from "../common";import { getContentFromData } from "../content-types";+import qclone from "qclone/src/qclone";var tfun = require("transfun/transfun.js").tfun;if (!tfun) {tfun = global.tfun;@@ -200,12 +201,17 @@ export default class Notes extends Collection {async _delete(moveToTrash = true, ...ids) {for (let id of ids) {let item = this.note(id);+ const itemData = qclone(item.data);if (!item) continue;- if (item.notebook && item.notebook.id && item.notebook.topic) {- await this._db.notebooks- .notebook(item.notebook.id)- .topics.topic(item.notebook.topic)- .delete(id);+ if (item.notebooks) {+ for (let notebook of item.notebooks) {+ for (let topic of notebook.topics) {+ await this._db.notebooks+ .notebook(notebook.id)+ .topics.topic(topic)+ .delete(id);+ }+ }}for (let tag of item.tags) {await this._db.tags.remove(tag, id);@@ -214,7 +220,7 @@ export default class Notes extends Collection {await this._db.colors.remove(item.color, id);}await this._collection.removeItem(id);- if (moveToTrash) await this._db.trash.add(item.data);+ if (moveToTrash) await this._db.trash.add(itemData);}}diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.jsindex 38033dcf7..5848deb00 100644--- a/packages/core/collections/trash.js+++ b/packages/core/collections/trash.js@@ -62,27 +62,29 @@ export default class Trash extends Collection {delete item.itemType;delete item.itemId;if (item.type === "note") {- let { notebook } = item;- item.notebook = undefined;+ let { notebooks } = item;+ item.notebooks = undefined;await this._db.notes.add(item);- if (notebook && notebook.id && notebook.topic) {- const { id, topic } = notebook;+ if (notebooks) {+ for (let nb of notebooks) {+ const { id, topics } = nb;+ for (let topic of topics) {+ // if the notebook or topic has been deleted+ if (+ !this._db.notebooks._collection.exists(id) ||+ !this._db.notebooks.notebook(id).topics.has(topic)+ ) {+ notebooks = undefined;+ continue;+ }- // if the notebook or topic has been deleted- if (- !this._db.notebooks._collection.exists(id) ||- !this._db.notebooks.notebook(id).topics.has(topic)- ) {- notebook = undefined;- }-- // restore the note to the topic it was in before deletion- if (notebook && notebook.id && notebook.topic) {- await this._db.notebooks- .notebook(id)- .topics.topic(topic)- .add(item.id);+ // restore the note to the topic it was in before deletion+ await this._db.notebooks+ .notebook(id)+ .topics.topic(topic)+ .add(item.id);+ }}}} else if (item.type === "notebook") {