Skip to content

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

fix: useEffect called with no Deps

ammarahm-ed2814c377a3d3
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 3e44d06f0..1d41acc7e 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,4 +1,5 @@
import React, {useCallback, useEffect} from 'react';
+import * as Keychain from 'react-native-keychain';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider';
@@ -7,12 +8,10 @@ import {DDS} from '../../services/DeviceDetection';
import {eSendEvent} from '../../services/EventManager';
import SearchService from '../../services/SearchService';
import {scrollRef} from '../../utils';
-import {
- eOnLoadNote,
- eScrollEvent,
- eUpdateSearchState,
-} from '../../utils/Events';
+import {eOnLoadNote, eScrollEvent} from '../../utils/Events';
import {tabBarRef} from '../../utils/Refs';
+import Storage from '../../utils/storage';
+import * as Sentry from '@sentry/react-native';
export const Home = ({navigation}) => {
const [state, dispatch] = useTracked();
@@ -50,7 +49,7 @@ export const Home = ({navigation}) => {
navigation.removeListener('focus', onFocus);
navigation.removeListener('blur', onBlur);
};
- });
+ },[]);
useEffect(() => {
if (navigation.isFocused()) {
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 040cc8262..95bb92759 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -61,7 +61,7 @@ export const Notebook = ({route, navigation}) => {
eSendEvent(eScrollEvent, {name: params.title, type: 'back'});
navigation.removeListener('focus', onFocus);
};
- });
+ },[]);
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 26d718d2b..97336b395 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -107,7 +107,7 @@ export const Notes = ({route, navigation}) => {
navigation.removeListener('focus', onFocus);
navigation.removeListener('blur', onBlur);
};
- });
+ },[]);
useEffect(() => {
if (navigation.isFocused()) {
diff --git a/apps/mobile/src/views/Search/index.js b/apps/mobile/src/views/Search/index.js
index bd04fbbf8..c544244a2 100644
--- a/apps/mobile/src/views/Search/index.js
+++ b/apps/mobile/src/views/Search/index.js
@@ -29,7 +29,7 @@ export const Search = ({route, navigation}) => {
return () => {
navigation.removeListener('focus', onFocus);
};
- });
+ },[]);
return (
<>
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index fb4b842a0..d3fa36ea5 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -18,10 +18,17 @@ import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import Backup from '../../services/Backup';
import {DDS} from '../../services/DeviceDetection';
-import {eSendEvent, ToastEvent} from '../../services/EventManager';
+import {
+ eSendEvent,
+ eSubscribeEvent,
+ eUnSubscribeEvent,
+ openVault,
+ ToastEvent,
+} from '../../services/EventManager';
import NavigationService from '../../services/Navigation';
import PremiumService from '../../services/PremiumService';
import SettingsService from '../../services/SettingsService';
+import * as Keychain from 'react-native-keychain';
import {
AndroidModule,
dWidth,
@@ -58,6 +65,11 @@ let menuRef = createRef();
export const Settings = ({navigation}) => {
const [state, dispatch] = useTracked();
const {colors, user, settings} = state;
+ const [vaultStatus, setVaultStatus] = React.useState({
+ exists: false,
+ biometryEnrolled: false,
+ isBiometryAvailable: false,
+ });
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent);
dispatch({type: Actions.THEME, colors: newColors});
@@ -94,14 +106,45 @@ export const Settings = ({navigation}) => {
});
}, []);
+ const checkVaultStatus = useCallback(() => {
+ db.vault.add('check_no_vault').catch(async (e) => {
+ console.log(e);
+ let biometry = await Keychain.getSupportedBiometryType();
+ let fingerprint = await Keychain.hasInternetCredentials('nn_vault');
+ console.log(biometry, fingerprint);
+ let available = false;
+ if (
+ biometry === Keychain.BIOMETRY_TYPE.FINGERPRINT ||
+ biometry === Keychain.BIOMETRY_TYPE.TOUCH_ID
+ ) {
+ available = true;
+ }
+ if (e.message === db.vault.ERRORS.noVault) {
+ setVaultStatus({
+ exists: false,
+ biometryEnrolled: fingerprint,
+ isBiometryAvailable: available,
+ });
+ } else {
+ setVaultStatus({
+ exists: true,
+ biometryEnrolled: fingerprint,
+ isBiometryAvailable: available,
+ });
+ }
+ });
+ });
+
useEffect(() => {
- console.log(user);
+ checkVaultStatus();
+ eSubscribeEvent('vaultUpdated', () => checkVaultStatus());
navigation.addListener('focus', onFocus);
return () => {
eSendEvent(eScrollEvent, {name: 'Settings', type: 'back'});
+ eUnSubscribeEvent('vaultUpdated', () => checkVaultStatus());
navigation.removeListener('focus', onFocus);
};
- });
+ }, []);
const getTimeLeft = (t2) => {
let d1 = new Date(Date.now());
@@ -796,15 +839,11 @@ export const Settings = ({navigation}) => {
<CustomButton
key="privacyMode"
- title={
- settings.privacyScreen
- ? 'Privacy Mode Enabled'
- : 'Privacy Mode Disabled'
- }
+ title="Privacy Mode"
tagline={
settings.privacyScreen
- ? 'App contents will be hidden when app goes in background and screenshots will be disabled'
- : 'App contents can be seen when app goes in background and screenshots will be disabled'
+ ? 'App contents will be hidden when app goes in background and screenshots are disabled'
+ : 'App contents can be seen when app goes in background and screenshots are enabled'
}
onPress={() => {
AndroidModule.setSecureMode(!settings.privacyScreen);
@@ -822,6 +861,50 @@ export const Settings = ({navigation}) => {
}
/>
+ {vaultStatus.exists ? (
+ vaultStatus.isBiometryAvailable ? (
+ <CustomButton
+ key="fingerprintVaultUnlock"
+ title="Unlock vault with Fingerprint"
+ tagline={
+ !vaultStatus.biometryEnrolled
+ ? 'Enable access to the vault with fingerprint.'
+ : 'You can access the vault with fingerprint.'
+ }
+ onPress={() => {
+ openVault({
+ item:{},
+ fingerprintAccess:true,
+ novault:true
+ })
+ }}
+ maxWidth="90%"
+ customComponent={
+ <Icon
+ size={SIZE.xl}
+ color={
+ vaultStatus.biometryEnrolled ? colors.accent : colors.icon
+ }
+ name={
+ vaultStatus.biometryEnrolled
+ ? 'toggle-switch'
+ : 'toggle-switch-off'
+ }
+ />
+ }
+ />
+ ) : null
+ ) : (
+ <CustomButton
+ key="createVault"
+ title="Create Vault"
+ tagline="Adds an extra layer of security for most important notes."
+ onPress={() => {
+ openVault({}, false);
+ }}
+ />
+ )}
+
{/* <CustomButton
key="screenshotMode"
title={
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index e39f41a2a..d1faa5de9 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -38,7 +38,7 @@ export const Tags = ({route, navigation}) => {
eSendEvent(eScrollEvent, {name:'Tags', type: 'back'});
navigation.removeListener('focus', onFocus);
};
- });
+ },[]);
useEffect(() => {
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 5aead1f19..394fbfb17 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -43,7 +43,7 @@ export const Trash = ({route, navigation}) => {
eSendEvent(eScrollEvent, {name:'Trash', type: 'back'});
navigation.removeListener('focus', onFocus);
};
- });
+ },[]);
useEffect(() => {
if (navigation.isFocused()) {