Skip to content

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

fix notes not rerendering

ammarahm-ed8d32359d31f4
diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.js
index 20b90c47a..960fdeb1b 100644
--- a/apps/mobile/src/components/NoteItem/index.js
+++ b/apps/mobile/src/components/NoteItem/index.js
@@ -18,6 +18,9 @@ const h = Dimensions.get('window').height;
export default class NoteItem extends React.Component {
constructor(props) {
super(props);
+ this.cipher = {
+ value: false,
+ };
this.state = {
unlockNote: false,
vaultDialog: false,
@@ -30,10 +33,25 @@ export default class NoteItem extends React.Component {
}
shouldComponentUpdate(nextProps, nextState) {
- return (
- JSON.stringify(nextProps) !== JSON.stringify(this.props) ||
- nextState !== this.state
- );
+ if (nextProps.item.locked !== this.cipher.value) {
+ return true;
+ } else {
+ return (
+ JSON.stringify(nextProps) !== JSON.stringify(this.props) ||
+ nextState !== this.state
+ );
+ }
+ }
+ componentDidUpdate() {
+ this.cipher.value = this.props.item.locked ? true : false;
+ }
+ componentWillUnmount() {
+ this.cipher.value = false;
+ }
+ componentDidMount() {
+ if (this.props.item.locked) {
+ this.cipher.value = true;
+ }
}
render() {
@@ -49,8 +67,7 @@ export default class NoteItem extends React.Component {
update,
index,
} = this.props;
-
- console.log('rerendering' + index);
+ console.log('rendering', index);
return (
<View
style={[
@@ -69,20 +86,6 @@ export default class NoteItem extends React.Component {
},
customStyle ? customStyle : {},
]}>
- <VaultDialog
- close={() => {
- this.setState({
- vaultDialog: false,
- unlock: false,
- isPerm: false,
- });
- }}
- note={item}
- perm={isPerm}
- openedToUnlock={unlock}
- visible={vaultDialog}
- />
-
{pinned ? (
<View
style={{
diff --git a/apps/mobile/src/components/NotesList/index.js b/apps/mobile/src/components/NotesList/index.js
index efe0e7549..b343f41c6 100644
--- a/apps/mobile/src/components/NotesList/index.js
+++ b/apps/mobile/src/components/NotesList/index.js
@@ -1,18 +1,15 @@
-import React, {useState, useEffect} from 'react';
+import React from 'react';
import {View, Text, FlatList, Platform, SectionList} from 'react-native';
import {SIZE, WEIGHT} from '../../common/common';
import NoteItem from '../NoteItem';
-import {useAppContext} from '../../provider/useAppContext';
import {NotesPlaceHolder} from '../ListPlaceholders';
import {slideRight, slideLeft} from '../../utils/animations';
import {w} from '../../utils/utils';
import SelectionWrapper from '../SelectionWrapper';
-import ActionSheet from '../ActionSheet';
-import {ActionSheetComponent} from '../ActionSheetComponent';
+
import {useTracked} from '../../provider';
export const NotesList = ({
- notes,
onScroll,
isSearch = false,
isGrouped = false,
@@ -20,7 +17,7 @@ export const NotesList = ({
}) => {
const [state, dispatch] = useTracked();
const {colors, selectionMode, pinned, selectedItemsList} = state;
-
+ const notes = [...state.notes];
///
const updateSelectionList = () => {};
const changeSelectionMode = () => {};