mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
feat: add pinItem function
This commit is contained in:
@@ -12,7 +12,8 @@ import {
|
||||
const KEYS = {
|
||||
notes: "notes",
|
||||
notebooks: "notebooks",
|
||||
trash: "trash"
|
||||
trash: "trash",
|
||||
tags: "tags"
|
||||
};
|
||||
|
||||
function checkInitialized() {
|
||||
@@ -37,7 +38,7 @@ class Database {
|
||||
for (let key of extractValues(KEYS)) {
|
||||
this.storage.read(key).then(data => {
|
||||
this[key] = data || {};
|
||||
if (key === "notebooks") {
|
||||
if (key === KEYS.tags) {
|
||||
this.isInitialized = true;
|
||||
//TODO use index here
|
||||
resolve(true);
|
||||
@@ -150,6 +151,22 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes one or more notes
|
||||
* @param {array} notes the notes to be deleted
|
||||
|
||||
Reference in New Issue
Block a user