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
mobile: add reminders on a note
ammarahm-ed79be55ab44d8
diff --git a/apps/mobile/app/components/list-items/reminder/index.tsx b/apps/mobile/app/components/list-items/reminder/index.tsxindex 8db4a5c54..f283690f4 100644--- a/apps/mobile/app/components/list-items/reminder/index.tsx+++ b/apps/mobile/app/components/list-items/reminder/index.tsx@@ -32,10 +32,18 @@ import ReminderSheet from "../../sheets/reminder";import { formatReminderTime } from "../../../utils/time/index";const ReminderItem = React.memo(- ({ item, index }: { item: Reminder; index: number }) => {+ ({+ item,+ index,+ isSheet+ }: {+ item: Reminder;+ index: number;+ isSheet: boolean;+ }) => {const colors = useThemeStore((state) => state.colors);const openReminder = () => {- ReminderSheet.present(item);+ ReminderSheet.present(item, undefined, isSheet);};return (<SelectionWrapper@@ -44,6 +52,7 @@ const ReminderItem = React.memo(height={100}onPress={openReminder}item={item}+ isSheet={isSheet}><View><Heading@@ -136,7 +145,7 @@ const ReminderItem = React.memo(color={colors.pri}name="dots-horizontal"size={SIZE.xl}- onPress={() => Properties.present(item)}+ onPress={() => Properties.present(item, [], isSheet)}customStyle={{justifyContent: "center",height: 35,diff --git a/apps/mobile/app/components/list-items/selection-wrapper/index.js b/apps/mobile/app/components/list-items/selection-wrapper/index.jsindex 506886325..98eefae44 100644--- a/apps/mobile/app/components/list-items/selection-wrapper/index.js+++ b/apps/mobile/app/components/list-items/selection-wrapper/index.js@@ -37,7 +37,8 @@ const SelectionWrapper = ({background,onLongPress,onPress,- testID+ testID,+ isSheet}) => {const itemId = useRef(item.id);const colors = useThemeStore((state) => state.colors);@@ -87,7 +88,7 @@ const SelectionWrapper = ({return (<PressableButton- customColor="transparent"+ customColor={isSheet ? colors.nav : "transparent"}testID={testID}onLongPress={_onLongPress}onPress={_onPress}@@ -102,7 +103,8 @@ const SelectionWrapper = ({borderRadius: 0,overflow: "hidden",paddingHorizontal: 12,- paddingVertical: compactMode ? 8 : 12+ paddingVertical: compactMode ? 8 : 12,+ borderRadius:isSheet ? 10 : 0}}>{item.type === "note" ? (diff --git a/apps/mobile/app/components/list/index.js b/apps/mobile/app/components/list/index.jsindex 4f25ae0b0..c32137b2f 100644--- a/apps/mobile/app/components/list/index.js+++ b/apps/mobile/app/components/list/index.js@@ -56,7 +56,6 @@ const RenderItem = ({ item, index, type, ...restArgs }) => {const groupOptions = db.settings?.getGroupOptions(type);const dateBy =groupOptions.sortBy !== "title" ? groupOptions.sortBy : "dateEdited";-const totalNotes = getTotalNotes(item);const tags =item.tags@@ -97,7 +96,8 @@ const List = ({},screen,ListHeader,- warning+ warning,+ isSheet = false}) => {const colors = useThemeStore((state) => state.colors);const scrollRef = useRef();@@ -115,13 +115,14 @@ const List = ({<RenderItemitem={item}index={index}- color={headerProps.color}- title={headerProps.heading}+ color={headerProps?.color}+ title={headerProps?.heading}type={screen === "Notes" ? "home" : type}screen={screen}+ isSheet={isSheet}/>),- [headerProps.color, headerProps.heading, screen, type]+ [headerProps?.color, headerProps?.heading, screen, type, isSheet]);const _onRefresh = async () => {@@ -185,20 +186,22 @@ const List = ({/>}ListEmptyComponent={- <Empty- loading={loading}- placeholderData={placeholderData}- headerProps={headerProps}- type={type}- screen={screen}- />+ placeholderData ? (+ <Empty+ loading={loading}+ placeholderData={placeholderData}+ headerProps={headerProps}+ type={type}+ screen={screen}+ />+ ) : null}ListFooterComponent={<Footer />}ListHeaderComponent={<>{ListHeader ? (ListHeader- ) : (+ ) : !headerProps ? null : (<Headertitle={headerProps.heading}color={headerProps.color}diff --git a/apps/mobile/app/components/properties/index.js b/apps/mobile/app/components/properties/index.jsindex 2cff2f714..90624dce0 100644--- a/apps/mobile/app/components/properties/index.js+++ b/apps/mobile/app/components/properties/index.js@@ -64,7 +64,7 @@ export const Properties = ({paddingHorizontal: 0,borderBottomRightRadius: DDS.isLargeTablet() ? 10 : 1,borderBottomLeftRadius: DDS.isLargeTablet() ? 10 : 1,- maxHeight: "95%"+ maxHeight: "100%"}}>{!item || !item.id ? (@@ -192,7 +192,7 @@ export const Properties = ({);};-Properties.present = (item, buttons = []) => {+Properties.present = (item, buttons = [], isSheet) => {if (!item) return;let type = item?.type;let props = [];@@ -207,6 +207,7 @@ Properties.present = (item, buttons = []) => {props[0] = db.notes.note(item.id).data;props.push(["Add to notebook",+ "Add-Reminder","Share","Export","Copy",@@ -219,6 +220,7 @@ Properties.present = (item, buttons = []) => {"RemoveTopic","History","ReadOnly",+ "Reminders","Local only","Duplicate",...android,@@ -247,6 +249,7 @@ Properties.present = (item, buttons = []) => {}if (!props[0]) return;presentSheet({+ context:isSheet ? "local" : undefined,component: (ref, close) => (<Propertiesclose={() => {diff --git a/apps/mobile/app/components/sheets/reminder/index.tsx b/apps/mobile/app/components/sheets/reminder/index.tsxindex 37a8c975e..1676822a5 100644--- a/apps/mobile/app/components/sheets/reminder/index.tsx+++ b/apps/mobile/app/components/sheets/reminder/index.tsx@@ -37,11 +37,13 @@ import { db } from "../../../common/database";import Navigation from "../../../services/navigation";import { formatReminderTime } from "../../../utils/time";import Icon from "react-native-vector-icons/MaterialCommunityIcons";+import { useReminderStore } from "../../../stores/use-reminder-store";type ReminderSheetProps = {actionSheetRef: RefObject<ActionSheet>;close?: () => void;update?: (options: PresentSheetOptions) => void;reminder?: Reminder;+ reference?: { id: string; type: string };};const ReminderModes =@@ -83,7 +85,8 @@ export default function ReminderSheet({actionSheetRef,close,update,- reminder+ reminder,+ reference}: ReminderSheetProps) {const colors = useThemeStore((state) => state.colors);const [reminderMode, setReminderMode] = useState<Reminder["mode"]>(@@ -157,8 +160,6 @@ export default function ReminderSheet({const reminderId = await db.reminders?.add({id: reminder?.id,date: date?.getTime(),- dateCreated: Date.now(),- dateModified: Date.now(),priority: reminderNotificationMode,title: title.current,description: details.current,@@ -175,8 +176,15 @@ export default function ReminderSheet({heading: "Failed to add a new reminder"});}+ if (reference) {+ db.relations?.add(reference, {+ id: _reminder?.id as string,+ type: _reminder?.type as string+ });+ }Notifications.scheduleNotification(_reminder as Reminder);- Navigation.queueRoutesForUpdate("Reminders");+ useReminderStore.getState().setReminders();+ close?.();}return (@@ -487,27 +495,17 @@ export default function ReminderSheet({</Paragraph>)}- <Button- style={{- width: "100%"- }}- title="Save"- type="accent"- onPress={saveReminder}- />-{reminder && reminder.date ? (<Viewstyle={{- backgroundColor: colors.nav,borderRadius: 5,flexDirection: "row",paddingHorizontal: 5,paddingVertical: 3,alignItems: "center",justifyContent: "flex-start",- alignSelf: "center",- marginTop: 12+ marginTop: 12,+ marginBottom: 4}}><>@@ -517,23 +515,38 @@ export default function ReminderSheet({color={colors.icon}style={{ marginLeft: 5 }}>- Upcoming: {formatReminderTime(reminder)}+ {formatReminderTime(reminder)}</Paragraph></></View>) : null}++ <Button+ style={{+ width: "100%"+ }}+ title="Save"+ type="accent"+ onPress={saveReminder}+ /></View>);}-ReminderSheet.present = (reminder?: Reminder) => {+ReminderSheet.present = (+ reminder?: Reminder,+ reference?: { id: string; type: string },+ isSheet?: boolean+) => {presentSheet({+ context: isSheet ? "local" : undefined,component: (ref, close, update) => (<ReminderSheetactionSheetRef={ref}close={close}update={update}reminder={reminder}+ reference={reference}/>)});diff --git a/apps/mobile/app/components/sheets/reminders-list/index.tsx b/apps/mobile/app/components/sheets/reminders-list/index.tsxnew file mode 100644index 000000000..3b6447632--- /dev/null+++ b/apps/mobile/app/components/sheets/reminders-list/index.tsx@@ -0,0 +1,112 @@+/*+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, { RefObject, useState } from "react";+import { View } from "react-native";+import ActionSheet from "react-native-actions-sheet";+import { db } from "../../../common/database";+import {+ presentSheet,+ PresentSheetOptions+} from "../../../services/event-manager";+import DialogHeader from "../../dialog/dialog-header";+import List from "../../list";+import { useEffect } from "react";+import { Reminder } from "../../../services/notifications";+import { PressableButtonProps } from "../../ui/pressable";+import SheetProvider from "../../sheet-provider";++type RelationsListProps = {+ actionSheetRef: RefObject<ActionSheet>;+ close?: () => void;+ update?: (options: PresentSheetOptions) => void;+ item: { id: string; type: string };+ referenceType: string;+ relationType: "to" | "from";+ title: string;+ button?: Button;+};++type Button = {+ onPress?: (() => void) | undefined;+ loading?: boolean | undefined;+ title?: string | undefined;+ type?: PressableButtonProps["type"];+};++export const RelationsList = ({+ actionSheetRef,+ close,+ update,+ item,+ referenceType,+ relationType,+ title,+ button+}: RelationsListProps) => {+ const [items, setItems] = useState<Reminder[]>([]);++ useEffect(() => {+ db.relations?.[relationType]?.(+ { id: item?.id, type: item.type },+ referenceType+ ).then((items) => setItems(items as any));+ }, [item?.id, item?.type, referenceType, relationType]);+ return (+ <View style={{ paddingHorizontal: 12, height: "100%" }}>+ <SheetProvider context="local" />+ <DialogHeader title={title} button={button} />+ <List+ listData={items}+ loading={false}+ type={referenceType}+ headerProps={null}+ isSheet={true}+ />+ </View>+ );+};++RelationsList.present = ({+ reference,+ referenceType,+ relationType,+ title,+ button+}: {+ reference: { id: string; type: string };+ referenceType: string;+ relationType: "to" | "from";+ title: string;+ button: Button;+}) => {+ presentSheet({+ component: (ref, close, update) => (+ <RelationsList+ actionSheetRef={ref}+ close={close}+ update={update}+ item={reference}+ referenceType={referenceType}+ relationType={relationType}+ title={title}+ button={button}+ />+ )+ });+};diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.jsindex ba13d4209..7ca3c2d28 100644--- a/apps/mobile/app/hooks/use-actions.js+++ b/apps/mobile/app/hooks/use-actions.js@@ -57,6 +57,7 @@ import {} from "../utils/events";import { deleteItems } from "../utils/functions";import { sleep } from "../utils/time";+import { RelationsList } from "../components/sheets/reminders-list/index";export const useActions = ({ close = () => null, item }) => {const colors = useThemeStore((state) => state.colors);@@ -603,6 +604,15 @@ export const useActions = ({ close = () => null, item }) => {icon: "book-outline",func: addTo},+ {+ name: "Add-Reminder",+ title: "Add reminder",+ icon: "bell-plus",+ func: () => {+ ReminderSheet.present(null, { id: item.id, type: "note" });+ },+ close: true+ },{name: "Move notes",title: "Add notes",@@ -798,13 +808,27 @@ export const useActions = ({ close = () => null, item }) => {{name: "Edit reminder",title: "Edit reminder",- icon: "clock-outline",+ icon: "pencil",func: async () => {close();await sleep(300);ReminderSheet.present(item);},close: false+ },+ {+ name: "Reminders",+ title: "Reminders",+ icon: "bell",+ func: () => {+ RelationsList.present({+ reference: item,+ referenceType: "reminder",+ relationType: "from",+ title: "Reminders"+ });+ },+ close: true}];diff --git a/apps/mobile/app/utils/time/index.ts b/apps/mobile/app/utils/time/index.tsindex b9f328cdb..d78293d2d 100644--- a/apps/mobile/app/utils/time/index.ts+++ b/apps/mobile/app/utils/time/index.ts@@ -80,16 +80,20 @@ export function formatReminderTime(reminder: Reminder) {time = getUpcomingReminderTime(reminder) as number;}+ const isPast = dayjs(time).isBefore(dayjs());+if (dayjs(time).isTomorrow()) {- return `Tomorrow, ${dayjs(time).format("hh:mm A")}`;+ return `"Upcoming": Tomorrow, ${dayjs(time).format("hh:mm A")}`;}if (dayjs(time).isYesterday()) {- return `Yesterday, ${dayjs(time).format("hh:mm A")}`;+ return `Last occurrence: Yesterday, ${dayjs(time).format("hh:mm A")}`;}if (dayjs(time).isToday()) {- return `Today, ${dayjs(time).format("hh:mm A")}`;+ return `${isPast ? "Last occurrence" : "Upcoming"}: Today, ${dayjs(+ time+ ).format("hh:mm A")}`;}// if (isNext(time, "week")) {@@ -110,7 +114,10 @@ export function formatReminderTime(reminder: Reminder) {// } of next month, ${dayjs(time).format("hh:mm A")}`;// }- return dayjs(time).format("ddd, DD MMM,YYYY hh:mm A");+ return (+ `${isPast ? "Last occurrence" : "Upcoming"}: ` ++ dayjs(time).format("ddd, DD MMM,YYYY hh:mm A")+ );}export const sleep = (duration: number) =>