mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix: automatically delete empty notes
This commit is contained in:
@@ -118,14 +118,21 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addNote(note) {
|
async addNote(note) {
|
||||||
if (
|
if (!note) return;
|
||||||
!note ||
|
|
||||||
(!note.title &&
|
|
||||||
(!note.content || !note.content.text || !note.content.delta))
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
let timestamp = note.dateCreated || Date.now();
|
let timestamp = note.dateCreated || Date.now();
|
||||||
note = { ...this.notes[timestamp], ...note };
|
note = { ...this.notes[timestamp], ...note };
|
||||||
|
|
||||||
|
if (
|
||||||
|
!note.title &&
|
||||||
|
!note.locked &&
|
||||||
|
(!note.content || !note.content.text || !note.content.delta) &&
|
||||||
|
this.notes[timestamp]
|
||||||
|
) {
|
||||||
|
//delete the note
|
||||||
|
await this.deleteNotes(note);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//add or update a note into the database
|
//add or update a note into the database
|
||||||
let title =
|
let title =
|
||||||
note.title ||
|
note.title ||
|
||||||
@@ -154,10 +161,12 @@ class Database {
|
|||||||
content: note.content,
|
content: note.content,
|
||||||
pinned: note.pinned || false,
|
pinned: note.pinned || false,
|
||||||
tags: note.tags || [],
|
tags: note.tags || [],
|
||||||
|
locked: note.locked || false,
|
||||||
notebook: note.notebook || {},
|
notebook: note.notebook || {},
|
||||||
colors: note.colors || [],
|
colors: note.colors || [],
|
||||||
favorite: note.favorite || false,
|
favorite: note.favorite || false,
|
||||||
headline:
|
headline:
|
||||||
|
!note.locked &&
|
||||||
note.content.text.substring(0, 150) +
|
note.content.text.substring(0, 150) +
|
||||||
(note.content.text.length > 150 ? "..." : ""),
|
(note.content.text.length > 150 ? "..." : ""),
|
||||||
length: note.content.text.length,
|
length: note.content.text.length,
|
||||||
@@ -187,7 +196,7 @@ class Database {
|
|||||||
return editItem.call(this, type, id, "favorite");
|
return editItem.call(this, type, id, "favorite");
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteNotes(notes) {
|
async deleteNotes(...notes) {
|
||||||
return await deleteItems.call(this, notes, KEYS.notes);
|
return await deleteItems.call(this, notes, KEYS.notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +373,7 @@ class Database {
|
|||||||
return getItem.call(this, id, KEYS.notebooks);
|
return getItem.call(this, id, KEYS.notebooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteNotebooks(notebooks) {
|
async deleteNotebooks(...notebooks) {
|
||||||
return await deleteItems.call(this, notebooks, KEYS.notebooks);
|
return await deleteItems.call(this, notebooks, KEYS.notebooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user