Skip to content

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

fix views not updating

ammarahm-edc20e36d29268
diff --git a/apps/mobile/src/utils/storage.js b/apps/mobile/src/utils/storage.js
index 31e4399b4..d98f34c21 100644
--- a/apps/mobile/src/utils/storage.js
+++ b/apps/mobile/src/utils/storage.js
@@ -1,5 +1,6 @@
import {NativeModules} from 'react-native';
import FastStorage from 'react-native-fast-storage';
+
var Aes = NativeModules.Aes;
async function read(key) {
@@ -25,12 +26,16 @@ function encrypt(password, data) {
let key;
return Aes.pbkdf2('password', 'salt', 5000, 256).then(aes => {
key = aes;
- console.log(aes);
return Aes.randomKey(16).then(iv => {
- return Aes.encrypt(data, key, iv).then(cipher => ({
- cipher,
- iv,
- }));
+ return Aes.encrypt(data, key, iv).then(cipher => {
+ return Aes.hmac256(cipher, key).then(hash => {
+ return {
+ hash,
+ cipher,
+ iv,
+ };
+ });
+ });
});
});
}
@@ -40,8 +45,13 @@ function decrypt(password, data) {
return Aes.pbkdf2(password, 'salt', 5000, 256).then(aes => {
key = aes;
- return Aes.decrypt(data.cipher, key, data.iv).then(e => {
- return e;
+ return Aes.hmac256(data.cipher, key).then(hash => {
+ if (hash !== data.hash) {
+ throw new Error('Wrong password');
+ }
+ return Aes.decrypt(data.cipher, key, data.iv).then(e => {
+ return e;
+ });
});
});
}
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index e4ce492b1..ae2b3a925 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -11,18 +11,23 @@ import {ACTIONS} from '../../provider/actions';
import {eSendEvent} from '../../services/eventManager';
import {eScrollEvent} from '../../services/events';
import {ToastEvent, w} from '../../utils/utils';
+import {useIsFocused} from 'react-navigation-hooks';
export const Favorites = ({navigation}) => {
const [state, dispatch] = useTracked();
const {colors, selectionMode, favorites} = state;
const [refreshing, setRefreshing] = useState(false);
+ const isFocused = useIsFocused();
+
useEffect(() => {
- dispatch({
- type: ACTIONS.CURRENT_SCREEN,
- screen: 'favorites',
- });
- dispatch({type: ACTIONS.FAVORITES});
- }, []);
+ if (isFocused) {
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'favorites',
+ });
+ dispatch({type: ACTIONS.FAVORITES});
+ }
+ }, [isFocused]);
const onScroll = event => {
let y = event.nativeEvent.contentOffset.y;
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 11c28b872..f8251b734 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -40,39 +40,31 @@ export const Folders = ({navigation}) => {
};
useEffect(() => {
- dispatch({type: ACTIONS.PINNED});
- }, []);
-
- useEffect(() => {
- eSendEvent(eScrollEvent, 0);
- dispatch({type: ACTIONS.NOTEBOOKS});
-
if (isFocused) {
+ dispatch({type: ACTIONS.PINNED});
+ dispatch({type: ACTIONS.NOTEBOOKS});
dispatch({
type: ACTIONS.CURRENT_SCREEN,
screen: 'notebooks',
});
}
+ }, [isFocused]);
+ useEffect(() => {
+ eSendEvent(eScrollEvent, 0);
let backhandler;
- if (isFocused) {
- backhandler = BackHandler.addEventListener(
- 'hardwareBackPress',
- handleBackPress,
- );
- } else {
- if (backhandler) {
- backhandler.remove();
- backhandler = null;
- }
- }
+
+ backhandler = BackHandler.addEventListener(
+ 'hardwareBackPress',
+ handleBackPress,
+ );
return () => {
if (!backhandler) return;
backhandler.remove();
backhandler = null;
};
- }, [isFocused]);
+ }, []);
const params = navigation.state.params;
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 127794dec..b107322e8 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -35,7 +35,6 @@ export const Notebook = ({navigation}) => {
allTopics = db.notebooks.notebook(navigation.state.params.notebook.id).data
.topics;
- console.log(allTopics);
notebook = db.notebooks.notebook(navigation.state.params.notebook.id);
@@ -67,13 +66,15 @@ export const Notebook = ({navigation}) => {
type: ACTIONS.CURRENT_SCREEN,
screen: 'notebook',
});
+ onLoad();
}
-
+ }, [isFocused]);
+ useEffect(() => {
eSubscribeEvent(eMoveNoteDialogNavigateBack, handleBackPress);
return () => {
eUnSubscribeEvent(eMoveNoteDialogNavigateBack, handleBackPress);
};
- }, [isFocused]);
+ }, []);
const onScroll = event => {
let y = event.nativeEvent.contentOffset.y;
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index c00787de7..85ca828b7 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -18,6 +18,7 @@ import {ToastEvent} from '../../utils/utils';
import {eSendEvent} from '../../services/eventManager';
import {eScrollEvent} from '../../services/events';
import {NotesPlaceHolder} from '../../components/ListPlaceholders';
+import {useIsFocused} from 'react-navigation-hooks';
export const Notes = ({navigation}) => {
const [state, dispatch] = useTracked();
@@ -25,6 +26,7 @@ export const Notes = ({navigation}) => {
const allNotes = state.notes;
const [notes, setNotes] = useState([]);
const [refreshing, setRefreshing] = useState(false);
+ const isFocused = useIsFocused();
let params = navigation.state ? navigation.state.params : null;
useEffect(() => {
@@ -34,6 +36,15 @@ export const Notes = ({navigation}) => {
};
}
}, []);
+ useEffect(() => {
+ if (isFocused) {
+ init();
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: param.type,
+ });
+ }
+ }, [isFocused, allNotes, colorNotes]);
const init = () => {
eSendEvent(eScrollEvent, 0);
@@ -49,18 +60,12 @@ export const Notes = ({navigation}) => {
.notebook(params.notebookId)
.topics.topic(params.title).all;
- console.log(allNotes, 'here getting topics');
-
if (allNotes && allNotes.length > 0) {
setNotes(allNotes);
}
}
};
- useEffect(() => {
- init();
- }, [allNotes, colorNotes]);
-
const _renderItem = ({item, index}) => (
<SelectionWrapper
index={index}
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index c89f3730e..d0fd95388 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -15,6 +15,7 @@ import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService';
import {ToastEvent} from '../../utils/utils';
+import {useIsFocused} from 'react-navigation-hooks';
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
@@ -22,13 +23,16 @@ export const Tags = ({navigation}) => {
const [state, dispatch] = useTracked();
const {colors, tags, selectionMode} = state;
const [refreshing, setRefreshing] = useState(false);
+ const isFocused = useIsFocused();
useEffect(() => {
- dispatch({type: ACTIONS.TAGS});
- dispatch({
- type: ACTIONS.CURRENT_SCREEN,
- screen: 'tags',
- });
- }, []);
+ if (isFocused) {
+ dispatch({type: ACTIONS.TAGS});
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'tags',
+ });
+ }
+ }, [isFocused]);
return (
<Container
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 40a06407a..d3613e598 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -13,21 +13,26 @@ import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions';
import {w, ToastEvent} from '../../utils/utils';
import SelectionWrapper from '../../components/SelectionWrapper';
+import {useIsFocused} from 'react-navigation-hooks';
export const Trash = ({navigation}) => {
const [state, dispatch] = useTracked();
const {colors, selectionMode, trash} = state;
const [refreshing, setRefreshing] = useState(false);
+ const isFocused = useIsFocused();
+
useEffect(() => {
- dispatch({
- type: ACTIONS.TRASH,
- });
+ if (isFocused) {
+ dispatch({
+ type: ACTIONS.TRASH,
+ });
- dispatch({
- type: ACTIONS.CURRENT_SCREEN,
- screen: 'trash',
- });
- }, []);
+ dispatch({
+ type: ACTIONS.CURRENT_SCREEN,
+ screen: 'trash',
+ });
+ }
+ }, [isFocused]);
const _renderItem = ({item, index}) => (
<SelectionWrapper colors={colors} item={item}>