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