mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
core: add collection for reminders
This commit is contained in:
committed by
Abdullah Atta
parent
657fe05464
commit
a8f1fbf6a1
@@ -47,6 +47,7 @@ import EventManager from "../utils/event-manager";
|
|||||||
import Pricing from "./pricing";
|
import Pricing from "./pricing";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import Shortcuts from "../collections/shortcuts";
|
import Shortcuts from "../collections/shortcuts";
|
||||||
|
import Reminders from "../collections/reminders";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {EventSource}
|
* @type {EventSource}
|
||||||
@@ -143,6 +144,8 @@ class Database {
|
|||||||
this.noteHistory = await NoteHistory.new(this, "notehistory", false);
|
this.noteHistory = await NoteHistory.new(this, "notehistory", false);
|
||||||
/**@type {Shortcuts} */
|
/**@type {Shortcuts} */
|
||||||
this.shortcuts = await Shortcuts.new(this, "shortcuts");
|
this.shortcuts = await Shortcuts.new(this, "shortcuts");
|
||||||
|
/**@type {Reminders} */
|
||||||
|
this.reminders = await Reminders.new(this, "reminders");
|
||||||
|
|
||||||
this.trash = new Trash(this);
|
this.trash = new Trash(this);
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ class Migrations {
|
|||||||
index: () => this._db.shortcuts.raw,
|
index: () => this._db.shortcuts.raw,
|
||||||
dbCollection: this._db.shortcuts
|
dbCollection: this._db.shortcuts
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
index: () => this._db.reminders.raw,
|
||||||
|
dbCollection: this._db.reminders
|
||||||
|
},
|
||||||
{
|
{
|
||||||
index: () => this._db.noteHistory.sessionContent.all(),
|
index: () => this._db.noteHistory.sessionContent.all(),
|
||||||
dbCollection: this._db.noteHistory
|
dbCollection: this._db.noteHistory
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class Collector {
|
|||||||
notebook: this._db.notebooks.raw,
|
notebook: this._db.notebooks.raw,
|
||||||
content: await this._db.content.all(),
|
content: await this._db.content.all(),
|
||||||
attachment: this._db.attachments.syncable,
|
attachment: this._db.attachments.syncable,
|
||||||
|
reminder: this._db.reminders.raw,
|
||||||
settings: [this._db.settings.raw]
|
settings: [this._db.settings.raw]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ class Merger {
|
|||||||
get: (id) => this._db.shortcuts.shortcut(id),
|
get: (id) => this._db.shortcuts.shortcut(id),
|
||||||
set: (item) => this._db.shortcuts.merge(item)
|
set: (item) => this._db.shortcuts.merge(item)
|
||||||
},
|
},
|
||||||
|
reminder: {
|
||||||
|
get: (id) => this._db.reminders.reminder(id),
|
||||||
|
set: (item) => this._db.reminders.merge(item)
|
||||||
|
},
|
||||||
notebook: {
|
notebook: {
|
||||||
threshold: 1000,
|
threshold: 1000,
|
||||||
get: (id) => this._db.notebooks.notebook(id),
|
get: (id) => this._db.notebooks.notebook(id),
|
||||||
|
|||||||
106
packages/core/collections/reminders.js
Normal file
106
packages/core/collections/reminders.js
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
This file is part of the Notesnook project (https://notesnook.com/)
|
||||||
|
|
||||||
|
Copyright (C) 2022 Streetwriters (Private) Limited
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import getId from "../utils/id";
|
||||||
|
import Collection from "./collection";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* id: string;
|
||||||
|
* type: string;
|
||||||
|
* title: string;
|
||||||
|
* description?: string;
|
||||||
|
* priority: "silent" | "vibrate" | "urgent";
|
||||||
|
* date: number;
|
||||||
|
* mode: "repeat" | "once" | "permanent";
|
||||||
|
* recurringMode?: "week" | "month" | "day";
|
||||||
|
* selectedDays?: number[];
|
||||||
|
* dateCreated: number;
|
||||||
|
* dateModified: number;
|
||||||
|
* }} Reminder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class Reminders extends Collection {
|
||||||
|
async merge(reminder) {
|
||||||
|
if (!reminder) return;
|
||||||
|
await this._collection.addItem(reminder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {Partial<Reminder>} reminder
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async add(reminder) {
|
||||||
|
if (!reminder) return;
|
||||||
|
if (reminder.remote)
|
||||||
|
throw new Error("Please use db.reminders.merge to merge reminders.");
|
||||||
|
|
||||||
|
const id = reminder.id || getId();
|
||||||
|
let oldReminder = this._collection.getItem(id);
|
||||||
|
|
||||||
|
reminder = {
|
||||||
|
...oldReminder,
|
||||||
|
...reminder
|
||||||
|
};
|
||||||
|
|
||||||
|
reminder = {
|
||||||
|
id,
|
||||||
|
type: "reminder",
|
||||||
|
dateCreated: reminder.dateCreated,
|
||||||
|
dateModified: reminder.dateModified,
|
||||||
|
date: reminder.date,
|
||||||
|
description: reminder.description,
|
||||||
|
mode: reminder.mode || "once",
|
||||||
|
priority: reminder.priority || "vibrate",
|
||||||
|
recurringMode: reminder.recurringMode,
|
||||||
|
selectedDays: reminder.selectedDays || [],
|
||||||
|
title: reminder.title
|
||||||
|
};
|
||||||
|
|
||||||
|
await this._collection.addItem(reminder);
|
||||||
|
return reminder.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
get raw() {
|
||||||
|
return this._collection.getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Reminder[]}
|
||||||
|
*/
|
||||||
|
get all() {
|
||||||
|
return this._collection.getItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
exists(itemId) {
|
||||||
|
return !!this.shortcut(itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
reminder(id) {
|
||||||
|
return this.all.find((reminder) => reminder.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove(...reminderIds) {
|
||||||
|
for (const id of reminderIds) {
|
||||||
|
await this._collection.removeItem(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -175,6 +175,10 @@ export default class Backup {
|
|||||||
index: () => data["shortcuts"],
|
index: () => data["shortcuts"],
|
||||||
dbCollection: this._db.shortcuts
|
dbCollection: this._db.shortcuts
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
index: () => data["reminders"],
|
||||||
|
dbCollection: this._db.reminders
|
||||||
|
},
|
||||||
{
|
{
|
||||||
index: () => data["notehistory"],
|
index: () => data["notehistory"],
|
||||||
dbCollection: this._db.noteHistory,
|
dbCollection: this._db.noteHistory,
|
||||||
|
|||||||
Reference in New Issue
Block a user