mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: noteId not being removed from color or deleting
This commit is contained in:
@@ -111,8 +111,6 @@ describe.each([
|
||||
verifyIndex(data, db, "notebooks", "notebooks");
|
||||
verifyIndex(data, db, "delta", "content");
|
||||
verifyIndex(data, db, "content", "content");
|
||||
verifyIndex(data, db, "tags", "tags");
|
||||
verifyIndex(data, db, "colors", "colors");
|
||||
verifyIndex(data, db, "trash", "trash");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -223,8 +223,8 @@ 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;
|
||||
const itemData = qclone(item.data);
|
||||
if (item.notebooks) {
|
||||
for (let notebook of item.notebooks) {
|
||||
for (let topic of notebook.topics) {
|
||||
@@ -238,8 +238,8 @@ export default class Notes extends Collection {
|
||||
for (let tag of item.tags) {
|
||||
await this._db.tags.remove(tag, id);
|
||||
}
|
||||
if (item.color) {
|
||||
await this._db.colors.remove(item.color, id);
|
||||
if (item.data.color) {
|
||||
await this._db.colors.remove(item.data.color, id);
|
||||
}
|
||||
await this._collection.removeItem(id);
|
||||
if (moveToTrash) await this._db.trash.add(itemData);
|
||||
|
||||
@@ -10,37 +10,9 @@ export default class Tags extends Collection {
|
||||
return tagItem;
|
||||
}
|
||||
|
||||
async merge(tag) {
|
||||
if (!tag) return;
|
||||
if (tag.deleted) {
|
||||
await this._collection.addItem(tag);
|
||||
return;
|
||||
}
|
||||
const oldTag = this.all.find(
|
||||
(t) => t.id === tag.id || t.title === tag.title
|
||||
);
|
||||
|
||||
if (!oldTag) return await this._collection.addItem(tag);
|
||||
|
||||
const deletedIds = set.union(oldTag.deletedIds, tag.deletedIds);
|
||||
const noteIds = set.difference(
|
||||
set.union(oldTag.noteIds, tag.noteIds),
|
||||
deletedIds
|
||||
);
|
||||
|
||||
const dateEdited =
|
||||
tag.dateEdited > oldTag.dateEdited ? tag.dateEdited : oldTag.dateEdited;
|
||||
tag = {
|
||||
...oldTag,
|
||||
noteIds,
|
||||
dateEdited,
|
||||
deletedIds,
|
||||
};
|
||||
await this._collection.addItem(tag);
|
||||
}
|
||||
|
||||
async add(tagId, noteId) {
|
||||
if (!tagId || !noteId) return;
|
||||
if (!tagId || !noteId) new Error("tagId and noteId cannot be falsy.");
|
||||
|
||||
let tag = this.all.find((t) => t.id === tagId || t.title === tagId) || {
|
||||
title: tagId,
|
||||
};
|
||||
@@ -50,13 +22,11 @@ export default class Tags extends Collection {
|
||||
|
||||
if (notes.find((id) => id === noteId)) return id;
|
||||
|
||||
let deletedIds = tag.deletedIds || [];
|
||||
tag = {
|
||||
type: "tag",
|
||||
id,
|
||||
title: tag.title,
|
||||
noteIds: [...notes, noteId],
|
||||
deletedIds,
|
||||
};
|
||||
|
||||
await this._collection.addItem(tag);
|
||||
@@ -72,14 +42,14 @@ export default class Tags extends Collection {
|
||||
}
|
||||
|
||||
async remove(tagTitle, noteId) {
|
||||
if (!tagTitle || !noteId) return;
|
||||
if (!tagTitle || !noteId) new Error("tagTitle and noteId cannot be falsy.");
|
||||
let tag = this.all.find((t) => t.title === tagTitle);
|
||||
if (!tag) return;
|
||||
if (!tag) throw new Error(`No tag with title "${tagTitle}" found.`);
|
||||
tag = qclone(tag);
|
||||
const noteIndex = tag.noteIds.indexOf(noteId);
|
||||
if (noteIndex <= -1) return;
|
||||
if (noteIndex <= -1)
|
||||
throw new Error(`No note of id "${noteId}" exists in this tag.`);
|
||||
tag.noteIds.splice(noteIndex, 1);
|
||||
tag.deletedIds.push(noteId);
|
||||
if (tag.noteIds.length > 0) await this._collection.addItem(tag);
|
||||
else await this._collection.removeItem(tag.id);
|
||||
}
|
||||
|
||||
@@ -137,14 +137,6 @@ export default class Backup {
|
||||
index: data["notebooks"],
|
||||
dbCollection: this._db.notebooks,
|
||||
},
|
||||
{
|
||||
index: data["tags"],
|
||||
dbCollection: this._db.tags,
|
||||
},
|
||||
{
|
||||
index: data["colors"],
|
||||
dbCollection: this._db.colors,
|
||||
},
|
||||
{
|
||||
index: data["trash"],
|
||||
dbCollection: this._db.trash,
|
||||
|
||||
@@ -94,6 +94,7 @@ export default class Note {
|
||||
}
|
||||
|
||||
async uncolor() {
|
||||
if (!this._note.color) return;
|
||||
await this._db.colors.remove(this._note.color, this._note.id);
|
||||
await this._db.notes._collection.addItem({
|
||||
...this._note,
|
||||
|
||||
Reference in New Issue
Block a user