Skip to content

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

web: rename reminder to notice for in-app notices

Abdullah Atta8380c7d994e4
diff --git a/apps/web/src/app-effects.tsx b/apps/web/src/app-effects.tsx
index 7370564dc..e4239a8ff 100644
--- a/apps/web/src/app-effects.tsx
+++ b/apps/web/src/app-effects.tsx
@@ -24,7 +24,7 @@ import { useStore as useThemeStore } from "./stores/theme-store";
import { useStore as useAttachmentStore } from "./stores/attachment-store";
import { useStore as useEditorStore } from "./stores/editor-store";
import { useStore as useAnnouncementStore } from "./stores/announcement-store";
-import { resetReminders, scheduleBackups } from "./common/reminders";
+import { resetNotices, scheduleBackups } from "./common/notices";
import { introduceFeatures, showUpgradeReminderDialogs } from "./common";
import { AppEventManager, AppEvents } from "./common/app-events";
import { db } from "./common/db";
@@ -93,7 +93,7 @@ export default function AppEffects({ setShow }: AppEffectsProps) {
if (await initUser()) {
showUpgradeReminderDialogs();
}
- await resetReminders();
+ await resetNotices();
setIsVaultCreated(await db.vault?.exists());
await showOnboardingDialog(interruptedOnboarding());
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/notices.ts
similarity index 64%
rename from apps/web/src/common/reminders.js
rename to apps/web/src/common/notices.ts
index 623cc50ca..fdba2c124 100644
--- a/apps/web/src/common/reminders.js
+++ b/apps/web/src/common/notices.ts
@@ -21,18 +21,23 @@ import Config from "../utils/config";
import { createBackup, verifyAccount } from "./index";
import { db } from "./db";
import { store as appStore } from "../stores/app-store";
-import { Backup, User, Email, Warn } from "../components/icons";
+import { Backup, User, Email, Warn, Icon } from "../components/icons";
import dayjs from "dayjs";
-import {
- showBuyDialog,
- showRecoveryKeyDialog
-} from "../common/dialog-controller";
+import { showBuyDialog, showRecoveryKeyDialog } from "./dialog-controller";
import { hardNavigate, hashNavigate } from "../navigation";
import { isDesktop, isTesting } from "../utils/platform";
import { isUserPremium } from "../hooks/use-is-user-premium";
import { showToast } from "../utils/toast";
import { TaskScheduler } from "../utils/task-scheduler";
+export type NoticeType = "autoBackupsOff" | "login" | "email" | "recoverykey";
+
+export type Notice = {
+ type: NoticeType;
+ priority: number;
+ params?: any;
+};
+
export const BACKUP_CRON_EXPRESSIONS = [
"",
"0 0 8 * * *", // daily at 8 AM
@@ -41,15 +46,15 @@ export const BACKUP_CRON_EXPRESSIONS = [
];
export async function scheduleBackups() {
- const backupReminderOffset = Config.get("backupReminderOffset", 0);
+ const backupInterval = Config.get("backupReminderOffset", 0);
await TaskScheduler.stop("automatic-backups");
- if (!backupReminderOffset) return false;
+ if (!backupInterval) return false;
console.log("Scheduling automatic backups");
await TaskScheduler.register(
"automatic-backups",
- BACKUP_CRON_EXPRESSIONS[backupReminderOffset],
+ BACKUP_CRON_EXPRESSIONS[backupInterval],
() => {
console.log("Backing up automatically");
saveBackup();
@@ -57,9 +62,9 @@ export async function scheduleBackups() {
);
}
-export function shouldAddAutoBackupsDisabledReminder() {
- const backupReminderOffset = Config.get("backupReminderOffset", 0);
- if (!isUserPremium() && backupReminderOffset) {
+export function shouldAddAutoBackupsDisabledNotice() {
+ const backupInterval = Config.get("backupReminderOffset", 0);
+ if (!isUserPremium() && backupInterval) {
Config.set("backupReminderOffset", 0);
return true;
}
@@ -67,23 +72,22 @@ export function shouldAddAutoBackupsDisabledReminder() {
return false;
}
-export async function shouldAddBackupReminder() {
- const backupReminderOffset = Config.get("backupReminderOffset", 0);
- if (!backupReminderOffset) return false;
+export async function shouldAddBackupNotice() {
+ const backupInterval = Config.get("backupReminderOffset", 0);
+ if (!backupInterval) return false;
- const lastBackupTime = await db.backup.lastBackupTime();
+ const lastBackupTime = await db.backup?.lastBackupTime();
if (!lastBackupTime) {
- await db.backup.updateBackupTime();
+ await db.backup?.updateBackupTime();
return false;
}
- const offsetToDays =
- backupReminderOffset === 1 ? 1 : backupReminderOffset === 2 ? 7 : 30;
+ const offsetToDays = backupInterval === 1 ? 1 : backupInterval === 2 ? 7 : 30;
return dayjs(lastBackupTime).add(offsetToDays, "d").isBefore(dayjs());
}
-export async function shouldAddRecoveryKeyBackupReminder() {
+export async function shouldAddRecoveryKeyBackupNotice() {
if (isIgnored("recoverykey")) return false;
const recoveryKeyBackupDate = Config.get("recoveryKeyBackupDate", 0);
@@ -91,17 +95,26 @@ export async function shouldAddRecoveryKeyBackupReminder() {
return dayjs(recoveryKeyBackupDate).add(30, "d").isBefore(dayjs());
}
-export async function shouldAddLoginReminder() {
- const user = await db.user.getUser();
+export async function shouldAddLoginNotice() {
+ const user = await db.user?.getUser();
if (!user) return true;
}
-export async function shouldAddConfirmEmailReminder() {
- const user = await db.user.getUser();
+export async function shouldAddConfirmEmailNotice() {
+ const user = await db.user?.getUser();
return !user?.isEmailConfirmed;
}
-export const Reminders = {
+type NoticeData = {
+ key: string;
+ title: string;
+ subtitle: string;
+ action: (params?: any) => void;
+ dismissable?: boolean;
+ icon: Icon;
+};
+
+export const NoticesData: Record<NoticeType, NoticeData> = {
autoBackupsOff: {
key: "autoBackupsOff",
title: "Automatic backups disabled",
@@ -136,32 +149,32 @@ export const Reminders = {
}
};
-var openedToast = null;
-export async function resetReminders() {
- const reminders = [];
+export async function resetNotices() {
+ const notices: Notice[] = [];
- if (shouldAddAutoBackupsDisabledReminder()) {
- reminders.push({ type: "autoBackupsOff", priority: "high" });
+ if (shouldAddAutoBackupsDisabledNotice()) {
+ notices.push({ type: "autoBackupsOff", priority: 3 });
}
- if (await shouldAddBackupReminder()) {
+ if (await shouldAddBackupNotice()) {
await saveBackup();
}
- if (await shouldAddLoginReminder()) {
- reminders.push({ type: "login", priority: "low" });
+ if (await shouldAddLoginNotice()) {
+ notices.push({ type: "login", priority: 1 });
}
- if (await shouldAddConfirmEmailReminder()) {
- reminders.push({ type: "email", priority: "high" });
+ if (await shouldAddConfirmEmailNotice()) {
+ notices.push({ type: "email", priority: 4 });
}
- if (await shouldAddRecoveryKeyBackupReminder()) {
- reminders.push({ type: "recoverykey", priority: "high" });
+ if (await shouldAddRecoveryKeyBackupNotice()) {
+ notices.push({ type: "recoverykey", priority: 5 });
}
- appStore.get().setReminders(...reminders);
+ appStore.get().setNotices(...notices);
}
-function isIgnored(key) {
+function isIgnored(key: keyof typeof NoticesData) {
return Config.get(`ignored:${key}`, false);
}
+var openedToast: { hide: () => void } | null = null;
async function saveBackup() {
if (isDesktop()) {
await createBackup();
@@ -174,7 +187,7 @@ async function saveBackup() {
{
text: "Later",
onClick: async () => {
- await db.backup.updateBackupTime();
+ await db.backup?.updateBackupTime();
openedToast?.hide();
openedToast = null;
},
diff --git a/apps/web/src/components/announcements/index.jsx b/apps/web/src/components/announcements/index.jsx
index b19a10ade..966c4e52b 100644
--- a/apps/web/src/components/announcements/index.jsx
+++ b/apps/web/src/components/announcements/index.jsx
@@ -22,7 +22,7 @@ import { Cross } from "../icons";
import { ANALYTICS_EVENTS, trackEvent } from "../../utils/analytics";
import AnnouncementBody from "./body";
import { useStore as useAnnouncementStore } from "../../stores/announcement-store";
-import ReminderBar from "../reminder-bar";
+import Notice from "../notice";
function Announcements() {
const announcements = useAnnouncementStore(
@@ -31,7 +31,7 @@ function Announcements() {
const dismiss = useAnnouncementStore((store) => store.dismiss);
const announcement = announcements[0];
- if (!announcement) return <ReminderBar />;
+ if (!announcement) return <Notice />;
return (
<Flex
mx={1}
diff --git a/apps/web/src/components/reminder-bar/index.jsx b/apps/web/src/components/notice/index.tsx
similarity index 73%
rename from apps/web/src/components/reminder-bar/index.jsx
rename to apps/web/src/components/notice/index.tsx
index 42dc5e8b4..737fa4e03 100644
--- a/apps/web/src/components/reminder-bar/index.jsx
+++ b/apps/web/src/components/notice/index.tsx
@@ -20,23 +20,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { useMemo } from "react";
import { Button, Flex, Text } from "@theme-ui/components";
import { useStore as useAppStore } from "../../stores/app-store";
-import { Reminders } from "../../common/reminders";
+import { NoticesData } from "../../common/notices";
import { Dismiss } from "../icons";
import Config from "../../utils/config";
-function ReminderBar() {
- const reminders = useAppStore((store) => store.reminders);
- const dismissReminders = useAppStore((store) => store.dismissReminders);
- const reminder = useMemo(() => {
- if (!reminders) return null;
-
- const copy = reminders.slice();
- const reminder = copy.sort((a, b) => a.priority - b.priority)[0];
- if (!reminder) return;
- return Reminders[reminder.type];
- }, [reminders]);
-
- if (!reminder) return null;
+function Notice() {
+ const notices = useAppStore((store) => store.notices);
+ const dismissNotices = useAppStore((store) => store.dismissNotices);
+ const notice = useMemo(() => {
+ if (!notices) return null;
+ return notices.slice().sort((a, b) => a.priority - b.priority)[0];
+ }, [notices]);
+ if (!notice) return null;
+ const NoticeData = NoticesData[notice.type];
return (
<Flex
sx={{
@@ -47,34 +43,34 @@ function ReminderBar() {
minWidth: 250
}}
p={1}
- onClick={reminder?.action}
+ onClick={() => NoticeData.action()}
mx={1}
>
<Flex sx={{ flex: 1, alignItems: "center" }}>
- <reminder.icon
+ <NoticeData.icon
size={18}
color="primary"
sx={{ bg: "shade", mr: 2, p: 2, borderRadius: 80 }}
/>
<Flex variant="columnCenter" sx={{ alignItems: "flex-start" }}>
<Text variant="body" sx={{ fontSize: "body" }}>
- {reminder.title}
+ {NoticeData.title}
</Text>
<Text variant="subBody" sx={{ display: "block" }}>
- {reminder.subtitle}
+ {NoticeData.subtitle}
</Text>
</Flex>
</Flex>
- {reminder.dismissable && (
+ {NoticeData.dismissable && (
<Button
onClick={(e) => {
e.stopPropagation();
const dontShowAgain = window.confirm(
"Don't show again on this device?"
);
- dismissReminders(reminder);
+ dismissNotices(notice);
if (dontShowAgain) {
- Config.set(`ignored:${reminder.key}`, true);
+ Config.set(`ignored:${NoticeData.key}`, true);
}
}}
sx={{
@@ -92,4 +88,4 @@ function ReminderBar() {
</Flex>
);
}
-export default ReminderBar;
+export default Notice;
diff --git a/apps/web/src/stores/app-store.js b/apps/web/src/stores/app-store.js
index 7b6f7e23a..119b3d661 100644
--- a/apps/web/src/stores/app-store.js
+++ b/apps/web/src/stores/app-store.js
@@ -31,7 +31,7 @@ import { store as announcementStore } from "./announcement-store";
import { store as settingStore } from "./setting-store";
import BaseStore from "./index";
import { showToast } from "../utils/toast";
-import { resetReminders } from "../common/reminders";
+import { resetNotices } from "../common/notices";
import { EV, EVENTS, SYNC_CHECK_IDS } from "@notesnook/core/common";
import { logger } from "../utils/logger";
import Config from "../utils/config";
@@ -65,7 +65,10 @@ class AppStore extends BaseStore {
};
colors = [];
globalMenu = { items: [], data: {} };
- reminders = [];
+ /**
+ * @type {import("../common/notices").Notice[]}
+ */
+ notices = [];
shortcuts = [];
lastSynced = 0;
@@ -147,7 +150,7 @@ class AppStore extends BaseStore {
logger.measure("refreshing app");
await this.updateLastSynced();
- await resetReminders();
+ await resetNotices();
noteStore.refresh();
notebookStore.refresh();
reminderStore.refresh();
@@ -219,28 +222,22 @@ class AppStore extends BaseStore {
/**
*
- * @param {"backup"|"signup"|"email"|"recoverykey"} type
- * @param {string} title
- * @param {string} detail
- * @param {"high"|"medium"|"low"} priority
+ * @param {import("../common/notices").Notice[]} notices
*/
- setReminders = (...reminders) => {
+ setNotices = (...notices) => {
this.set((state) => {
- state.reminders = [];
- for (let reminder of reminders) {
- const { priority, type } = reminder;
- state.reminders.push({
- type,
- priority: priority === "high" ? 1 : priority === "medium" ? 2 : 1
- });
+ for (const notice of notices) {
+ const oldIndex = state.notices.findIndex((a) => a.type === notice.type);
+ if (oldIndex > -1) state.notices.splice(oldIndex, 1);
+ state.notices.push(notice);
}
});
};
- dismissReminders = (...reminders) => {
+ dismissNotices = (...reminders) => {
this.set((state) => {
for (let reminder of reminders) {
- state.reminders.splice(state.reminders.indexOf(reminder), 1);
+ state.notices.splice(state.notices.indexOf(reminder), 1);
}
});
};