Skip to content

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

mobile: yearly reminders

Ammar Ahmedfeba11626d52
diff --git a/apps/mobile/app/components/sheets/reminder/index.tsx b/apps/mobile/app/components/sheets/reminder/index.tsx
index fe1d040eb..4ef989b6c 100644
--- a/apps/mobile/app/components/sheets/reminder/index.tsx
+++ b/apps/mobile/app/components/sheets/reminder/index.tsx
@@ -68,8 +68,10 @@ const ReminderModes =
const RecurringModes = {
Daily: "day",
Week: "week",
- Month: "month"
+ Month: "month",
+ Year: "year"
};
+
const WeekDays = new Array(7).fill(true);
const MonthDays = new Array(31).fill(true);
const WeekDayNames = {
@@ -168,6 +170,7 @@ export default function ReminderSheet({
if (
reminderMode === ReminderModes.Repeat &&
recurringMode !== "day" &&
+ recurringMode !== "year" &&
selectedDays.length === 0
)
throw new Error("Please select the day to repeat the reminder on");
@@ -233,7 +236,9 @@ export default function ReminderSheet({
alignItems: "center"
}}
>
- <Heading size={SIZE.lg}>Set reminder</Heading>
+ <Heading size={SIZE.lg}>
+ {reminder ? "Edit reminder" : "New reminder"}
+ </Heading>
<Button
title="Save"
type="accent"
@@ -256,11 +261,7 @@ export default function ReminderSheet({
<ScrollView
style={{
flexDirection: "row",
- borderWidth: 1,
marginTop: 12,
- borderRadius: 5,
- borderColor: colors.primary.border,
- paddingLeft: 12,
height: 50
}}
horizontal
@@ -338,11 +339,7 @@ export default function ReminderSheet({
style={{
flexDirection: "row",
marginBottom: 12,
- height: 50,
- borderWidth: 1,
- borderRadius: 5,
- borderColor: colors.primary.border,
- paddingLeft: 12
+ height: 50
}}
horizontal
>
@@ -397,7 +394,8 @@ export default function ReminderSheet({
<View
style={{
flexDirection: "row",
- marginBottom: recurringMode === "day" ? 0 : 12,
+ marginBottom:
+ recurringMode === "day" || recurringMode === "year" ? 0 : 12,
alignItems: "center"
}}
>
@@ -415,7 +413,7 @@ export default function ReminderSheet({
type={
recurringMode ===
RecurringModes[mode as keyof typeof RecurringModes]
- ? "grayAccent"
+ ? "selected"
: "gray"
}
onPress={() => {
@@ -432,7 +430,8 @@ export default function ReminderSheet({
</View>
<ScrollView showsHorizontalScrollIndicator={false} horizontal>
- {recurringMode === RecurringModes.Daily
+ {recurringMode === RecurringModes.Daily ||
+ recurringMode === RecurringModes.Year
? null
: recurringMode === RecurringModes.Week
? WeekDays.map((item, index) => (
@@ -532,7 +531,12 @@ export default function ReminderSheet({
locale={
db.settings?.getTimeFormat() === "24-hour" ? "en_GB" : "en_US"
}
- mode={reminderMode === ReminderModes.Repeat ? "time" : "datetime"}
+ mode={
+ reminderMode === ReminderModes.Repeat &&
+ recurringMode !== "year"
+ ? "time"
+ : "datetime"
+ }
/>
{reminderMode === ReminderModes.Repeat ? null : (
@@ -570,6 +574,10 @@ export default function ReminderSheet({
<Paragraph size={SIZE.xs} color={colors.secondary.paragraph}>
{recurringMode === RecurringModes.Daily
? "Repeats daily " + `at ${dayjs(date).format("hh:mm A")}.`
+ : recurringMode === RecurringModes.Year
+ ? `The reminder will repeat every year on ${dayjs(
+ date
+ ).format("dddd, MMMM D, h:mm A")}.`
: selectedDays.length === 7 &&
recurringMode === RecurringModes.Week
? `The reminder will repeat daily at ${dayjs(date).format(
diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsx
index 696a2585b..7aff76cb2 100644
--- a/apps/mobile/app/hooks/use-app-events.tsx
+++ b/apps/mobile/app/hooks/use-app-events.tsx
@@ -97,6 +97,7 @@ import {
import { getGithubVersion } from "../utils/github-version";
import { tabBarRef } from "../utils/global-refs";
import { sleep } from "../utils/time";
+import Notifications from "../services/notifications";
const onCheckSyncStatus = async (type: SyncStatusEvent) => {
const { disableSync, disableAutoSync } = SettingsService.get();
@@ -660,6 +661,7 @@ export const useAppEvents = () => {
try {
await setupDatabase(password);
await db.init();
+ Notifications.setupReminders(true);
} catch (e) {
DatabaseLogger.error(e as Error);
ToastManager.error(
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index 29ed8c6f9..abed69452 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -96,14 +96,12 @@ function encodeLine(line: string) {
async function initDatabase(notes = true) {
if (!db.isInitialized) {
- await db.initCollections();
- }
- if (notes) {
- await db.notes?.init();
+ await db.init();
}
}
const onEvent = async ({ type, detail }: Event) => {
+ await initDatabase();
const { notification, pressAction, input } = detail;
if (type === EventType.DELIVERED && Platform.OS === "android") {
if (notification?.id) {
@@ -111,8 +109,11 @@ const onEvent = async ({ type, detail }: Event) => {
notification?.id?.split("_")[0]
);
- if (reminder && reminder.recurringMode === "month") {
- await initDatabase();
+ if (
+ reminder &&
+ (reminder.recurringMode === "month" ||
+ reminder?.recurringMode === "year")
+ ) {
await scheduleNotification(reminder);
}
}
@@ -123,7 +124,6 @@ const onEvent = async ({ type, detail }: Event) => {
notifee.decrementBadgeCount();
if (notification?.data?.type === "quickNote") return;
MMKV.removeItem("appState");
- await initDatabase();
if (notification?.data?.type === "reminder" && notification?.id) {
const reminder = db.reminders?.reminder(notification.id?.split("_")[0]);
if (!reminder) return;
@@ -143,7 +143,6 @@ const onEvent = async ({ type, detail }: Event) => {
notifee.decrementBadgeCount();
switch (pressAction?.id) {
case "REMINDER_SNOOZE": {
- await initDatabase();
if (!notification?.id) break;
const reminder = await db.reminders?.reminder(
notification?.id?.split("_")[0]
@@ -165,7 +164,6 @@ const onEvent = async ({ type, detail }: Event) => {
break;
}
case "REMINDER_DISABLE": {
- await initDatabase();
if (!notification?.id) break;
const reminder = await db.reminders?.reminder(
notification?.id?.split("_")[0]
@@ -183,7 +181,6 @@ const onEvent = async ({ type, detail }: Event) => {
break;
}
case "UNPIN": {
- await initDatabase();
if (!notification?.id) break;
remove(notification?.id as string);
const reminder = db.reminders?.reminder(
@@ -213,8 +210,6 @@ const onEvent = async ({ type, detail }: Event) => {
reply_button_text: "Take note",
reply_placeholder_text: "Write something..."
});
- if (!db.isInitialized) await db.init();
- await db.notes?.init();
const id = await db.notes?.add({
content: {
@@ -398,7 +393,7 @@ async function scheduleNotification(
);
}
} catch (e) {
- console.log(e);
+ console.log("Schedule notification", e);
}
}
@@ -740,6 +735,41 @@ async function getTriggers(
});
}
+ break;
+ case "year":
+ let timestamp = dayjs()
+ .month(relativeTime.month())
+ .date(relativeTime.date())
+ .hour(relativeTime.hour())
+ .minute(relativeTime.minute());
+
+ // Timestamp must always be in future.
+ if (timestamp.isBefore(dayjs())) {
+ do {
+ timestamp = timestamp.add(1, "year");
+ } while (timestamp.isBefore(dayjs()));
+ }
+
+ if (Platform.OS === "ios") {
+ triggers.push({
+ timestamp: timestamp.toDate().getTime() as number,
+ type: TriggerType.TIMESTAMP,
+ repeatFrequency: RepeatFrequency.YEARLY,
+ id: `${reminder.id}`,
+ alarmManager: {
+ allowWhileIdle: true
+ }
+ });
+ } else {
+ triggers.push({
+ timestamp: timestamp.toDate().getTime() as number,
+ type: TriggerType.TIMESTAMP,
+ id: reminder.id,
+ alarmManager: {
+ allowWhileIdle: true
+ }
+ });
+ }
break;
}
}
@@ -837,11 +867,14 @@ async function pinQuickNote(launch: boolean) {
async function setupReminders(checkNeedsScheduling = false) {
const reminders = ((await db.reminders?.all.items()) as Reminder[]) || [];
const triggers = await notifee.getTriggerNotifications();
-
for (const reminder of reminders) {
if (reminder.mode === "permanent") {
await scheduleNotification(reminder);
}
+
+ // Skip reminders that are not repeating and their trigger date is in past.
+ if (reminder.mode === "once" && dayjs().isAfter(reminder.date)) continue;
+
const pending = triggers.filter((t) =>
t.notification.id?.startsWith(reminder.id)
);
@@ -853,6 +886,7 @@ async function setupReminders(checkNeedsScheduling = false) {
reminder.dateModified
: true;
}
+
if (!needsReschedule && checkNeedsScheduling) continue;
await scheduleNotification(reminder);
diff --git a/apps/mobile/native/ios/Podfile.lock b/apps/mobile/native/ios/Podfile.lock
index 3584324a1..2b3de7af6 100644
--- a/apps/mobile/native/ios/Podfile.lock
+++ b/apps/mobile/native/ios/Podfile.lock
@@ -485,10 +485,10 @@ PODS:
- React-Core
- RNKeychain (4.0.5):
- React
- - RNNotifee (7.4.4):
+ - RNNotifee (7.4.5):
- React-Core
- - RNNotifee/NotifeeCore (= 7.4.4)
- - RNNotifee/NotifeeCore (7.4.4):
+ - RNNotifee/NotifeeCore (= 7.4.5)
+ - RNNotifee/NotifeeCore (7.4.5):
- React-Core
- RNPrivacySnapshot (1.0.0):
- React-Core
@@ -921,7 +921,7 @@ SPEC CHECKSUMS:
RNGestureHandler: dec4645026e7401a0899f2846d864403478ff6a5
RNIap: fc9af04ee706894a80c9d8f979bae930b0dee191
RNKeychain: 840f8e6f13be0576202aefcdffd26a4f54bfe7b5
- RNNotifee: 2ae3c18196e6f307fa62ae5c8e5305dea03ff147
+ RNNotifee: 81e7afee13c8674ce1eefe429e767c67fd6f912f
RNPrivacySnapshot: 8eaf571478a353f2e5184f5c803164f22428b023
RNReanimated: d347d84b665039d88dbcb1feddb2aa59156c9bd2
RNScreens: d3675ab2878704de70c9dae57fa5d024802404cc
diff --git a/apps/mobile/native/package.json b/apps/mobile/native/package.json
index 0d33f9df5..6d1e1b405 100644
--- a/apps/mobile/native/package.json
+++ b/apps/mobile/native/package.json
@@ -5,7 +5,7 @@
"main": "index.js",
"license": "GPL-3.0-or-later",
"dependencies": {
- "@ammarahmed/notifee-react-native": "7.4.4",
+ "@ammarahmed/notifee-react-native": "7.4.6",
"@ammarahmed/react-native-share-extension": "^2.5.5",
"@ammarahmed/react-native-sodium": "1.5.4",
"@bam.tech/react-native-image-resizer": "3.0.5",
diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.json
index 861654dfe..9827e5524 100644
--- a/apps/mobile/package-lock.json
+++ b/apps/mobile/package-lock.json
@@ -29,7 +29,6 @@
"kysely": "^0.26.3",
"react": "18.2.0",
"react-native": "0.72.0",
- "react-native-quick-sqlite": "^8.0.6",
"tinycolor2": "1.6.0"
},
"devDependencies": {
@@ -27656,7 +27655,7 @@
"version": "1.0.0",
"license": "GPL-3.0-or-later",
"dependencies": {
- "@ammarahmed/notifee-react-native": "7.4.4",
+ "@ammarahmed/notifee-react-native": "7.4.6",
"@ammarahmed/react-native-background-fetch": "^4.2.2",
"@ammarahmed/react-native-eventsource": "1.1.0",
"@ammarahmed/react-native-share-extension": "^2.5.5",
@@ -27792,8 +27791,9 @@
}
},
"node_modules/@ammarahmed/notifee-react-native": {
- "version": "7.4.4",
- "license": "Apache-2.0",
+ "version": "7.4.6",
+ "resolved": "https://registry.npmjs.org/@ammarahmed/notifee-react-native/-/notifee-react-native-7.4.6.tgz",
+ "integrity": "sha512-3T7L8b3cncekJGPjMp5+mlGKtted3Oae/ojLlUAmGmCaDhaRr4bLdDh8FtY6Ik+m4+B4VbYYFxRdF04NMHZgyQ==",
"peerDependencies": {
"react-native": "*"
}
@@ -47664,7 +47664,9 @@
},
"dependencies": {
"@ammarahmed/notifee-react-native": {
- "version": "7.4.4",
+ "version": "7.4.6",
+ "resolved": "https://registry.npmjs.org/@ammarahmed/notifee-react-native/-/notifee-react-native-7.4.6.tgz",
+ "integrity": "sha512-3T7L8b3cncekJGPjMp5+mlGKtted3Oae/ojLlUAmGmCaDhaRr4bLdDh8FtY6Ik+m4+B4VbYYFxRdF04NMHZgyQ==",
"requires": {}
},
"@ammarahmed/react-native-background-fetch": {
@@ -80033,7 +80035,7 @@
"@notesnook/mobile-native": {
"version": "file:native",
"requires": {
- "@ammarahmed/notifee-react-native": "7.4.4",
+ "@ammarahmed/notifee-react-native": "7.4.6",
"@ammarahmed/react-native-background-fetch": "^4.2.2",
"@ammarahmed/react-native-eventsource": "1.1.0",
"@ammarahmed/react-native-share-extension": "^2.5.5",
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index bb3916242..6b49e5d90 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -45,7 +45,6 @@
"kysely": "^0.26.3",
"react": "18.2.0",
"react-native": "0.72.0",
- "react-native-quick-sqlite": "^8.0.6",
"tinycolor2": "1.6.0"
}
}
\ No newline at end of file
diff --git a/apps/mobile/patches/@ammarahmed+notifee-react-native+7.4.4.patch b/apps/mobile/patches/@ammarahmed+notifee-react-native+7.4.4.patch
deleted file mode 100644
index 08f53349d..000000000
--- a/apps/mobile/patches/@ammarahmed+notifee-react-native+7.4.4.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-diff --git a/node_modules/@ammarahmed/notifee-react-native/dist/version.js b/node_modules/@ammarahmed/notifee-react-native/dist/version.js
-new file mode 100644
-index 0000000..5fec2e3
---- /dev/null
-+++ b/node_modules/@ammarahmed/notifee-react-native/dist/version.js
-@@ -0,0 +1,6 @@
-+"use strict";
-+Object.defineProperty(exports, "__esModule", { value: true });
-+exports.version = void 0;
-+// Generated by genversion.
-+exports.version = '7.3.1';
-+//# sourceMappingURL=version.js.map
-\ No newline at end of file