Skip to content

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

fix unnecessary renders

ammarahm-eda8001b138415
diff --git a/apps/mobile/src/components/NoteItem/wrapper.js b/apps/mobile/src/components/NoteItem/wrapper.js
index 951517aa4..442a672d9 100644
--- a/apps/mobile/src/components/NoteItem/wrapper.js
+++ b/apps/mobile/src/components/NoteItem/wrapper.js
@@ -99,7 +99,11 @@ export const NoteWrapper = React.memo(
);
},
(prev, next) => {
-
+
+ if (prev.item?.dateEdited !== next.item?.dateEdited) {
+ return false;
+ }
+
if (
JSON.stringify(prev.tags) !== JSON.stringify(next.tags)
) {
diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js
index e98c608b3..33c197d4f 100644
--- a/apps/mobile/src/components/NotebookItem/index.js
+++ b/apps/mobile/src/components/NotebookItem/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import {View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {notesnook} from '../../../e2e/test.ids';
@@ -7,7 +7,7 @@ import {useSettingStore} from '../../provider/stores';
import {eSendEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
import {getTotalNotes, history} from '../../utils';
-import {eOnNewTopicAdded, refreshNotesPage} from '../../utils/Events';
+import {refreshNotesPage} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
import {Button} from '../Button';
@@ -16,194 +16,195 @@ import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
export const NotebookItem = ({item, isTopic = false, notebookID, isTrash}) => {
- const [state] = useTracked();
- const {colors} = state;
- const settings = useSettingStore(state => state.settings);
- const compactMode = settings.notebooksListMode === 'compact';
+ const [state] = useTracked();
+ const {colors} = state;
+ const settings = useSettingStore(state => state.settings);
+ const compactMode = settings.notebooksListMode === 'compact';
- const topics = item.topics?.slice(0, 3) || [];
+ const topics = item.topics?.slice(0, 3) || [];
- const totalNotes = getTotalNotes(item);
- const showActionSheet = () => {
- let rowItems =
- item.type === 'topic'
- ? ['Edit Topic', 'Add Shortcut', 'Delete']
- : ['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete'];
- rowItems = isTrash ? ['Restore', 'PermDelete'] : rowItems;
+ const totalNotes = getTotalNotes(item);
+ const showActionSheet = () => {
+ let rowItems =
+ item.type === 'topic'
+ ? ['Edit Topic', 'Add Shortcut', 'Delete']
+ : ['Edit Notebook', 'Pin', 'Add Shortcut', 'Delete'];
+ rowItems = isTrash ? ['Restore', 'PermDelete'] : rowItems;
- ActionSheetEvent(item, false, false, rowItems, {
- notebookID: notebookID
- });
- };
+ ActionSheetEvent(item, false, false, rowItems, {
+ notebookID: notebookID
+ });
+ };
- const navigateToTopic = topic => {
- if (history.selectedItemsList.length > 0) return;
- let routeName = 'NotesPage';
- let params = {...topic, menu: false, get: 'topics'};
- let headerState = {
- heading: topic.title,
- id: topic.id,
- type: topic.type
+ const navigateToTopic = topic => {
+ if (history.selectedItemsList.length > 0) return;
+ let routeName = 'NotesPage';
+ let params = {...topic, menu: false, get: 'topics'};
+ let headerState = {
+ heading: topic.title,
+ id: topic.id,
+ type: topic.type
+ };
+ eSendEvent(refreshNotesPage, params);
+ Navigation.navigate(routeName, params, headerState);
};
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate(routeName, params, headerState);
- };
- return (
- <>
- <View
- style={{
- flexGrow: 1,
- flexShrink: 1
- }}>
- <Heading
- size={SIZE.md}
- numberOfLines={1}
+
+ return (
+ <>
+ <View
style={{
- flexWrap: 'wrap'
+ flexGrow: 1,
+ flexShrink: 1
}}>
- {item.title}
- </Heading>
- {isTopic || !item.description || compactMode ? null : (
- <Paragraph
- size={SIZE.sm}
- numberOfLines={2}
+ <Heading
+ size={SIZE.md}
+ numberOfLines={1}
style={{
flexWrap: 'wrap'
}}>
- {item.description}
- </Paragraph>
- )}
+ {item.title}
+ </Heading>
+ {isTopic || !item.description || compactMode ? null : (
+ <Paragraph
+ size={SIZE.sm}
+ numberOfLines={2}
+ style={{
+ flexWrap: 'wrap'
+ }}>
+ {item.description}
+ </Paragraph>
+ )}
+
+ {isTopic || compactMode ? null : (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ flexWrap: 'wrap'
+ }}>
+ {topics.map(topic => (
+ <Button
+ title={topic.title}
+ key={topic.id}
+ height={null}
+ textStyle={{
+ fontWeight: 'normal',
+ fontFamily: null
+ }}
+ type="grayBg"
+ fontSize={SIZE.xs + 1}
+ icon="bookmark-outline"
+ textStyle={{
+ marginRight: 0
+ }}
+ iconSize={SIZE.sm}
+ style={{
+ borderRadius: 5,
+ maxWidth: 120,
+ borderWidth: 0.5,
+ paddingVertical: 2.5,
+ borderColor: colors.icon,
+ paddingHorizontal: 6,
+ marginVertical: 5,
+ marginRight: 5
+ }}
+ onPress={() => navigateToTopic(topic)}
+ />
+ ))}
+ </View>
+ )}
- {isTopic || compactMode ? null : (
<View
style={{
flexDirection: 'row',
+ justifyContent: 'flex-start',
alignItems: 'center',
- flexWrap: 'wrap'
- }}>
- {topics.map(topic => (
- <Button
- title={topic.title}
- key={topic.id}
- height={null}
- textStyle={{
- fontWeight: 'normal',
- fontFamily: null
- }}
- type="grayBg"
- fontSize={SIZE.xs + 1}
- icon="bookmark-outline"
- textStyle={{
- marginRight: 0
- }}
- iconSize={SIZE.sm}
- style={{
- borderRadius: 5,
- maxWidth: 120,
- borderWidth: 0.5,
- paddingVertical:2.5,
- borderColor: colors.icon,
- paddingHorizontal: 6,
- marginVertical: 5,
- marginRight: 5
- }}
- onPress={() => navigateToTopic(topic)}
- />
- ))}
- </View>
- )}
-
- <View
- style={{
- flexDirection: 'row',
- justifyContent: 'flex-start',
- alignItems: 'center',
- marginTop: 5,
- height: SIZE.md + 2
- }}>
- <Paragraph
- color={colors.accent}
- size={SIZE.xs + 1}
- style={{
- marginRight: 6
+ marginTop: 5,
+ height: SIZE.md + 2
}}>
- {isTopic ? 'Topic' : 'Notebook'}
- </Paragraph>
+ <Paragraph
+ color={colors.accent}
+ size={SIZE.xs + 1}
+ style={{
+ marginRight: 6
+ }}>
+ {isTopic ? 'Topic' : 'Notebook'}
+ </Paragraph>
- {isTrash ? (
- <>
+ {isTrash ? (
+ <>
+ <Paragraph
+ color={colors.icon}
+ size={SIZE.xs + 1}
+ style={{
+ textAlignVertical: 'center',
+ marginRight: 6
+ }}>
+ {'Deleted on ' +
+ new Date(item.dateDeleted).toISOString().slice(0, 10)}
+ </Paragraph>
+ <Paragraph
+ color={colors.accent}
+ size={SIZE.xs + 1}
+ style={{
+ textAlignVertical: 'center',
+ marginRight: 6
+ }}>
+ {item.itemType[0].toUpperCase() + item.itemType.slice(1)}
+ </Paragraph>
+ </>
+ ) : (
<Paragraph
color={colors.icon}
size={SIZE.xs + 1}
style={{
- textAlignVertical: 'center',
marginRight: 6
}}>
- {'Deleted on ' +
- new Date(item.dateDeleted).toISOString().slice(0, 10)}
+ {new Date(item.dateCreated).toDateString().substring(4)}
</Paragraph>
- <Paragraph
- color={colors.accent}
- size={SIZE.xs + 1}
- style={{
- textAlignVertical: 'center',
- marginRight: 6
- }}>
- {item.itemType[0].toUpperCase() + item.itemType.slice(1)}
- </Paragraph>
- </>
- ) : (
+ )}
<Paragraph
color={colors.icon}
size={SIZE.xs + 1}
style={{
marginRight: 6
}}>
- {new Date(item.dateCreated).toDateString().substring(4)}
+ {item && totalNotes > 1
+ ? totalNotes + ' notes'
+ : totalNotes === 1
+ ? totalNotes + ' note'
+ : '0 notes'}
</Paragraph>
- )}
- <Paragraph
- color={colors.icon}
- size={SIZE.xs + 1}
- style={{
- marginRight: 6
- }}>
- {item && totalNotes > 1
- ? totalNotes + ' notes'
- : totalNotes === 1
- ? totalNotes + ' note'
- : '0 notes'}
- </Paragraph>
- {item.pinned ? (
- <Icon
- style={{marginRight: 6}}
- name="pin"
- size={SIZE.sm}
- style={{
- marginRight: 10,
- marginTop: 2
- }}
- color={colors.accent}
- />
- ) : null}
+ {item.pinned ? (
+ <Icon
+ style={{marginRight: 6}}
+ name="pin"
+ size={SIZE.sm}
+ style={{
+ marginRight: 10,
+ marginTop: 2
+ }}
+ color={colors.accent}
+ />
+ ) : null}
+ </View>
</View>
- </View>
- <ActionIcon
- color={colors.heading}
- name="dots-horizontal"
- testID={notesnook.ids.notebook.menu}
- size={SIZE.xl}
- onPress={showActionSheet}
- customStyle={{
- justifyContent: 'center',
- height: 35,
- width: 35,
- borderRadius: 100,
- alignItems: 'center'
- }}
- />
- </>
- );
-};
+ <ActionIcon
+ color={colors.heading}
+ name="dots-horizontal"
+ testID={notesnook.ids.notebook.menu}
+ size={SIZE.xl}
+ onPress={showActionSheet}
+ customStyle={{
+ justifyContent: 'center',
+ height: 35,
+ width: 35,
+ borderRadius: 100,
+ alignItems: 'center'
+ }}
+ />
+ </>
+ );
+ }
\ No newline at end of file
diff --git a/apps/mobile/src/components/NotebookItem/wrapper.js b/apps/mobile/src/components/NotebookItem/wrapper.js
index a88961654..49b26058c 100644
--- a/apps/mobile/src/components/NotebookItem/wrapper.js
+++ b/apps/mobile/src/components/NotebookItem/wrapper.js
@@ -7,52 +7,64 @@ import {history} from '../../utils';
import {eOnNewTopicAdded, refreshNotesPage} from '../../utils/Events';
import SelectionWrapper from '../SelectionWrapper';
-export const NotebookWrapper = React.memo(({item, index}) => {
- const isTrash = item.type === 'trash';
- const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
+export const NotebookWrapper = React.memo(
+ ({item, index}) => {
+ const isTrash = item.type === 'trash';
+ const setSelectedItem = useSelectionStore(state => state.setSelectedItem);
- const onPress = () => {
- if (history.selectedItemsList.length > 0 && history.selectionMode) {
- setSelectedItem(item);
- return;
- } else {
- history.selectedItemsList = [];
- }
- let routeName = item.type === 'topic' ? 'NotesPage' : 'Notebook';
+ const onPress = () => {
+ if (history.selectedItemsList.length > 0 && history.selectionMode) {
+ setSelectedItem(item);
+ return;
+ } else {
+ history.selectedItemsList = [];
+ }
+ let routeName = item.type === 'topic' ? 'NotesPage' : 'Notebook';
- let params =
- item.type === 'topic'
- ? {...item, menu: false}
- : {
- menu: false,
- notebook: item,
- title: item.title
- };
- let headerState = {
- heading: item.title,
- id: item.id,
- type: item.type
+ let params =
+ item.type === 'topic'
+ ? {...item, menu: false}
+ : {
+ menu: false,
+ notebook: item,
+ title: item.title
+ };
+ let headerState = {
+ heading: item.title,
+ id: item.id,
+ type: item.type
+ };
+ if (item.type === 'topic') {
+ eSendEvent(refreshNotesPage, params);
+ } else {
+ eSendEvent(eOnNewTopicAdded, params);
+ }
+ Navigation.navigate(routeName, params, headerState);
};
- if (item.type === 'topic') {
- eSendEvent(refreshNotesPage, params);
- } else {
- eSendEvent(eOnNewTopicAdded, params);
- }
- Navigation.navigate(routeName, params, headerState);
- };
- return (
- <SelectionWrapper
- pinned={item.pinned}
- index={index}
- onPress={onPress}
- height={item.type === 'topic' ? 80 : 110}
- item={item}>
- <NotebookItem
- isTopic={item.type === 'topic'}
- item={item}
+ return (
+ <SelectionWrapper
+ pinned={item.pinned}
index={index}
- isTrash={isTrash}
- />
- </SelectionWrapper>
- );
-});
+ onPress={onPress}
+ height={item.type === 'topic' ? 80 : 110}
+ item={item}>
+ <NotebookItem
+ isTopic={item.type === 'topic'}
+ item={item}
+ index={index}
+ isTrash={isTrash}
+ />
+ </SelectionWrapper>
+ );
+ },
+ (prev, next) => {
+ if (prev.item?.dateEdited !== next.item?.dateEdited) {
+ return false;
+ }
+ if (JSON.stringify(prev.item) !== JSON.stringify(next.item)) {
+ return false;
+ }
+
+ return true;
+ }
+);
diff --git a/apps/mobile/src/components/TagItem/index.js b/apps/mobile/src/components/TagItem/index.js
index 09c8dcbed..e5bed724c 100644
--- a/apps/mobile/src/components/TagItem/index.js
+++ b/apps/mobile/src/components/TagItem/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useEffect} from 'react';
import {useWindowDimensions, View} from 'react-native';
import {notesnook} from '../../../e2e/test.ids';
import {PressableButton} from '../../components/PressableButton';
@@ -13,89 +13,101 @@ import {ActionSheetEvent} from '../DialogManager/recievers';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
-const TagItem = ({item, index}) => {
- const [state] = useTracked();
- const {colors} = state;
- const {fontScale} = useWindowDimensions();
- const onPress = () => {
- let params = {
- ...item,
- type: 'tag',
- get: 'tagged'
- };
+const TagItem = React.memo(
+ ({item, index}) => {
+ const [state] = useTracked();
+ const {colors} = state;
+ const {fontScale} = useWindowDimensions();
+ const onPress = () => {
+ let params = {
+ ...item,
+ type: 'tag',
+ get: 'tagged'
+ };
- eSendEvent(refreshNotesPage, params);
- Navigation.navigate('NotesPage', params, {
- heading: '#' + item.title,
- id: item.id,
- type: item.type
- });
- };
+ eSendEvent(refreshNotesPage, params);
+ Navigation.navigate('NotesPage', params, {
+ heading: '#' + item.title,
+ id: item.id,
+ type: item.type
+ });
+ };
- return (
- <PressableButton
- onPress={onPress}
- selectedColor={colors.nav}
- testID={notesnook.ids.tag.get(index)}
- alpha={!colors.night ? -0.02 : 0.02}
- opacity={1}
- customStyle={{
- paddingHorizontal: 12,
- height: 80 * fontScale,
- flexDirection: 'row',
- alignItems: 'center',
- borderBottomWidth: 1.5,
- borderBottomColor: colors.nav,
- width: '100%',
- justifyContent: 'space-between'
- }}>
- <View
- style={{
- maxWidth: '92%'
+ return (
+ <PressableButton
+ onPress={onPress}
+ selectedColor={colors.nav}
+ testID={notesnook.ids.tag.get(index)}
+ alpha={!colors.night ? -0.02 : 0.02}
+ opacity={1}
+ customStyle={{
+ paddingHorizontal: 12,
+ height: 80 * fontScale,
+ flexDirection: 'row',
+ alignItems: 'center',
+ borderBottomWidth: 1.5,
+ borderBottomColor: colors.nav,
+ width: '100%',
+ justifyContent: 'space-between'
}}>
- <Heading size={SIZE.md}>
- <Heading
- size={SIZE.md}
- style={{
- color: colors.accent
- }}>
- #
- </Heading>
- {db.tags.alias(item.id)}
- </Heading>
- <Paragraph
- color={colors.icon}
- size={SIZE.xs + 1}
+ <View
style={{
- marginTop: 5
+ maxWidth: '92%'
}}>
- {item && item.noteIds.length && item.noteIds.length > 1
- ? item.noteIds.length + ' notes'
- : item.noteIds.length === 1
- ? item.noteIds.length + ' note'
- : null}
- </Paragraph>
- </View>
+ <Heading size={SIZE.md}>
+ <Heading
+ size={SIZE.md}
+ style={{
+ color: colors.accent
+ }}>
+ #
+ </Heading>
+ {db.tags.alias(item.id)}
+ </Heading>
+ <Paragraph
+ color={colors.icon}
+ size={SIZE.xs + 1}
+ style={{
+ marginTop: 5
+ }}>
+ {item && item.noteIds.length && item.noteIds.length > 1
+ ? item.noteIds.length + ' notes'
+ : item.noteIds.length === 1
+ ? item.noteIds.length + ' note'
+ : null}
+ </Paragraph>
+ </View>
- <ActionIcon
- color={colors.heading}
- name="dots-horizontal"
- size={SIZE.xl}
- onPress={() => {
- let rowItems = ['Add Shortcut', 'Delete', 'Rename Tag'];
- ActionSheetEvent(item, false, false, rowItems);
- }}
- testID={notesnook.ids.tag.menu}
- customStyle={{
- justifyContent: 'center',
- height: 35,
- width: 35,
- borderRadius: 100,
- alignItems: 'center'
- }}
- />
- </PressableButton>
- );
-};
+ <ActionIcon
+ color={colors.heading}
+ name="dots-horizontal"
+ size={SIZE.xl}
+ onPress={() => {
+ let rowItems = ['Add Shortcut', 'Delete', 'Rename Tag'];
+ ActionSheetEvent(item, false, false, rowItems);
+ }}
+ testID={notesnook.ids.tag.menu}
+ customStyle={{
+ justifyContent: 'center',
+ height: 35,
+ width: 35,
+ borderRadius: 100,
+ alignItems: 'center'
+ }}
+ />
+ </PressableButton>
+ );
+ },
+ (prev, next) => {
+ if (prev.item?.dateEdited !== next.item?.dateEdited) {
+ return false;
+ }
+ if (JSON.stringify(prev.item) !== JSON.stringify(next.item)) {
+ return false;
+ }
+
+ return true;
+ }
+);
export default TagItem;