mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
fix views not updating
This commit is contained in:
@@ -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;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
useEffect(() => {
|
||||
dispatch({
|
||||
type: ACTIONS.TRASH,
|
||||
});
|
||||
const isFocused = useIsFocused();
|
||||
|
||||
dispatch({
|
||||
type: ACTIONS.CURRENT_SCREEN,
|
||||
screen: 'trash',
|
||||
});
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (isFocused) {
|
||||
dispatch({
|
||||
type: ACTIONS.TRASH,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: ACTIONS.CURRENT_SCREEN,
|
||||
screen: 'trash',
|
||||
});
|
||||
}
|
||||
}, [isFocused]);
|
||||
|
||||
const _renderItem = ({item, index}) => (
|
||||
<SelectionWrapper colors={colors} item={item}>
|
||||
|
||||
Reference in New Issue
Block a user