Skip to content

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

mobile: add Reminders screen to nav

ammarahm-ed3702bb018663
diff --git a/apps/mobile/app/components/list-items/reminder/index.tsx b/apps/mobile/app/components/list-items/reminder/index.tsx
new file mode 100644
index 000000000..2935b4941
--- /dev/null
+++ b/apps/mobile/app/components/list-items/reminder/index.tsx
@@ -0,0 +1,35 @@
+/*
+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 { View } from "react-native";
+import type { Reminder } from "../../../services/notifications";
+const ReminderItem = React.memo(
+ ({ item, index }: { item: Reminder; index: number }) => {
+ return <View />;
+ },
+ (prev, next) => {
+ if (prev.item?.dateModified !== next.item?.dateModified) {
+ return false;
+ }
+ return true;
+ }
+);
+ReminderItem.displayName = "ReminderItem";
+
+export default ReminderItem;
diff --git a/apps/mobile/app/components/list/index.js b/apps/mobile/app/components/list/index.js
index 0e82dba46..4f25ae0b0 100644
--- a/apps/mobile/app/components/list/index.js
+++ b/apps/mobile/app/components/list/index.js
@@ -38,6 +38,7 @@ import TagItem from "../list-items/tag";
import { Empty } from "./empty";
import { getTotalNotes } from "../../utils";
import { useSettingStore } from "../../stores/use-setting-store";
+import ReminderItem from "../list-items/reminder";
const renderItems = {
note: NoteWrapper,
@@ -45,7 +46,8 @@ const renderItems = {
topic: NotebookWrapper,
tag: TagItem,
section: SectionHeader,
- header: SectionHeader
+ header: SectionHeader,
+ reminder: ReminderItem
};
const RenderItem = ({ item, index, type, ...restArgs }) => {
diff --git a/apps/mobile/app/navigation/navigation-stack.js b/apps/mobile/app/navigation/navigation-stack.js
index f55ad69ab..c6717dade 100644
--- a/apps/mobile/app/navigation/navigation-stack.js
+++ b/apps/mobile/app/navigation/navigation-stack.js
@@ -34,6 +34,7 @@ import { ColoredNotes } from "../screens/notes/colored";
import { Monographs } from "../screens/notes/monographs";
import { TaggedNotes } from "../screens/notes/tagged";
import { TopicNotes } from "../screens/notes/topic-notes";
+import Reminders from "../screens/reminders";
import { Search } from "../screens/search";
import Settings from "../screens/settings";
import AppLock from "../screens/settings/app-lock";
@@ -156,6 +157,11 @@ const _Tabs = () => {
name="ColoredNotes"
component={ColoredNotes}
/>
+ <NativeStack.Screen
+ options={{ lazy: true }}
+ name="Reminders"
+ component={Reminders}
+ />
<NativeStack.Screen
options={{ lazy: true }}
name="Monographs"
diff --git a/apps/mobile/app/screens/reminders/index.tsx b/apps/mobile/app/screens/reminders/index.tsx
new file mode 100644
index 000000000..45235ef70
--- /dev/null
+++ b/apps/mobile/app/screens/reminders/index.tsx
@@ -0,0 +1,85 @@
+/*
+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 { db } from "../../common/database";
+import DelayLayout from "../../components/delay-layout";
+import List from "../../components/list";
+import { useNavigationFocus } from "../../hooks/use-navigation-focus";
+import Navigation, { NavigationProps } from "../../services/navigation";
+import SearchService from "../../services/search";
+import SettingsService from "../../services/settings";
+import useNavigationStore from "../../stores/use-navigation-store";
+import { useReminderStore } from "../../stores/use-reminder-store";
+
+const prepareSearch = () => {
+ SearchService.update({
+ placeholder: "Search in reminders",
+ type: "reminders",
+ title: "Reminders",
+ get: () => db.reminders?.all
+ });
+};
+
+const PLACEHOLDER_DATA = {
+ heading: "Your reminders",
+ paragraph: "You have not set any reminders yet.",
+ button: null,
+ loading: "Loading reminders"
+};
+
+export const Reminders = ({
+ navigation,
+ route
+}: NavigationProps<"Reminders">) => {
+ const reminders = useReminderStore((state) => state.reminders);
+ const isFocused = useNavigationFocus(navigation, {
+ onFocus: (prev) => {
+ Navigation.routeNeedsUpdate(
+ route.name,
+ Navigation.routeUpdateFunctions[route.name]
+ );
+ useNavigationStore.getState().update({
+ name: route.name
+ });
+
+ SearchService.prepareSearch = prepareSearch;
+ return !prev?.current;
+ },
+ onBlur: () => false,
+ delay: SettingsService.get().homepage === route.name ? 1 : -1
+ });
+
+ return (
+ <DelayLayout>
+ <List
+ listData={reminders}
+ type="reminders"
+ headerProps={{
+ heading: "Reminders"
+ }}
+ loading={!isFocused}
+ screen="Reminders"
+ placeholderData={PLACEHOLDER_DATA}
+ />
+ </DelayLayout>
+ );
+};
+
+export default Reminders;
diff --git a/apps/mobile/app/services/navigation.ts b/apps/mobile/app/services/navigation.ts
index b9392f699..79d9aa955 100755
--- a/apps/mobile/app/services/navigation.ts
+++ b/apps/mobile/app/services/navigation.ts
@@ -28,6 +28,7 @@ import useNavigationStore, {
} from "../stores/use-navigation-store";
import { useNotebookStore } from "../stores/use-notebook-store";
import { useNoteStore } from "../stores/use-notes-store";
+import { useReminderStore } from "../stores/use-reminder-store";
import { useTagStore } from "../stores/use-tag-store";
import { useTrashStore } from "../stores/use-trash-store";
import { eOnNewTopicAdded } from "../utils/events";
@@ -59,7 +60,8 @@ const routeNames = {
Welcome: "Welcome",
AppLock: "AppLock",
Login: "Login",
- Signup: "Signup"
+ Signup: "Signup",
+ Reminders: "Reminders"
};
export type NavigationProps<T extends RouteName> = NativeStackScreenProps<
@@ -83,7 +85,8 @@ const routeUpdateFunctions: {
TaggedNotes: (params) => eSendEvent("TaggedNotes", params),
ColoredNotes: (params) => eSendEvent("ColoredNotes", params),
TopicNotes: (params) => eSendEvent("TopicNotes", params),
- Monographs: (params) => eSendEvent("Monographs", params)
+ Monographs: (params) => eSendEvent("Monographs", params),
+ Reminders: () => useReminderStore.getState().setReminders()
};
function clearRouteFromQueue(routeName: RouteName) {
diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts
index 1f2db5ae1..c95b94e7f 100644
--- a/apps/mobile/app/services/notifications.ts
+++ b/apps/mobile/app/services/notifications.ts
@@ -39,17 +39,11 @@ import { DDS } from "./device-detection";
import { eSendEvent } from "./event-manager";
import SettingsService from "./settings";
-type ReferenceNode = {
- id: string;
- parentId?: string;
- type: string;
-};
-
export type Reminder = {
id: string;
type: string;
title: string;
- details?: string;
+ description?: string;
priority: "silent" | "vibrate" | "urgent";
date?: number;
mode: "repeat" | "once" | "permanent";
@@ -57,7 +51,6 @@ export type Reminder = {
selectedDays: number[];
dateCreated: number;
dateModified: number;
- references?: ReferenceNode[];
};
let pinned: DisplayedNotification[] = [];
@@ -119,15 +112,15 @@ const onEvent = async ({ type, detail }: Event) => {
async function scheduleNotification(reminder: Reminder, payload?: string) {
try {
- const { title, details, priority } = reminder;
+ const { title, description, priority } = reminder;
const triggers = getTriggers(reminder);
if (!triggers && reminder.mode === "permanent") {
displayNotification({
id: reminder.id,
title: title,
- message: details || "",
+ message: description || "",
ongoing: true,
- subtitle: details || ""
+ subtitle: description || ""
});
return;
}
@@ -138,12 +131,12 @@ async function scheduleNotification(reminder: Reminder, payload?: string) {
{
id: trigger.id,
title: title,
- body: details,
+ body: description,
data: {
type: "reminder",
payload: payload || ""
},
- subtitle: details,
+ subtitle: description,
android: {
channelId: await getChannelId(priority),
smallIcon: "ic_stat_name",
@@ -151,11 +144,11 @@ async function scheduleNotification(reminder: Reminder, payload?: string) {
id: "default",
mainComponent: "notesnook"
},
- style: !details
+ style: !description
? undefined
: {
type: AndroidStyle.BIGTEXT,
- text: details
+ text: description
}
},
ios: {
diff --git a/apps/mobile/app/stores/use-navigation-store.ts b/apps/mobile/app/stores/use-navigation-store.ts
index 8a1016a02..cf1dddcec 100644
--- a/apps/mobile/app/stores/use-navigation-store.ts
+++ b/apps/mobile/app/stores/use-navigation-store.ts
@@ -68,6 +68,7 @@ export type RouteParams = {
Monographs: NotesScreenParams;
AppLock: AppLockRouteParams;
Auth: AuthParams;
+ Reminders: GenericRouteParam;
};
export type RouteName = keyof RouteParams;
diff --git a/apps/mobile/app/stores/use-reminder-store.ts b/apps/mobile/app/stores/use-reminder-store.ts
new file mode 100644
index 000000000..97ad24efd
--- /dev/null
+++ b/apps/mobile/app/stores/use-reminder-store.ts
@@ -0,0 +1,54 @@
+/*
+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 { groupArray } from "@notesnook/core/utils/grouping";
+import create, { State } from "zustand";
+import { db } from "../common/database";
+import { Reminder } from "../services/notifications";
+
+export interface ReminderStore extends State {
+ reminders: Reminder[];
+ setReminders: (items?: Reminder[]) => void;
+ cleareReminders: () => void;
+}
+
+export const useReminderStore = create<ReminderStore>((set, get) => ({
+ reminders: [],
+ setReminders: (items) => {
+ if (!items) {
+ set({
+ reminders: groupArray(
+ (db.reminders?.all as Reminder[]) || [],
+ db.settings?.getGroupOptions("reminders")
+ )
+ });
+ return;
+ }
+ const prev = get().reminders;
+ for (let i = 0; i < items.length; i++) {
+ const item = items[i];
+ const index = prev.findIndex((v) => v.id === item.id);
+ if (index !== -1) {
+ prev[index] = item;
+ }
+ }
+ set({ reminders: prev });
+ },
+ cleareReminders: () => set({ reminders: [] })
+}));
diff --git a/apps/mobile/app/utils/constants.js b/apps/mobile/app/utils/constants.js
index d7fb05705..530f7b890 100644
--- a/apps/mobile/app/utils/constants.js
+++ b/apps/mobile/app/utils/constants.js
@@ -118,6 +118,11 @@ export const MenuItemsList = [
icon: "pound",
close: true
},
+ {
+ name: "Reminders",
+ icon: "clock-outline",
+ close: true
+ },
{
name: "Monographs",
icon: "text-box-multiple-outline",