mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: add favoriteItem function
This commit is contained in:
@@ -151,20 +151,12 @@ class Database {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
async pinItem(type, id) {
|
||||
switch (type) {
|
||||
case "notebook":
|
||||
case "note":
|
||||
col = type == "note" ? this.notes : this.notebooks;
|
||||
func = type == "note" ? this.addNote : this.addNotebook;
|
||||
if (col[id] === undefined) {
|
||||
throw new Error(`Wrong ${type} id.`);
|
||||
}
|
||||
await func({ ...col[id], pinned: true });
|
||||
break;
|
||||
default:
|
||||
throw new Error("Invalid type given to pinItem");
|
||||
}
|
||||
pinItem(type, id) {
|
||||
return editItem.call(this, type, id, { pinned: true });
|
||||
}
|
||||
|
||||
favoriteItem(type, id) {
|
||||
return editItem.call(this, type, id, { favorite: true });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,3 +487,19 @@ function makeTopic(topic) {
|
||||
notes: []
|
||||
};
|
||||
}
|
||||
|
||||
async function editItem(type, id, edit) {
|
||||
switch (type) {
|
||||
case "notebook":
|
||||
case "note":
|
||||
col = type == "note" ? this.notes : this.notebooks;
|
||||
func = type == "note" ? this.addNote : this.addNotebook;
|
||||
if (col[id] === undefined) {
|
||||
throw new Error(`Wrong ${type} id.`);
|
||||
}
|
||||
await func({ ...col[id], ...edit });
|
||||
break;
|
||||
default:
|
||||
throw new Error("Invalid type given to pinItem");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user