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
refactor
ammarahm-ed97ec6bd61931
diff --git a/apps/mobile/src/views/Settings/backuprestore.js b/apps/mobile/src/views/Settings/backuprestore.jsindex 1385798eb..c4e7fcc01 100644--- a/apps/mobile/src/views/Settings/backuprestore.js+++ b/apps/mobile/src/views/Settings/backuprestore.js@@ -1,94 +1,28 @@-import dayjs from 'dayjs';-import React, {useCallback, useEffect, useRef, useState} from 'react';-import {- Appearance,- Linking,- Platform,- ScrollView,- TouchableOpacity,- View-} from 'react-native';-import * as RNIap from 'react-native-iap';-import {enabled} from 'react-native-privacy-snapshot';-import Menu, {MenuItem} from 'react-native-reanimated-material-menu';-import AnimatedProgress from 'react-native-reanimated-progress-bar';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';+import React, {useState} from 'react';+import {Platform, TouchableOpacity, View} from 'react-native';import ToggleSwitch from 'toggle-switch-react-native';-import {Button} from '../../components/Button';-import {Button as MButton} from '../../components/Button/index';-import {ContainerTopSection} from '../../components/Container/ContainerTopSection';-import BaseDialog from '../../components/Dialog/base-dialog';-import DialogButtons from '../../components/Dialog/dialog-buttons';-import DialogContainer from '../../components/Dialog/dialog-container';-import DialogHeader from '../../components/Dialog/dialog-header';-import {presentDialog} from '../../components/Dialog/functions';-import {Issue} from '../../components/Github/issue';-import {Header as TopHeader} from '../../components/Header/index';-import Input from '../../components/Input';-import {PressableButton} from '../../components/PressableButton';-import Seperator from '../../components/Seperator';-import {Card} from '../../components/SimpleList/card';-import {Toast} from '../../components/Toast';-import Heading from '../../components/Typography/Heading';import Paragraph from '../../components/Typography/Paragraph';import {useTracked} from '../../provider';-import {Actions} from '../../provider/Actions';-import {- useMessageStore,- useSettingStore,- useUserStore-} from '../../provider/stores';+import {useSettingStore, useUserStore} from '../../provider/stores';import Backup from '../../services/Backup';-import BiometricService from '../../services/BiometricService';-import {DDS} from '../../services/DeviceDetection';import {eSendEvent,- eSubscribeEvent,- eUnSubscribeEvent,- openVault,presentSheet,ToastEvent} from '../../services/EventManager';-import Navigation from '../../services/Navigation';-import Notifications from '../../services/Notifications';import PremiumService from '../../services/PremiumService';import SettingsService from '../../services/SettingsService';-import Sync from '../../services/Sync';-import {- AndroidModule,- APP_VERSION,- InteractionManager,- MenuItemsList,- SUBSCRIPTION_PROVIDER,- SUBSCRIPTION_STATUS,- SUBSCRIPTION_STATUS_STRINGS-} from '../../utils';-import {- ACCENT,- COLOR_SCHEME,- COLOR_SCHEME_DARK,- COLOR_SCHEME_LIGHT,- setColorScheme-} from '../../utils/Colors';-import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils';-import {db} from '../../utils/database';import {eCloseProgressDialog,eOpenLoginDialog,- eOpenPremiumDialog,- eOpenProgressDialog,- eOpenRecoveryKeyDialog,- eOpenRestoreDialog,- eScrollEvent,- eUpdateSearchState+ eOpenRestoreDialog} from '../../utils/Events';import {openLinkInBrowser} from '../../utils/functions';import {MMKV} from '../../utils/mmkv';-import {tabBarRef} from '../../utils/Refs';-import {pv, SIZE} from '../../utils/SizeUtils';-import Storage from '../../utils/storage';+import {SIZE} from '../../utils/SizeUtils';import {sleep} from '../../utils/TimeUtils';-import { CustomButton } from './button';+import {CustomButton} from './button';+import {verifyUser} from './functions';import SectionHeader from './section-header';const SettingsBackupAndRestore = ({isSheet}) => {@@ -172,40 +106,7 @@ const SettingsBackupAndRestore = ({isSheet}) => {await Backup.run();return;}- presentDialog({- title: "Verify it's you",- input: true,- inputPlaceholder: 'Enter account password',- paragraph: 'Please enter your account password to backup your data',- positiveText: 'Verify',- secureTextEntry: true,- positivePress: async value => {- try {- let verified = await db.user.verifyPassword(value);- if (verified) {- sleep(300).then(async () => {- await Backup.run();- });- } else {- ToastEvent.show({- heading: 'Incorrect password',- message: 'The account password you entered is incorrect',- type: 'error',- context: 'local'- });- return false;- }- } catch (e) {- ToastEvent.show({- heading: 'Failed to backup data',- message: e.message,- type: 'error',- context: 'local'- });- return false;- }- }- });+ verifyUser(null, Backup.run);},desc: 'Backup your data to phone storage'},diff --git a/apps/mobile/src/views/Settings/functions.js b/apps/mobile/src/views/Settings/functions.jsnew file mode 100644index 000000000..9b24fe81e--- /dev/null+++ b/apps/mobile/src/views/Settings/functions.js@@ -0,0 +1,42 @@+import {presentDialog} from '../../components/Dialog/functions';+import {ToastEvent} from '../../services/EventManager';+import {db} from '../../utils/database';+import {sleep} from '../../utils/TimeUtils';++export async function verifyUser(context, onsuccess) {+ presentDialog({+ context: context,+ title: "Verify it's you",+ input: true,+ inputPlaceholder: 'Enter account password',+ paragraph: 'Please enter your account password',+ positiveText: 'Verify',+ secureTextEntry: true,+ positivePress: async value => {+ try {+ let verified = await db.user.verifyPassword(value);+ if (verified) {+ sleep(300).then(async () => {+ await onsuccess();+ });+ } else {+ ToastEvent.show({+ heading: 'Incorrect password',+ message: 'The account password you entered is incorrect',+ type: 'error',+ context: 'global'+ });+ return false;+ }+ } catch (e) {+ ToastEvent.show({+ heading: 'Failed to backup data',+ message: e.message,+ type: 'error',+ context: 'global'+ });+ return false;+ }+ }+ });+}diff --git a/apps/mobile/src/views/Settings/logout.js b/apps/mobile/src/views/Settings/logout.jsindex 40df0a31a..ae9a8098c 100644--- a/apps/mobile/src/views/Settings/logout.js+++ b/apps/mobile/src/views/Settings/logout.js@@ -1,301 +1,183 @@-import dayjs from 'dayjs';-import React, {useCallback, useEffect, useRef, useState} from 'react';-import {- Appearance,- Linking,- Platform,- ScrollView,- TouchableOpacity,- View-} from 'react-native';-import * as RNIap from 'react-native-iap';-import {enabled} from 'react-native-privacy-snapshot';-import Menu, {MenuItem} from 'react-native-reanimated-material-menu';+import React, {useRef, useState} from 'react';+import {View} from 'react-native';import AnimatedProgress from 'react-native-reanimated-progress-bar';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import ToggleSwitch from 'toggle-switch-react-native';-import {Button} from '../../components/Button';-import {Button as MButton} from '../../components/Button/index';-import {ContainerTopSection} from '../../components/Container/ContainerTopSection';import BaseDialog from '../../components/Dialog/base-dialog';import DialogButtons from '../../components/Dialog/dialog-buttons';import DialogContainer from '../../components/Dialog/dialog-container';import DialogHeader from '../../components/Dialog/dialog-header';import {presentDialog} from '../../components/Dialog/functions';-import {Issue} from '../../components/Github/issue';-import {Header as TopHeader} from '../../components/Header/index';import Input from '../../components/Input';import {PressableButton} from '../../components/PressableButton';import Seperator from '../../components/Seperator';-import {Card} from '../../components/SimpleList/card';import {Toast} from '../../components/Toast';import Heading from '../../components/Typography/Heading';import Paragraph from '../../components/Typography/Paragraph';import {useTracked} from '../../provider';-import {Actions} from '../../provider/Actions';-import {- useMessageStore,- useSettingStore,- useUserStore-} from '../../provider/stores';-import Backup from '../../services/Backup';+import {useUserStore} from '../../provider/stores';import BiometricService from '../../services/BiometricService';-import {DDS} from '../../services/DeviceDetection';-import {- eSendEvent,- eSubscribeEvent,- eUnSubscribeEvent,- openVault,- presentSheet,- ToastEvent-} from '../../services/EventManager';-import Navigation from '../../services/Navigation';-import Notifications from '../../services/Notifications';-import PremiumService from '../../services/PremiumService';-import SettingsService from '../../services/SettingsService';-import Sync from '../../services/Sync';-import {- AndroidModule,- APP_VERSION,- InteractionManager,- MenuItemsList,- SUBSCRIPTION_PROVIDER,- SUBSCRIPTION_STATUS,- SUBSCRIPTION_STATUS_STRINGS-} from '../../utils';-import {- ACCENT,- COLOR_SCHEME,- COLOR_SCHEME_DARK,- COLOR_SCHEME_LIGHT,- setColorScheme-} from '../../utils/Colors';-import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils';+import {ToastEvent} from '../../services/EventManager';import {db} from '../../utils/database';-import {- eCloseProgressDialog,- eOpenLoginDialog,- eOpenPremiumDialog,- eOpenProgressDialog,- eOpenRecoveryKeyDialog,- eOpenRestoreDialog,- eScrollEvent,- eUpdateSearchState-} from '../../utils/Events';-import {openLinkInBrowser} from '../../utils/functions';-import {MMKV} from '../../utils/mmkv';-import {tabBarRef} from '../../utils/Refs';-import {pv, SIZE} from '../../utils/SizeUtils';+import {SIZE} from '../../utils/SizeUtils';import Storage from '../../utils/storage';import {sleep} from '../../utils/TimeUtils';const AccoutLogoutSection = () => {- const [state, dispatch] = useTracked();- const {colors} = state;- const user = useUserStore(state => state.user);- const [visible, setVisible] = useState(false);- const [deleteAccount, setDeleteAccount] = useState(false);- const [loading, setLoading] = useState(false);- const passwordValue = useRef();- const pwdInput = useRef();-- return !user ? null : (- <>- {loading && (- <BaseDialog visible={true}>- <View- style={{- width: '100%',- height: '100%',- backgroundColor: colors.bg,- justifyContent: 'center',- alignItems: 'center'- }}>- <Heading color={colors.pri} size={SIZE.lg}>- Logging out- </Heading>- <Paragraph color={colors.icon}>- Please wait while log out and clear app data.- </Paragraph>- <View- style={{- flexDirection: 'row',- height: 10,- width: 100,- marginTop: 15- }}>- <AnimatedProgress fill={colors.accent} total={8} current={8} />- </View>- </View>- </BaseDialog>- )}-- {visible && (- <BaseDialog visible={true}>- <DialogContainer>- <DialogHeader- title="Logout"- paragraph="Clear all your data and reset the app."- padding={12}- />- <Seperator />- <DialogButtons- positiveTitle="Logout"- negativeTitle="Cancel"- onPressNegative={() => setVisible(false)}- onPressPositive={async () => {- try {- setVisible(false);- setLoading(true);- await sleep(10);- await db.user.logout();- await BiometricService.resetCredentials();- await Storage.write('introCompleted', 'true');- setLoading(false);- } catch (e) {- setVisible(false);- setLoading(false);- }- }}- />- </DialogContainer>- </BaseDialog>- )}-- {deleteAccount && (- <BaseDialog- onRequestClose={() => {- setDeleteAccount(false);- passwordValue.current = null;- }}- visible={true}>- <DialogContainer>- <DialogHeader- title="Delete account"- paragraph="All your data will be removed- permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE."- paragraphColor={colors.red}- padding={12}- />-- <Seperator half />-- <View- style={{- paddingHorizontal: 12- }}>- <Input- placeholder="Enter account password"- fwdRef={pwdInput}- onChangeText={v => {- passwordValue.current = v;- }}- secureTextEntry={true}- />- </View>-- <DialogButtons- positiveTitle="Delete"- positiveType="errorShade"- onPressPositive={async () => {- if (!passwordValue.current) {- ToastEvent.show({- heading: 'Account Password is required',- type: 'error',- context: 'local'- });- return;- }- try {- await db.user.deleteUser(passwordValue.current);- } catch (e) {- ToastEvent.show({- heading: 'Failed to delete account',- message: e.message,- type: 'error',- context: 'local'- });- }- close();- }}- onPressNegative={() => {- setDeleteAccount(false);- passwordValue.current = null;- }}- />- </DialogContainer>- <Toast context="local" />- </BaseDialog>- )}-- {[- {- name: 'Logout',- func: async () => {- setVisible(true);- }- }- ].map((item, index) => (- <PressableButton- onPress={item.func}- key={item.name}- type="gray"- customStyle={{- height: 50,- borderTopWidth: index === 0 ? 1 : 0,- borderTopColor: colors.nav,- width: '100%',- alignItems: 'flex-start',- paddingHorizontal: 12,- marginTop: index === 0 ? 25 : 0,- borderRadius: 0- }}>- <Heading- color={item.name === 'Logout' ? colors.pri : colors.red}- style={{- fontSize: SIZE.md- }}>- {item.name}- </Heading>- </PressableButton>- ))}-- <PressableButton- onPress={() => {- setDeleteAccount(true);- passwordValue.current = null;- }}- type="error"- customStyle={{- borderWidth: 1,- borderRadius: 5,- paddingVertical: 10,- width: '95%',- alignItems: 'flex-start',- paddingHorizontal: 12,- marginTop: 25,- borderColor: colors.red- }}>- <Heading- color={colors.red}- style={{- fontSize: SIZE.md- }}>- Delete account- </Heading>- <Paragraph- style={{- flexWrap: 'wrap',- flexBasis: 1- }}- color={colors.red}>- Your account will be deleted and all your data will be removed- permanantly. Make sure you have saved backup of your notes. This- action is IRREVERSIBLE.- </Paragraph>- </PressableButton>- </>- );- };+ const [state, dispatch] = useTracked();+ const {colors} = state;+ const user = useUserStore(state => state.user);+ const [loading, setLoading] = useState(false);+ const passwordValue = useRef();- export default AccoutLogoutSection;\ No newline at end of file+ return user ? null : (+ <>+ {loading && (+ <BaseDialog visible={true}>+ <View+ style={{+ width: '100%',+ height: '100%',+ backgroundColor: colors.bg,+ justifyContent: 'center',+ alignItems: 'center'+ }}>+ <Heading color={colors.pri} size={SIZE.lg}>+ Logging out+ </Heading>+ <Paragraph color={colors.icon}>+ Please wait while log out and clear app data.+ </Paragraph>+ <View+ style={{+ flexDirection: 'row',+ height: 10,+ width: 100,+ marginTop: 15+ }}>+ <AnimatedProgress fill={colors.accent} total={8} current={8} />+ </View>+ </View>+ </BaseDialog>+ )}++ {[+ {+ name: 'Logout',+ func: async () => {+ presentDialog({+ title: 'Logout',+ paragraph: 'Clear all your data and reset the app.',+ positiveText: 'Logout',+ positivePress: async () => {+ try {+ setLoading(true);+ await sleep(10);+ await db.user.logout();+ await BiometricService.resetCredentials();+ await Storage.write('introCompleted', 'true');+ setLoading(false);+ } catch (e) {+ setLoading(false);+ }+ }+ });+ }+ }+ ].map((item, index) => (+ <PressableButton+ onPress={item.func}+ key={item.name}+ type="gray"+ customStyle={{+ height: 50,+ borderTopWidth: index === 0 ? 1 : 0,+ borderTopColor: colors.nav,+ width: '100%',+ alignItems: 'flex-start',+ paddingHorizontal: 12,+ marginTop: index === 0 ? 25 : 0,+ borderRadius: 0+ }}>+ <Heading+ color={item.name === 'Logout' ? colors.pri : colors.red}+ style={{+ fontSize: SIZE.md+ }}>+ {item.name}+ </Heading>+ </PressableButton>+ ))}++ <PressableButton+ onPress={() => {+ presentDialog({+ title: 'Delete account',+ paragraphColor: colors.red,+ paragraph:+ 'All your data will be removed permanantly. Make sure you have saved backup of your notes. This action is IRREVERSIBLE.',+ positiveType: 'errorShade',+ input: true,+ inputPlaceholder: 'Enter account password',+ positiveText: 'Delete',+ positivePress: async value => {+ try {+ let verified = await db.user.verifyPassword(value);+ if (verified) {+ setLoading(true);+ await sleep(10);+ await db.user.deleteUser(passwordValue.current);+ await BiometricService.resetCredentials();+ await Storage.write('introCompleted', 'true');+ setLoading(false);+ } else {+ ToastEvent.show({+ heading: 'Incorrect password',+ message: 'The account password you entered is incorrect',+ type: 'error',+ context: 'global'+ });+ }+ } catch (e) {+ ToastEvent.show({+ heading: 'Failed to delete account',+ message: e.message,+ type: 'error',+ context: 'global'+ });+ }+ }+ });+ }}+ type="error"+ customStyle={{+ borderWidth: 1,+ borderRadius: 5,+ paddingVertical: 10,+ width: '95%',+ alignItems: 'flex-start',+ paddingHorizontal: 12,+ marginTop: 25,+ borderColor: colors.red+ }}>+ <Heading+ color={colors.red}+ style={{+ fontSize: SIZE.md+ }}>+ Delete account+ </Heading>+ <Paragraph+ style={{+ flexWrap: 'wrap',+ flexBasis: 1+ }}+ color={colors.red}>+ Your account will be deleted and all your data will be removed+ permanantly. Make sure you have saved backup of your notes. This+ action is IRREVERSIBLE.+ </Paragraph>+ </PressableButton>+ </>+ );+};++export default AccoutLogoutSection;diff --git a/apps/mobile/src/views/Settings/usersection.js b/apps/mobile/src/views/Settings/usersection.jsindex 5393b2a66..002c71e6e 100644--- a/apps/mobile/src/views/Settings/usersection.js+++ b/apps/mobile/src/views/Settings/usersection.js@@ -1,17 +1,11 @@import dayjs from 'dayjs';-import React, {useRef, useState} from 'react';+import React from 'react';import {Linking, Platform, View} from 'react-native';import * as RNIap from 'react-native-iap';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {Button} from '../../components/Button';-import BaseDialog from '../../components/Dialog/base-dialog';-import DialogButtons from '../../components/Dialog/dialog-buttons';-import DialogContainer from '../../components/Dialog/dialog-container';-import DialogHeader from '../../components/Dialog/dialog-header';-import Input from '../../components/Input';import Seperator from '../../components/Seperator';import {Card} from '../../components/SimpleList/card';-import {Toast} from '../../components/Toast';import Heading from '../../components/Typography/Heading';import Paragraph from '../../components/Typography/Paragraph';import {useTracked} from '../../provider';@@ -28,7 +22,6 @@ import {SUBSCRIPTION_STATUS,SUBSCRIPTION_STATUS_STRINGS} from '../../utils';-import {db} from '../../utils/database';import {eCloseProgressDialog,eOpenPremiumDialog,@@ -36,7 +29,8 @@ import {} from '../../utils/Events';import {SIZE} from '../../utils/SizeUtils';import {sleep} from '../../utils/TimeUtils';-import { CustomButton } from './button';+import {CustomButton} from './button';+import {verifyUser} from './functions';const getTimeLeft = t2 => {let daysRemaining = dayjs(t2).diff(dayjs(), 'days');@@ -52,48 +46,11 @@ const SettingsUserSection = () => {const user = useUserStore(state => state.user);const messageBoardState = useMessageStore(state => state.message);- const [verifyUser, setVerifyUser] = useState(false);const subscriptionDaysLeft =user && getTimeLeft(parseInt(user.subscription?.expiry));const isExpired = user && subscriptionDaysLeft.time < 0;const expiryDate = dayjs(user?.subscription?.expiry).format('MMMM D, YYYY');const startDate = dayjs(user?.subscription?.start).format('MMMM D, YYYY');- const passwordVerifyValue = useRef();- const input = useRef();-- const tryVerification = async () => {- if (!passwordVerifyValue.current) {- ToastEvent.show({- heading: 'Account Password is required',- type: 'error',- context: 'local'- });- return;- }- try {- let verify = await db.user.verifyPassword(passwordVerifyValue.current);- if (verify) {- setVerifyUser(false);- passwordVerifyValue.current = null;- await sleep(300);- eSendEvent(eOpenRecoveryKeyDialog);- } else {- ToastEvent.show({- heading: 'Incorrect password',- message: 'Please enter the correct password to save recovery key.',- type: 'error',- context: 'local'- });- }- } catch (e) {- ToastEvent.show({- heading: 'Incorrect password',- message: e.message,- type: 'error',- context: 'local'- });- }- };const manageSubscription = () => {if (!user.isEmailConfirmed) {@@ -314,59 +271,14 @@ const SettingsUserSection = () => {</View></View>- {verifyUser && (- <BaseDialog- onRequestClose={() => {- setVerifyUser(false);- passwordVerifyValue.current = null;- }}- onShow={() => {- setTimeout(() => {- input.current?.focus();- }, 300);- }}- statusBarTranslucent={false}- visible={true}>- <DialogContainer>- <DialogHeader- title="Verify it's you"- paragraph="Enter your account password to save your data recovery key."- padding={12}- />- <Seperator half />- <View- style={{- paddingHorizontal: 12- }}>- <Input- fwdRef={input}- placeholder="Enter account password"- onChangeText={v => {- passwordVerifyValue.current = v;- }}- onSubmit={tryVerification}- secureTextEntry={true}- />- </View>-- <DialogButtons- positiveTitle="Verify"- onPressPositive={tryVerification}- onPressNegative={() => {- setVerifyUser(false);- passwordVerifyValue.current = null;- }}- />- </DialogContainer>- <Toast context="local" />- </BaseDialog>- )}-{[{name: 'Save data recovery key',func: async () => {- setVerifyUser(true);+ verifyUser(null, async () => {+ await sleep(300);+ eSendEvent(eOpenRecoveryKeyDialog);+ });},desc: 'Recover your data using the recovery key if your password is lost.'},