Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: add reminders view

Abdullah Attade9566dc7528
diff --git a/apps/web/src/assets/reminder.svg b/apps/web/src/assets/reminder.svg
new file mode 100644
index 000000000..c68b6cc8a
--- /dev/null
+++ b/apps/web/src/assets/reminder.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" data-name="Layer 1" viewBox="0 0 790 512.21"><path fill="#e6e6e6" d="M720.56 510.7 698 442.6s24.82 24.82 24.82 45.18l-4.46-47.09s12.73 17.18 11.46 43.28-9.26 26.72-9.26 26.72ZM236.02 448.7 214 382.23s24.22 24.22 24.22 44.1l-4.35-45.96s12.43 16.76 11.18 42.23-9.03 26.08-9.03 26.08Z"/><path fill="#e6e6e6" d="M579.73 479.36c.03 43.71-86.67 30.27-192.81 30.36s-191.54 13.69-191.58-30.03 86.64-53.3 192.78-53.39 191.57 9.34 191.6 53.06Z"/><path fill="#3f3d56" d="M0 509.69h790v2H0z"/><path fill="#a0616a" d="M505.34 420.32h-13.88l-6.6-53.52h20.48v53.52z"/><path fill="#2f2e41" d="M480 416.36h28.31v16.85H464.7v-1.54a15.3 15.3 0 0 1 15.3-15.31Z"/><path fill="#a0616a" d="M607.34 499.32h-13.88l-6.6-53.52h20.48v53.52z"/><path fill="#2f2e41" d="M582 495.36h28.31v16.85H566.7v-1.54a15.3 15.3 0 0 1 15.3-15.31Z"/><path fill="#a0616a" d="M671.34 340.3a10.32 10.32 0 0 0-2.9-15.54l-32.22-131.3-20.6 8.87 38.33 126.95a10.37 10.37 0 0 0 17.4 11.03ZM646.2 74.96a11.38 11.38 0 0 0-17.4 1.16l-49.9 5.72 7.6 19.24 45.36-8.49a11.44 11.44 0 0 0 14.35-17.63Z"/><path fill="#2f2e41" d="m564 326.7 21.77 163.37 27.1-5.58s-4-118.98 9.55-133.33S605 311.7 605 311.7Z"/><path fill="#2f2e41" d="m573 281.7-10 15s-77-32-77 19-4.4 85.6-6 88 18.44 8.59 28 7c0 0 11.8-82.23 11-87 0 0 75.53 37.03 89.88 33.84s17.73-14.47 20.12-20.85-1-57-1-57l-47.81-14.59Z"/><path fill="#ccc" d="m574.35 191.63-2.85-3.42s-31.92-71.83-19.38-91.2 67.26-22.24 68.97-21.1-4.08 15.94-.09 22.78c0 0-42.4 9.2-45.24 10.33s21.96 43.28 21.96 43.28l-2.85 25.65Z"/><path fill="#ccc" d="M630.22 156.29s-29.65 3.42-30.79 3.42-1.7-7.41-1.7-7.41L571.5 188.2s-12.92 104.2-9.5 102.48 66.5 8.11 67.08 3.55-.57-27.36 1.14-28.5 29.64-71.83 29.64-71.83-2.85-14.82-12.54-19.95-17.1-17.67-17.1-17.67Z"/><path fill="#ccc" d="m650.74 184.22 9.12 9.7S673.4 305.26 666 308.68s-22 3-22 3l-14.35-52.79Z"/><circle cx="601.73" cy="123" r="26.24" fill="#a0616a"/><path fill="#2f2e41" d="M595.57 127.1c-.35-5.45-7.22-5.64-12.68-5.7s-11.97.15-15.06-4.35c-2.04-2.97-1.65-7.1.03-10.28s4.46-5.64 7.19-8c7.04-6.09 14.3-12.13 22.75-16.03s18.36-5.47 27.13-2.34c10.77 3.84 25.33 23.62 26.59 34.99s-3.29 22.95-10.95 31.45-25.18 5.06-36.2 8.08c6.7-9.49 2.28-26.73-8.46-31.16Z"/><circle cx="361.72" cy="403.5" r="62.99" fill="var(--primary)"/><path fill="var(--primary)" d="M319.66 336.04a45.16 45.16 0 0 1-41.26-26.79L178.45 84.16A59.83 59.83 0 1 1 290.32 42.3l72.38 235.4a45.08 45.08 0 0 1-43.04 58.34Z"/></svg>
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index bfe3d6234..3409320ce 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -56,6 +56,10 @@ export const CREATE_BUTTON_MAP = {
tags: {
title: "Create a tag",
onClick: () => hashNavigate(`/tags/create`)
+ },
+ reminders: {
+ title: "Add a reminder",
+ onClick: () => hashNavigate(`/reminders/create`)
}
};
diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts
index ddbcfc539..12204480c 100644
--- a/apps/web/src/common/multi-select.ts
+++ b/apps/web/src/common/multi-select.ts
@@ -21,6 +21,7 @@ import { showMultiDeleteConfirmation } from "./dialog-controller";
import { store as noteStore } from "../stores/note-store";
import { store as notebookStore } from "../stores/notebook-store";
import { store as attachmentStore } from "../stores/attachment-store";
+import { store as reminderStore } from "../stores/reminder-store";
import { db } from "./db";
import { showToast } from "../utils/toast";
import Vault from "./vault";
@@ -73,8 +74,6 @@ async function moveNotebooksToTrash(notebooks: Item[]) {
const isMultiselect = notebooks.length > 1;
if (isMultiselect) {
if (!(await showMultiDeleteConfirmation(notebooks.length))) return;
- } else {
- if (item.locked && !(await Vault.unlockNote(item.id))) return;
}
await TaskManager.startTask({
@@ -152,7 +151,35 @@ async function deleteAttachments(attachments: Item[]) {
);
}
+async function moveRemindersToTrash(reminders: Item[]) {
+ const isMultiselect = reminders.length > 1;
+ if (isMultiselect) {
+ if (!(await showMultiDeleteConfirmation(reminders.length))) return;
+ }
+
+ await TaskManager.startTask({
+ type: "status",
+ id: "deleteReminders",
+ action: async (report) => {
+ report({
+ text: `Deleting ${pluralize(
+ reminders.length,
+ "reminder",
+ "reminders"
+ )}...`
+ });
+ await reminderStore.delete(...reminders.map((i) => i.id));
+ }
+ });
+
+ showToast(
+ "success",
+ `${pluralize(reminders.length, "reminder", "reminders")} moved to trash`
+ );
+}
+
export const Multiselect = {
+ moveRemindersToTrash,
moveNotebooksToTrash,
moveNotesToTrash,
deleteTopics,
diff --git a/apps/web/src/components/icons/index.tsx b/apps/web/src/components/icons/index.tsx
index 7c7cafb07..573fc21f1 100644
--- a/apps/web/src/components/icons/index.tsx
+++ b/apps/web/src/components/icons/index.tsx
@@ -176,7 +176,12 @@ import {
mdiSpeedometer,
mdiFormatLineSpacing,
mdiCalendarClockOutline,
- mdiPuzzleOutline
+ mdiPuzzleOutline,
+ mdiBellRingOutline,
+ mdiClockTimeFiveOutline,
+ mdiBellOffOutline,
+ mdiVibrate,
+ mdiBellCancelOutline
} from "@mdi/js";
import { useTheme } from "@emotion/react";
import { AnimatedFlex } from "../animated";
@@ -361,6 +366,7 @@ export const Colors = createIcon(mdiPaletteOutline);
export const Published = createIcon(mdiCloudCheckOutline);
export const Copy = createIcon(mdiContentCopy);
export const Refresh = createIcon(mdiRefresh);
+export const Clock = createIcon(mdiClockTimeFiveOutline);
export const Duplicate = createIcon(mdiContentDuplicate);
export const Select = createIcon(mdiCheckboxMultipleMarkedCircleOutline);
export const NotebookEdit = createIcon(mdiBookEditOutline);
@@ -443,3 +449,9 @@ export const Performance = createIcon(mdiSpeedometer);
export const Date = createIcon(mdiCalendarClockOutline);
export const LineSpacing = createIcon(mdiFormatLineSpacing);
export const Extension = createIcon(mdiPuzzleOutline);
+
+export const Reminders = createIcon(mdiBellRingOutline);
+export const ReminderOff = createIcon(mdiBellCancelOutline);
+export const Silent = createIcon(mdiBellOffOutline);
+export const Vibrate = createIcon(mdiVibrate);
+export const Loud = createIcon(mdiBellRingOutline);
diff --git a/apps/web/src/components/list-container/index.tsx b/apps/web/src/components/list-container/index.tsx
index c7d420012..c58cc8d92 100644
--- a/apps/web/src/components/list-container/index.tsx
+++ b/apps/web/src/components/list-container/index.tsx
@@ -57,11 +57,11 @@ type ListContainerProps = {
type: keyof typeof ListProfiles;
items: Item[];
groupType: string;
- context: Context;
+ context?: Context;
refresh: () => void;
- header: JSX.Element;
+ header?: JSX.Element;
placeholder: () => JSX.Element;
- isLoading: boolean;
+ isLoading?: boolean;
button?: {
onClick: () => void;
};
@@ -228,6 +228,7 @@ function ListContainer(props: ListContainerProps) {
default:
return (
<Component
+ //@ts-ignore
item={item}
context={context}
index={index}
diff --git a/apps/web/src/components/list-container/list-profiles.tsx b/apps/web/src/components/list-container/list-profiles.tsx
index cbee65276..87bc17378 100644
--- a/apps/web/src/components/list-container/list-profiles.tsx
+++ b/apps/web/src/components/list-container/list-profiles.tsx
@@ -26,6 +26,8 @@ import TrashItem from "../trash-item";
import Attachment from "../attachment";
import { db } from "../../common/db";
import { getTotalNotes } from "../../common";
+import Reminder from "../reminder";
+import type { Reminder as ReminderType } from "@notesnook/core/collections/reminders";
const SINGLE_LINE_HEIGHT = 1.4;
const DEFAULT_LINE_HEIGHT =
@@ -46,14 +48,16 @@ type NotebookReference = Item & { topics: string[] };
type NotebookType = Item & { topics: Item[] };
export type Context = { type: string } & Record<string, unknown>;
-type ItemWrapperProps = {
+type ItemWrapperProps<TItem = Item> = {
index: number;
- item: Item;
+ item: TItem;
type: keyof typeof ListProfiles;
- context: Context;
+ context?: Context;
};
-type ItemWrapper = (props: ItemWrapperProps) => JSX.Element;
+type ItemWrapper<TItem = Item> = (
+ props: ItemWrapperProps<TItem>
+) => JSX.Element;
const NotesProfile: ItemWrapper = ({ index, item, type, context }) => (
<Note
@@ -84,10 +88,16 @@ const TopicsProfile: ItemWrapper = ({ index, item, context }) => (
<Topic
index={index}
item={item}
- onClick={() => navigate(`/notebooks/${context.notebookId}/${item.id}`)}
+ onClick={() =>
+ context ? navigate(`/notebooks/${context.notebookId}/${item.id}`) : null
+ }
/>
);
+const RemindersProfile: ItemWrapper<ReminderType> = ({ index, item }) => (
+ <Reminder item={item} index={index} />
+);
+
const TrashProfile: ItemWrapper = ({ index, item, type }) => (
<TrashItem index={index} item={item} date={getDate(item, type)} />
);
@@ -100,6 +110,7 @@ export const ListProfiles = {
home: NotesProfile,
notebooks: NotebooksProfile,
notes: NotesProfile,
+ reminders: RemindersProfile,
tags: TagsProfile,
topics: TopicsProfile,
trash: TrashProfile,
@@ -128,7 +139,7 @@ type NotebookResult =
function getNotebook(
notebooks: Item[],
- contextType: string
+ contextType?: string
): NotebookResult | undefined {
if (contextType === "topic" || !notebooks?.length) return;
diff --git a/apps/web/src/components/navigation-menu/index.tsx b/apps/web/src/components/navigation-menu/index.tsx
index 30422309d..114448085 100644
--- a/apps/web/src/components/navigation-menu/index.tsx
+++ b/apps/web/src/components/navigation-menu/index.tsx
@@ -34,7 +34,8 @@ import {
LightMode,
Login,
Circle,
- Icon
+ Icon,
+ Reminders
} from "../icons";
import { AnimatedFlex } from "../animated";
import NavigationItem from "./navigation-item";
@@ -88,6 +89,11 @@ const routes: Route[] = [
path: "/monographs",
icon: Monographs
},
+ {
+ title: "Reminders",
+ path: "/reminders",
+ icon: Reminders
+ },
{ title: "Trash", path: "/trash", icon: Trash }
];
diff --git a/apps/web/src/components/placeholders/loader.js b/apps/web/src/components/placeholders/loader.js
index cc91f2244..ca8a11736 100644
--- a/apps/web/src/components/placeholders/loader.js
+++ b/apps/web/src/components/placeholders/loader.js
@@ -26,6 +26,7 @@ import { ReactComponent as Tag } from "../../assets/tag.svg";
import { ReactComponent as Trash } from "../../assets/trash.svg";
import { ReactComponent as Fav } from "../../assets/fav.svg";
import { ReactComponent as Attachment } from "../../assets/attachment.svg";
+import { ReactComponent as Reminder } from "../../assets/reminder.svg";
const Placeholders = {
note: Note,
@@ -36,7 +37,8 @@ const Placeholders = {
tag: Tag,
trash: Trash,
favorites: Fav,
- attachments: Attachment
+ attachments: Attachment,
+ reminder: Reminder
};
export default function PlaceholderLoader({ name, onLoad, ...restProps }) {
diff --git a/apps/web/src/components/placeholders/reminders-placeholder.js b/apps/web/src/components/placeholders/reminders-placeholder.js
new file mode 100644
index 000000000..302e232b1
--- /dev/null
+++ b/apps/web/src/components/placeholders/reminders-placeholder.js
@@ -0,0 +1,38 @@
+/*
+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 Placeholder from "./index";
+import { Plus } from "../icons";
+import { hashNavigate } from "../../navigation";
+
+function RemindersPlaceholder() {
+ return (
+ <Placeholder
+ id="reminder"
+ title="Your reminders"
+ text="You have not added any reminders yet."
+ callToAction={{
+ text: "Add your first reminder",
+ icon: Plus,
+ onClick: () => hashNavigate("/reminders/create")
+ }}
+ />
+ );
+}
+export default RemindersPlaceholder;
diff --git a/apps/web/src/components/reminder/index.tsx b/apps/web/src/components/reminder/index.tsx
new file mode 100644
index 000000000..a85e7b7b5
--- /dev/null
+++ b/apps/web/src/components/reminder/index.tsx
@@ -0,0 +1,135 @@
+/*
+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 React from "react";
+import ListItem from "../list-item";
+import { Flex } from "@theme-ui/components";
+import * as Icon from "../icons";
+import IconTag from "../icon-tag";
+import {
+ Reminder as ReminderType,
+ formatReminderTime
+} from "@notesnook/core/collections/reminders";
+import { hashNavigate } from "../../navigation";
+import { Multiselect } from "../../common/multi-select";
+import { showReminderPreviewDialog } from "../../common/dialog-controller";
+import { store } from "../../stores/reminder-store";
+import { db } from "../../common/db";
+
+const RECURRING_MODE_MAP = {
+ week: "Weekly",
+ day: "Daily",
+ month: "Monthly"
+} as const;
+
+const PRIORITY_ICON_MAP = {
+ silent: Icon.Silent,
+ vibrate: Icon.Vibrate,
+ urgent: Icon.Loud
+} as const;
+
+function Reminder({ item, index }: { item: ReminderType; index: number }) {
+ const reminder = item;
+ const PriorityIcon = PRIORITY_ICON_MAP[reminder.priority];
+ return (
+ <ListItem
+ selectable
+ item={reminder}
+ title={reminder.title}
+ body={reminder.description}
+ footer={
+ <Flex
+ sx={{
+ alignItems: "center"
+ }}
+ >
+ {reminder.disabled ? (
+ <Icon.ReminderOff size={16} color="fontTertiary" sx={{ mr: 1 }} />
+ ) : (
+ <PriorityIcon size={16} color="fontTertiary" sx={{ mr: 1 }} />
+ )}
+ {reminder.mode === "repeat" && reminder.recurringMode && (
+ <IconTag
+ icon={Icon.Refresh}
+ text={RECURRING_MODE_MAP[reminder.recurringMode]}
+ />
+ )}
+ <IconTag icon={Icon.Clock} text={formatReminderTime(reminder)} />
+ </Flex>
+ }
+ index={index}
+ menu={{
+ items: menuItems,
+ extraData: { reminder }
+ }}
+ />
+ );
+}
+
+export default React.memo(Reminder, (prev, next) => {
+ return prev?.item?.title === next?.item?.title;
+});
+
+type MenuActionParams = {
+ reminder: ReminderType;
+ items: ReminderType[];
+};
+
+type MenuItemValue<T> = T | ((options: MenuActionParams) => T);
+
+const menuItems: {
+ key: string;
+ title: MenuItemValue<string>;
+ icon: MenuItemValue<Icon.Icon>;
+ onClick: (options: MenuActionParams) => void;
+ color?: MenuItemValue<string>;
+ iconColor?: MenuItemValue<string>;
+ multiSelect?: boolean;
+}[] = [
+ {
+ key: "edit",
+ title: "Edit",
+ icon: Icon.NotebookEdit,
+ onClick: ({ reminder }) => hashNavigate(`/reminders/${reminder.id}/edit`)
+ },
+ {
+ key: "toggle",
+ title: ({ reminder }) => (reminder.disabled ? "Turn on" : "Turn off"),
+ icon: ({ reminder }: MenuActionParams) =>
+ reminder.disabled ? Icon.Reminders : Icon.ReminderOff,
+ onClick: async ({ reminder }) => {
+ await db.reminders?.add({
+ id: reminder.id,
+ disabled: !reminder.disabled
+ });
+ store.refresh();
+ }
+ },
+ {
+ key: "delete",
+ title: "Delete",
+ color: "error",
+ iconColor: "error",
+ icon: Icon.Trash,
+ onClick: async ({ items }) => {
+ await Multiselect.moveRemindersToTrash(items);
+ },
+ multiSelect: true
+ }
+];
diff --git a/apps/web/src/navigation/routes.js b/apps/web/src/navigation/routes.js
index b60f74bbe..88c31817b 100644
--- a/apps/web/src/navigation/routes.js
+++ b/apps/web/src/navigation/routes.js
@@ -30,6 +30,7 @@ import Trash from "../views/trash";
import { store as notestore } from "../stores/note-store";
import { store as nbstore } from "../stores/notebook-store";
import { showToast } from "../utils/toast";
+import Reminders from "../views/reminders";
const routes = {
"/notes": () => ({
@@ -117,6 +118,19 @@ const routes = {
}
};
},
+ "/reminders": () => {
+ return {
+ key: "notes",
+ title: "Reminders",
+ type: "reminders",
+ component: <Reminders />,
+ buttons: {
+ search: {
+ title: "Search reminders"
+ }
+ }
+ };
+ },
"/trash": () => ({
key: "trash",
type: "trash",
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 27f515a61..0d0cf6e02 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -26,6 +26,7 @@ import { store as tagStore } from "./tag-store";
import { store as editorstore } from "./editor-store";
import { store as attachmentStore } from "./attachment-store";
import { store as monographStore } from "./monograph-store";
+import { store as reminderStore } from "./reminder-store";
import BaseStore from "./index";
import { showToast } from "../utils/toast";
import { resetReminders } from "../common/reminders";
@@ -55,6 +56,9 @@ class AppStore extends BaseStore {
lastSynced = 0;
init = () => {
+ // this needs to happen here so reminders can be set on app load.
+ reminderStore.refresh();
+
let count = 0;
EV.subscribe(EVENTS.appRefreshRequested, () => this.refresh());
@@ -114,6 +118,7 @@ class AppStore extends BaseStore {
await resetReminders();
noteStore.refresh();
notebookStore.refresh();
+ reminderStore.refresh();
trashStore.refresh();
tagStore.refresh();
attachmentStore.refresh();
diff --git a/apps/web/src/stores/reminder-store.js b/apps/web/src/stores/reminder-store.js
new file mode 100644
index 000000000..a349dcb95
--- /dev/null
+++ b/apps/web/src/stores/reminder-store.js
@@ -0,0 +1,129 @@
+/*
+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 createStore from "../common/store";
+import { db } from "../common/db";
+import BaseStore from "./index";
+import { groupArray } from "@notesnook/core/utils/grouping";
+import { TaskScheduler } from "../utils/task-scheduler";
+import dayjs from "dayjs";
+
+class ReminderStore extends BaseStore {
+ reminders = [];
+
+ refresh = (reset = true) => {
+ const reminders = db.reminders.all;
+ this.set(
+ (state) =>
+ (state.reminders = groupArray(
+ reminders,
+ db.settings.getGroupOptions("reminders")
+ ))
+ );
+ if (reset) resetReminders(reminders);
+ };
+
+ delete = async (...ids) => {
+ await db.reminders.remove(...ids);
+ this.refresh();
+ };
+}
+
+/**
+ * @type {[import("zustand").UseStore<ReminderStore>, ReminderStore]}
+ */
+const [useStore, store] = createStore(ReminderStore);
+export { useStore, store };
+
+async function resetReminders(reminders) {
+ await TaskScheduler.stopAllWithPrefix("reminder:");
+
+ if (!("Notification" in window) || Notification.permission !== "granted")
+ return;
+
+ for (const reminder of reminders) {
+ if (reminder.disabled) continue;
+
+ // set a one time reminder at the snoozed date
+ if (reminder.snoozeUntil > Date.now()) {
+ await scheduleReminder(
+ `${reminder.id}-snoozed`,
+ reminder,
+ reminderToCronExpression({ mode: "once", date: reminder.snoozeUntil })
+ );
+ }
+
+ await scheduleReminder(
+ reminder.id,
+ reminder,
+ reminderToCronExpression(reminder)
+ );
+ }
+}
+
+function scheduleReminder(id, reminder, cron) {
+ return TaskScheduler.register(`reminder:${id}`, cron, () => {
+ const notification = new Notification(reminder.title, {
+ body: reminder.description,
+ vibrate: reminder.priority === "vibrate",
+ silent: reminder.priority === "silent",
+ tag: id,
+ renotify: true,
+ requireInteraction: true
+ });
+
+ notification.onclick = function () {
+ };
+
+ store.refresh(false);
+ });
+}
+
+function reminderToCronExpression(reminder) {
+ const { date, recurringMode, selectedDays, mode } = reminder;
+ const dateTime = dayjs(date);
+
+ if (mode === "once") {
+ return dateTime.format("ss mm HH DD MM * YYYY");
+ } else {
+ const cron = dateTime.format("ss mm HH").split(" ");
+ if (recurringMode === "week") {
+ cron.push("*"); // day of month
+ cron.push("*"); // month
+ cron.push(selectedDays.sort((a, b) => a - b).join(",")); // day of week
+ cron.push("*"); // year
+ } else if (recurringMode === "month") {
+ cron.push(
+ selectedDays
+ .sort((a, b) => a - b)
+ .map((a) => ++a)
+ .join(",")
+ ); // day of month
+ cron.push("*"); // month
+ cron.push("*"); // day of week
+ cron.push("*"); // year
+ } else if (recurringMode === "day") {
+ cron.push("*"); // day of month
+ cron.push("*"); // month
+ cron.push("*"); // day of week
+ cron.push("*"); // year
+ }
+ return cron.join(" ");
+ }
+}
diff --git a/apps/web/src/utils/task-scheduler.ts b/apps/web/src/utils/task-scheduler.ts
index cc5f7c721..d0fb907a6 100644
--- a/apps/web/src/utils/task-scheduler.ts
+++ b/apps/web/src/utils/task-scheduler.ts
@@ -58,6 +58,10 @@ export class TaskScheduler {
await scheduler?.stopAll();
worker?.terminate();
}
+
+ static async stopAllWithPrefix(prefix: string) {
+ await scheduler?.stopAllWithPrefix(prefix);
+ }
}
function init() {
diff --git a/apps/web/src/utils/task-scheduler.worker.ts b/apps/web/src/utils/task-scheduler.worker.ts
index a3588efdb..0acedee8a 100644
--- a/apps/web/src/utils/task-scheduler.worker.ts
+++ b/apps/web/src/utils/task-scheduler.worker.ts
@@ -52,6 +52,11 @@ const module = {
delete RUNNING_TASKS[id];
}
},
+ stopAllWithPrefix: (prefix: string) => {
+ for (const id in RUNNING_TASKS) {
+ if (id.startsWith(prefix)) module.stop(id);
+ }
+ },
stopAll: () => {
for (const id in RUNNING_TASKS) {
module.stop(id);
diff --git a/apps/web/src/views/reminders.tsx b/apps/web/src/views/reminders.tsx
new file mode 100644
index 000000000..190c22b41
--- /dev/null
+++ b/apps/web/src/views/reminders.tsx
@@ -0,0 +1,47 @@
+/*
+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 ListContainer from "../components/list-container";
+import { useStore, store } from "../stores/reminder-store";
+import RemindersPlaceholder from "../components/placeholders/reminders-placeholder";
+import { hashNavigate } from "../navigation";
+import useNavigate from "../hooks/use-navigate";
+
+function Reminders() {
+ useNavigate("reminders", () => store.refresh());
+ const reminders = useStore((state) => state.reminders);
+ const refresh = useStore((state) => state.refresh);
+ console.log(reminders);
+ return (
+ <>
+ <ListContainer
+ type="reminders"
+ groupType="reminders"
+ refresh={refresh}
+ items={reminders}
+ placeholder={RemindersPlaceholder}
+ button={{
+ onClick: () => hashNavigate("/reminders/create")
+ }}
+ />
+ </>
+ );
+}
+
+export default Reminders;
diff --git a/packages/core/collections/reminders.js b/packages/core/collections/reminders.js
index df3bb9794..5cdb6b9a7 100644
--- a/packages/core/collections/reminders.js
+++ b/packages/core/collections/reminders.js
@@ -45,7 +45,9 @@ dayjs.extend(isBetween);
* selectedDays?: number[];
* dateCreated: number;
* dateModified: number;
- * localOnly: boolean;
+ * localOnly?: boolean;
+ * disabled?: boolean;
+ * snoozeUntil?: number;
* }} Reminder
*
*/
@@ -86,7 +88,9 @@ export default class Reminders extends Collection {
recurringMode: reminder.recurringMode,
selectedDays: reminder.selectedDays || [],
title: reminder.title,
- localOnly: reminder.localOnly
+ localOnly: reminder.localOnly,
+ disabled: reminder.disabled,
+ snoozeUntil: reminder.snoozeUntil
};
await this._collection.addItem(reminder);