mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
feat: implement topics and move note
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
getLastWeekTimestamp
|
||||
} from "../utils/date";
|
||||
import Storage from "../database/storage";
|
||||
import Notebooks from "./notebooks";
|
||||
var tfun = require("transfun/transfun.js").tfun;
|
||||
if (!tfun) {
|
||||
tfun = global.tfun;
|
||||
@@ -21,8 +22,14 @@ export default class Notes {
|
||||
this.tagsCollection = new Tags(context);
|
||||
}
|
||||
|
||||
async init() {
|
||||
/**
|
||||
*
|
||||
* @param {Notebooks} notebooks
|
||||
*/
|
||||
async init(notebooks) {
|
||||
await this.collection.init();
|
||||
this.notebooks = notebooks;
|
||||
await this.tagsCollection.init();
|
||||
}
|
||||
|
||||
async add(noteArg) {
|
||||
@@ -203,6 +210,36 @@ export default class Notes {
|
||||
await this.collection.addItem(note);
|
||||
}
|
||||
|
||||
async move(to, ...noteIds) {
|
||||
if (!to) throw new Error("The destination notebook cannot be undefined.");
|
||||
if (!to.id || !to.topic)
|
||||
throw new Error(
|
||||
"The destination notebook must contain notebookId and topic."
|
||||
);
|
||||
let topic = this.notebooks.topics(to.id).topic(to.topic);
|
||||
if (!topic) throw new Error("No such topic exists.");
|
||||
await topic.transaction(async () => {
|
||||
for (let id of noteIds) {
|
||||
let note = this.get(id);
|
||||
if (!note) continue;
|
||||
/* if (note.notebook && note.notebook.id & note.notebook.topic) {
|
||||
if (
|
||||
note.notebook.id === notebook.id &&
|
||||
note.notebook.topic === topic.title
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
let topic = this.notebooks
|
||||
.topics(note.notebook.id)
|
||||
.topic(note.notebook.topic);
|
||||
if (!topic) continue;
|
||||
await topic.delete(id);
|
||||
} */
|
||||
await topic.add(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async favorite(id) {
|
||||
await this.add({ id, favorite: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user