A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: preview reminders on notification click
Abdullah Atta2467b57a2ed6
diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsxindex 8ab47b510..71b9bce40 100644--- a/apps/web/src/common/dialog-controller.tsx+++ b/apps/web/src/common/dialog-controller.tsx@@ -40,6 +40,7 @@ import { Period } from "../components/dialogs/buy-dialog/types";import { FeatureKeys } from "../components/dialogs/feature-dialog";import { AuthenticatorType } from "../components/dialogs/mfa/types";import { Suspense } from "react";+import { Reminder } from "@notesnook/core/collections/reminders";type DialogTypes = typeof Dialogs;type DialogIds = keyof DialogTypes;@@ -617,6 +618,12 @@ export function showReminderDialog(reminderKey: string) {));}+export function showReminderPreviewDialog(reminder: Reminder) {+ return showDialog("ReminderPreviewDialog", (Dialog, perform) => (+ <Dialog reminder={reminder} onClose={perform} />+ ));+}+export function showTrackingDetailsDialog() {return showDialog("TrackingDetailsDialog", (Dialog, perform) => (<Dialog onClose={(res: boolean) => perform(res)} />diff --git a/apps/web/src/components/dialogs/index.ts b/apps/web/src/components/dialogs/index.tsindex 628c42ff4..b5dc6b8c3 100644--- a/apps/web/src/components/dialogs/index.ts+++ b/apps/web/src/components/dialogs/index.ts@@ -38,6 +38,9 @@ const TrackingDetailsDialog = React.lazy();const ReminderDialog = React.lazy(() => import("./reminder-dialog"));const AddReminderDialog = React.lazy(() => import("./add-reminder-dialog"));+const ReminderPreviewDialog = React.lazy(+ () => import("./reminder-preview-dialog")+);const AnnouncementDialog = React.lazy(() => import("./announcement-dialog"));const IssueDialog = React.lazy(() => import("./issue-dialog"));const MultifactorDialog = React.lazy(() => import("./mfa/multi-factor-dialog"));@@ -76,4 +79,5 @@ export const Dialogs = {AttachmentsDialog,MigrationDialog,AddReminderDialog,+ ReminderPreviewDialog};diff --git a/apps/web/src/components/dialogs/reminder-preview-dialog.tsx b/apps/web/src/components/dialogs/reminder-preview-dialog.tsxnew file mode 100644index 000000000..3b44f5a53--- /dev/null+++ b/apps/web/src/components/dialogs/reminder-preview-dialog.tsx@@ -0,0 +1,175 @@+/*+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 { Perform } from "../../common/dialog-controller";+import Dialog from "./dialog";+import Field from "../field";+import {+ Box,+ Button,+ Checkbox,+ Flex,+ Label,+ Radio,+ Text+} from "@theme-ui/components";+import dayjs from "dayjs";+import { useEffect, useState } from "react";+import { db } from "../../common/db";+import { useStore } from "../../stores/reminder-store";+import { showToast } from "../../utils/toast";+import {+ formatReminderTime,+ Reminder+} from "@notesnook/core/collections/reminders";+import IconTag from "../icon-tag";+import { Clock, Refresh } from "../icons";++export type ReminderPreviewDialogProps = {+ onClose: Perform;+ reminder: Reminder;+};++const RECURRING_MODE_MAP = {+ week: "Weekly",+ day: "Daily",+ month: "Monthly"+} as const;++const SNOOZE_TIMES = [+ {+ id: "5-min",+ title: "5 minutes",+ interval: 60 * 5 * 1000+ },+ {+ id: "10-min",+ title: "10 minutes",+ interval: 60 * 10 * 1000+ },+ { id: "15-min", title: "15 minutes", interval: 60 * 15 * 1000 },+ { id: "1-hour", title: "1 hour", interval: 60 * 60 * 1000 }+];++export default function ReminderPreviewDialog(+ props: ReminderPreviewDialogProps+) {+ const { reminder } = props;++ // const [selectedDays, setSelectedDays] = useState<number[]>([]);+ // const [recurringMode, setRecurringMode] = useState<+ // ValueOf<typeof RecurringModes>+ // >(RecurringModes.DAY);+ // const [mode, setMode] = useState<ValueOf<typeof Modes>>(Modes.ONCE);+ // const [priority, setPriority] = useState<ValueOf<typeof Priorities>>(+ // Priorities.VIBRATE+ // );+ // const [date, setDate] = useState(dayjs().format("YYYY-MM-DD"));+ // const [time, setTime] = useState(dayjs().format("HH:mm"));+ // const [title, setTitle] = useState<string>();+ // const [description, setDescription] = useState<string>();+ // const refresh = useStore((state) => state.refresh);+ //+ // useEffect(() => {+ // setSelectedDays([]);+ // }, [recurringMode, mode]);+ //+ // useEffect(() => {+ // setRecurringMode(RecurringModes.DAY);+ // }, [mode]);+ //+ // useEffect(() => {+ // if (!reminderId) return;+ // const reminder = db.reminders?.reminder(reminderId);+ // if (!reminder) return;+ //+ // setSelectedDays(reminder.selectedDays || []);+ // setRecurringMode(reminder.recurringMode || RecurringModes.DAY);+ // setMode(reminder.mode || Modes.ONCE);+ // setPriority(reminder.priority || Priorities.VIBRATE);+ // setDate(dayjs(reminder.date).format("YYYY-MM-DD"));+ // setTime(dayjs(reminder.date).format("HH:mm"));+ // setTitle(reminder.title);+ // setDescription(reminder.description);+ // console.log(reminder);+ // }, [reminderId]);+ //+ // const repeatsDaily =+ // (selectedDays.length === 7 && recurringMode === RecurringModes.WEEK) ||+ // (selectedDays.length === 31 && recurringMode === RecurringModes.MONTH) ||+ // recurringMode === RecurringModes.DAY;++ return (+ <Dialog+ isOpen={true}+ title={reminder.title}+ description={reminder.description}+ onClose={props.onClose}+ negativeButton={{+ text: "Close",+ onClick: props.onClose+ }}+ >+ <Flex+ sx={{+ alignItems: "center",+ mb: 2+ }}+ >+ {reminder.mode === "repeat" && reminder.recurringMode && (+ <IconTag+ icon={Refresh}+ text={RECURRING_MODE_MAP[reminder.recurringMode]}+ />+ )}+ <IconTag icon={Clock} text={formatReminderTime(reminder)} />+ </Flex>++ <Text variant="body">Remind me in:</Text>+ <Flex+ sx={{+ alignItems: "center",+ my: 1,+ gap: 1+ }}+ >+ {SNOOZE_TIMES.map((time) => (+ <Button+ key={time.id}+ variant="tool"+ onClick={() => {+ db.reminders?.add({+ id: reminder.id,+ snoozeUntil: Date.now() + time.interval+ });+ }}+ sx={{+ borderRadius: 100,+ py: 1,+ px: 2,+ flexShrink: 0+ }}+ >+ {time.title}+ </Button>+ ))}+ </Flex>+ </Dialog>+ );+}diff --git a/apps/web/src/stores/reminder-store.js b/apps/web/src/stores/reminder-store.jsindex a349dcb95..55ad79e9d 100644--- a/apps/web/src/stores/reminder-store.js+++ b/apps/web/src/stores/reminder-store.js@@ -22,6 +22,7 @@ import { db } from "../common/db";import BaseStore from "./index";import { groupArray } from "@notesnook/core/utils/grouping";import { TaskScheduler } from "../utils/task-scheduler";+import { showReminderPreviewDialog } from "../common/dialog-controller";import dayjs from "dayjs";class ReminderStore extends BaseStore {@@ -89,6 +90,7 @@ function scheduleReminder(id, reminder, cron) {});notification.onclick = function () {+ showReminderPreviewDialog(reminder);};store.refresh(false);