A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
improvements in navigation performance
ammarahm-ed6d93015646ed
diff --git a/apps/mobile/src/components/Menu/ColorSection.js b/apps/mobile/src/components/Menu/ColorSection.jsindex 66a458320..8b3942f16 100644--- a/apps/mobile/src/components/Menu/ColorSection.js+++ b/apps/mobile/src/components/Menu/ColorSection.js@@ -27,116 +27,126 @@ export const ColorSection = () => {return colorNotes.map((item, index) => <ColorItem key={item.id} item={item} index={index} />);};-const ColorItem = ({ item, index }) => {- const [state] = useTracked();- const { colors } = state;- const setColorNotes = useMenuStore(state => state.setColorNotes);- const [headerTextState, setHeaderTextState] = useState(null);- const alias = db.colors.alias(item.id);-- const onHeaderStateChange = event => {- if (event?.id === item.id) {- setHeaderTextState(event);- } else {- setHeaderTextState(null);- }- };+const ColorItem = React.memo(+ ({ item, index }) => {+ const [state] = useTracked();+ const { colors } = state;+ const setColorNotes = useMenuStore(state => state.setColorNotes);+ const [headerTextState, setHeaderTextState] = useState(null);+ const alias = db.colors.alias(item.id);- useEffect(() => {- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);- return () => {- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ const onHeaderStateChange = event => {+ setTimeout(() => {+ if (event.id === item.name.toLowerCase() + '_navigation') {+ setHeaderTextState(event);+ } else {+ if (headerTextState !== null) {+ setHeaderTextState(null);+ }+ }+ }, 600);};- }, []);- const onPress = item => {- let params = {- ...item,- type: 'color',- menu: true,- get: 'colored'- };+ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, [headerTextState]);- eSendEvent(refreshNotesPage, params);- Navigation.navigate('NotesPage', params, {- heading: alias.slice(0, 1).toUpperCase() + alias.slice(1),- id: item.id,- type: 'color'- });- Navigation.closeDrawer();- };+ const onPress = item => {+ let params = {+ ...item,+ type: 'color',+ menu: true,+ get: 'colored'+ };- const onLongPress = () => {- presentDialog({- title: 'Rename color',- input: true,- inputPlaceholder: 'Enter name for this color',- defaultValue: alias,- paragraph: 'You are renaming the color ' + item.title,- positivePress: async value => {- if (!value || value.trim().length === 0) return;- await db.colors.rename(item.id, value);- setColorNotes();- console.log('color updated');- },- positiveText: 'Rename'- });- };+ eSendEvent(refreshNotesPage, params);+ Navigation.navigate('NotesPage', params, {+ heading: alias.slice(0, 1).toUpperCase() + alias.slice(1),+ id: item.id,+ type: 'color'+ });+ Navigation.closeDrawer();+ };++ const onLongPress = () => {+ presentDialog({+ title: 'Rename color',+ input: true,+ inputPlaceholder: 'Enter name for this color',+ defaultValue: alias,+ paragraph: 'You are renaming the color ' + item.title,+ positivePress: async value => {+ if (!value || value.trim().length === 0) return;+ await db.colors.rename(item.id, value);+ setColorNotes();+ console.log('color updated');+ },+ positiveText: 'Rename'+ });+ };- return (- <PressableButton- customColor={headerTextState?.id === item.id ? 'rgba(0,0,0,0.04)' : 'transparent'}- onLongPress={onLongPress}- customSelectedColor={COLORS_NOTE[item.title.toLowerCase()]}- customAlpha={!colors.night ? -0.02 : 0.02}- customOpacity={0.12}- onPress={() => onPress(item)}- customStyle={{- width: '100%',- alignSelf: 'center',- borderRadius: 5,- flexDirection: 'row',- paddingHorizontal: 8,- justifyContent: 'space-between',- alignItems: 'center',- height: normalize(50),- marginBottom: 5- }}- >- <View- style={{+ return (+ <PressableButton+ customColor={headerTextState?.id === item.id ? 'rgba(0,0,0,0.04)' : 'transparent'}+ onLongPress={onLongPress}+ customSelectedColor={COLORS_NOTE[item.title.toLowerCase()]}+ customAlpha={!colors.night ? -0.02 : 0.02}+ customOpacity={0.12}+ onPress={() => onPress(item)}+ customStyle={{+ width: '100%',+ alignSelf: 'center',+ borderRadius: 5,flexDirection: 'row',- alignItems: 'center'+ paddingHorizontal: 8,+ justifyContent: 'space-between',+ alignItems: 'center',+ height: normalize(50),+ marginBottom: 5}}><Viewstyle={{- width: 30,- justifyContent: 'center',- alignItems: 'flex-start'+ flexDirection: 'row',+ alignItems: 'center'}}><Viewstyle={{- width: SIZE.lg - 2,- height: SIZE.lg - 2,- backgroundColor: COLORS_NOTE[item.title.toLowerCase()],- borderRadius: 100,+ width: 30,justifyContent: 'center',- marginRight: 10+ alignItems: 'flex-start'}}- />+ >+ <View+ style={{+ width: SIZE.lg - 2,+ height: SIZE.lg - 2,+ backgroundColor: COLORS_NOTE[item.title.toLowerCase()],+ borderRadius: 100,+ justifyContent: 'center',+ marginRight: 10+ }}+ />+ </View>+ {headerTextState?.id === item.id ? (+ <Heading color={colors.heading} size={SIZE.md}>+ {alias.slice(0, 1).toUpperCase() + alias.slice(1)}+ </Heading>+ ) : (+ <Paragraph color={colors.pri} size={SIZE.md}>+ {alias.slice(0, 1).toUpperCase() + alias.slice(1)}+ </Paragraph>+ )}</View>- {headerTextState?.id === item.id ? (- <Heading color={colors.heading} size={SIZE.md}>- {alias.slice(0, 1).toUpperCase() + alias.slice(1)}- </Heading>- ) : (- <Paragraph color={colors.pri} size={SIZE.md}>- {alias.slice(0, 1).toUpperCase() + alias.slice(1)}- </Paragraph>- )}- </View>- </PressableButton>- );-};+ </PressableButton>+ );+ },+ (prev, next) => {+ if (prev.item?.id !== next.item?.id) return false;+ return true;+ }+);diff --git a/apps/mobile/src/components/Menu/MenuListItem.js b/apps/mobile/src/components/Menu/MenuListItem.jsindex d2eefd17e..812475d16 100644--- a/apps/mobile/src/components/Menu/MenuListItem.js+++ b/apps/mobile/src/components/Menu/MenuListItem.js@@ -1,5 +1,5 @@import React, { useEffect, useState } from 'react';-import { View } from 'react-native';+import { InteractionManager, View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import { useTracked } from '../../provider';import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';@@ -12,114 +12,124 @@ import Heading from '../Typography/Heading';import Paragraph from '../Typography/Paragraph';import ToggleSwitch from 'toggle-switch-react-native';-export const MenuListItem = ({ item, index, noTextMode, testID, rightBtn }) => {- const [state, dispatch] = useTracked();- const { colors } = state;- const [headerTextState, setHeaderTextState] = useState(null);- let isFocused = headerTextState?.id === item.name.toLowerCase() + '_navigation';+export const MenuListItem = React.memo(+ ({ item, index, noTextMode, testID, rightBtn }) => {+ const [state] = useTracked();+ const { colors } = state;+ const [headerTextState, setHeaderTextState] = useState(null);+ let isFocused = headerTextState?.id === item.name.toLowerCase() + '_navigation';- const _onPress = event => {- if (item.func) {- item.func();- } else {- Navigation.navigate(- item.name,- {- menu: true- },- {- heading: item.name,- id: item.name.toLowerCase() + '_navigation'- }- );- }- if (item.close) {- Navigation.closeDrawer();- }- };-- const onHeaderStateChange = event => {- if (event.id === item.name.toLowerCase() + '_navigation') {- setHeaderTextState(event);- } else {- setHeaderTextState(null);- }- };+ const _onPress = event => {+ if (item.func) {+ item.func();+ } else {+ Navigation.navigate(+ item.name,+ {+ menu: true+ },+ {+ heading: item.name,+ id: item.name.toLowerCase() + '_navigation'+ }+ );+ }+ if (item.close) {+ Navigation.closeDrawer();+ }+ };- useEffect(() => {- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);- return () => {- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ const onHeaderStateChange = event => {+ setTimeout(() => {+ if (event.id === item.name.toLowerCase() + '_navigation') {+ setHeaderTextState(event);+ } else {+ if (headerTextState !== null) {+ setHeaderTextState(null);+ }+ }+ }, 600);};- }, []);- return (- <PressableButton- testID={testID}- key={item.name + index}- onPress={_onPress}- type={!isFocused ? 'gray' : 'grayBg'}- customStyle={{- width: '100%',- alignSelf: 'center',- borderRadius: 5,- flexDirection: 'row',- paddingHorizontal: 8,- justifyContent: 'space-between',- alignItems: 'center',- height: normalize(50),- marginBottom: 5- }}- >- <View- style={{+ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, [headerTextState]);++ return (+ <PressableButton+ testID={testID}+ key={item.name + index}+ onPress={_onPress}+ type={!isFocused ? 'gray' : 'grayBg'}+ customStyle={{+ width: '100%',+ alignSelf: 'center',+ borderRadius: 5,flexDirection: 'row',- alignItems: 'center'+ paddingHorizontal: 8,+ justifyContent: 'space-between',+ alignItems: 'center',+ height: normalize(50),+ marginBottom: 5}}>- <Icon+ <Viewstyle={{- width: 30,- textAlignVertical: 'center',- textAlign: 'left'+ flexDirection: 'row',+ alignItems: 'center'}}- name={item.icon}- color={item.icon === 'crown' ? colors.yellow : isFocused ? colors.accent : colors.pri}- size={SIZE.lg - 2}- />- {isFocused ? (- <Heading color={colors.heading} size={SIZE.md}>- {item.name}- </Heading>- ) : (- <Paragraph size={SIZE.md}>{item.name}</Paragraph>- )}- </View>+ >+ <Icon+ style={{+ width: 30,+ textAlignVertical: 'center',+ textAlign: 'left'+ }}+ name={item.icon}+ color={item.icon === 'crown' ? colors.yellow : isFocused ? colors.accent : colors.pri}+ size={SIZE.lg - 2}+ />+ {isFocused ? (+ <Heading color={colors.heading} size={SIZE.md}>+ {item.name}+ </Heading>+ ) : (+ <Paragraph size={SIZE.md}>{item.name}</Paragraph>+ )}+ </View>- {item.switch ? (- <ToggleSwitch- isOn={item.on}- onColor={colors.accent}- offColor={colors.icon}- size="small"- animationSpeed={150}- onToggle={_onPress}- />- ) : rightBtn ? (- <Button- title={rightBtn.name}- type="shade"- height={30}- fontSize={SIZE.xs}- iconSize={SIZE.xs}- icon={rightBtn.icon}- style={{- borderRadius: 100,- paddingHorizontal: 16- }}- onPress={rightBtn.func}- />- ) : null}- </PressableButton>- );-};+ {item.switch ? (+ <ToggleSwitch+ isOn={item.on}+ onColor={colors.accent}+ offColor={colors.icon}+ size="small"+ animationSpeed={150}+ onToggle={_onPress}+ />+ ) : rightBtn ? (+ <Button+ title={rightBtn.name}+ type="shade"+ height={30}+ fontSize={SIZE.xs}+ iconSize={SIZE.xs}+ icon={rightBtn.icon}+ style={{+ borderRadius: 100,+ paddingHorizontal: 16+ }}+ onPress={rightBtn.func}+ />+ ) : null}+ </PressableButton>+ );+ },+ (prev, next) => {+ if (prev.item.name !== next.item.name) return false;+ return true;+ }+);diff --git a/apps/mobile/src/components/Menu/TagsSection.js b/apps/mobile/src/components/Menu/TagsSection.jsindex 38ef16020..c3d1124c8 100644--- a/apps/mobile/src/components/Menu/TagsSection.js+++ b/apps/mobile/src/components/Menu/TagsSection.js@@ -95,137 +95,146 @@ export const TagsSection = () => {);};-export const PinItem = ({ item, index, onPress, placeholder }) => {- const [state, dispatch] = useTracked();- const { colors } = state;- const setMenuPins = useMenuStore(state => state.setMenuPins);- const alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title;- const [visible, setVisible] = useState(false);- const [headerTextState, setHeaderTextState] = useState(null);- const color = headerTextState?.id === item.id ? colors.accent : colors.pri;- const fwdRef = useRef();-- const onHeaderStateChange = event => {- if (event?.id === item.id) {- setHeaderTextState(event);- } else {- setHeaderTextState(null);- }- };+export const PinItem = React.memo(+ ({ item, index, onPress, placeholder }) => {+ const [state] = useTracked();+ const { colors } = state;+ const setMenuPins = useMenuStore(state => state.setMenuPins);+ const alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title;+ const [visible, setVisible] = useState(false);+ const [headerTextState, setHeaderTextState] = useState(null);+ const color = headerTextState?.id === item.id ? colors.accent : colors.pri;+ const fwdRef = useRef();- useEffect(() => {- if (placeholder) return;- eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);- return () => {- eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ const onHeaderStateChange = event => {+ setTimeout(() => {+ if (event.id === item.name.toLowerCase() + '_navigation') {+ setHeaderTextState(event);+ } else {+ if (headerTextState !== null) {+ setHeaderTextState(null);+ }+ }+ }, 600);};- }, []);- const icons = {- topic: 'bookmark',- notebook: 'book-outline',- tag: 'pound'- };+ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, [headerTextState]);- return (- <>- {visible && (- <SheetWrapper- onClose={() => {- setVisible(false);- }}- gestureEnabled={false}- fwdRef={fwdRef}- visible={true}- >- <Seperator />- <Button- title="Remove Shortcut"- type="error"- onPress={async () => {- await db.settings.unpin(item.id);+ const icons = {+ topic: 'bookmark',+ notebook: 'book-outline',+ tag: 'pound'+ };++ return (+ <>+ {visible && (+ <SheetWrapper+ onClose={() => {setVisible(false);- setMenuPins();- }}- fontSize={SIZE.md}- width="95%"- height={50}- customStyle={{- marginBottom: 30}}- />- </SheetWrapper>- )}- <PressableButton- type={headerTextState?.id === item.id ? 'grayBg' : 'gray'}- onLongPress={() => {- if (placeholder) return;- Properties.present(item);- }}- onPress={() => onPress(item)}- customStyle={{- width: '100%',- alignSelf: 'center',- borderRadius: 5,- flexDirection: 'row',- paddingHorizontal: 8,- justifyContent: 'space-between',- alignItems: 'center',- height: normalize(50),- marginBottom: 5- }}- >- <View- style={{+ gestureEnabled={false}+ fwdRef={fwdRef}+ visible={true}+ >+ <Seperator />+ <Button+ title="Remove Shortcut"+ type="error"+ onPress={async () => {+ await db.settings.unpin(item.id);+ setVisible(false);+ setMenuPins();+ }}+ fontSize={SIZE.md}+ width="95%"+ height={50}+ customStyle={{+ marginBottom: 30+ }}+ />+ </SheetWrapper>+ )}+ <PressableButton+ type={headerTextState?.id === item.id ? 'grayBg' : 'gray'}+ onLongPress={() => {+ if (placeholder) return;+ Properties.present(item);+ }}+ onPress={() => onPress(item)}+ customStyle={{+ width: '100%',+ alignSelf: 'center',+ borderRadius: 5,flexDirection: 'row',+ paddingHorizontal: 8,+ justifyContent: 'space-between',alignItems: 'center',- flexGrow: 1,- flex: 1+ height: normalize(50),+ marginBottom: 5}}><Viewstyle={{- width: 30,- justifyContent: 'center'- }}- >- <Icon color={color} size={SIZE.lg - 2} name={icons[item.type]} />- <Icon- style={{- position: 'absolute',- bottom: -6,- left: -6- }}- color={color}- size={SIZE.xs}- name="arrow-top-right-thick"- />- </View>- <View- style={{- alignItems: 'flex-start',+ flexDirection: 'row',+ alignItems: 'center',flexGrow: 1,flex: 1}}>- {headerTextState?.id === item.id ? (- <Heading+ <View+ style={{+ width: 30,+ justifyContent: 'center'+ }}+ >+ <Icon color={color} size={SIZE.lg - 2} name={icons[item.type]} />+ <Iconstyle={{- flexWrap: 'wrap'+ position: 'absolute',+ bottom: -6,+ left: -6}}- color={colors.heading}- size={SIZE.md}- >- {alias}- </Heading>- ) : (- <Paragraph numberOfLines={1} color={colors.pri} size={SIZE.md}>- {alias}- </Paragraph>- )}+ color={color}+ size={SIZE.xs}+ name="arrow-top-right-thick"+ />+ </View>+ <View+ style={{+ alignItems: 'flex-start',+ flexGrow: 1,+ flex: 1+ }}+ >+ {headerTextState?.id === item.id ? (+ <Heading+ style={{+ flexWrap: 'wrap'+ }}+ color={colors.heading}+ size={SIZE.md}+ >+ {alias}+ </Heading>+ ) : (+ <Paragraph numberOfLines={1} color={colors.pri} size={SIZE.md}>+ {alias}+ </Paragraph>+ )}+ </View></View>- </View>- </PressableButton>- </>- );-};+ </PressableButton>+ </>+ );+ },+ (prev, next) => {+ if (prev.item?.id !== next.item?.id) return false;+ return true;+ }+);diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.jsindex 2cbfb7e21..98156385e 100644--- a/apps/mobile/src/components/Menu/index.js+++ b/apps/mobile/src/components/Menu/index.js@@ -1,4 +1,4 @@-import React from 'react';+import React, { useCallback } from 'react';import { FlatList, View } from 'react-native';import { useSafeAreaInsets } from 'react-native-safe-area-context';import { notesnook } from '../../../e2e/test.ids';@@ -31,6 +31,7 @@ export const Menu = React.memo(const insets = useSafeAreaInsets();const user = useUserStore(state => state.user);const noTextMode = false;+function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {let newColors = setColorScheme(colors, accent);dispatch({ type: Actions.THEME, colors: newColors });@@ -69,6 +70,19 @@ export const Menu = React.memo(}};+ const renderItem = useCallback(+ () => (+ <>+ {MenuItemsList.map((item, index) => (+ <MenuListItem key={item.name} item={item} testID={item.name} index={index} />+ ))}+ <ColorSection noTextMode={noTextMode} />+ <TagsSection />+ </>+ ),+ []+ );+return (<Viewstyle={{@@ -99,15 +113,7 @@ export const Menu = React.memo(showsVerticalScrollIndicator={false}data={[0]}keyExtractor={() => 'mainMenuView'}- renderItem={() => (- <>- {MenuItemsList.map((item, index) => (- <MenuListItem key={item.name} item={item} testID={item.name} index={index} />- ))}- <ColorSection noTextMode={noTextMode} />- <TagsSection />- </>- )}+ renderItem={renderItem}/><Viewstyle={{diff --git a/apps/mobile/src/components/NoteItem/index.js b/apps/mobile/src/components/NoteItem/index.jsindex e6892e4a7..3289f5e1d 100644--- a/apps/mobile/src/components/NoteItem/index.js+++ b/apps/mobile/src/components/NoteItem/index.js@@ -1,10 +1,10 @@import { decode, EntityLevel } from 'entities';-import React, { useEffect } from 'react';-import { Platform, View } from 'react-native';+import React from 'react';+import { View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import { notesnook } from '../../../e2e/test.ids';import { useTracked } from '../../provider';-import { useSettingStore, useTagStore } from '../../provider/stores';+import { useSettingStore } from '../../provider/stores';import { eSendEvent } from '../../services/EventManager';import Navigation from '../../services/Navigation';import { COLORS_NOTE } from '../../utils/Colors';@@ -13,7 +13,6 @@ import { refreshNotesPage } from '../../utils/Events';import { SIZE } from '../../utils/SizeUtils';import { ActionIcon } from '../ActionIcon';import { Button } from '../Button';-import { ActionSheetEvent } from '../DialogManager/recievers';import { TimeSince } from '../Menu/TimeSince';import { Properties } from '../Properties';import Heading from '../Typography/Heading';diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.jsindex 7e3139e1e..6df0d1692 100644--- a/apps/mobile/src/components/NotebookItem/index.js+++ b/apps/mobile/src/components/NotebookItem/index.js@@ -11,7 +11,6 @@ import { refreshNotesPage } from '../../utils/Events';import { SIZE } from '../../utils/SizeUtils';import { ActionIcon } from '../ActionIcon';import { Button } from '../Button';-import { ActionSheetEvent } from '../DialogManager/recievers';import { Properties } from '../Properties';import Heading from '../Typography/Heading';import Paragraph from '../Typography/Paragraph';diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.jsindex 2eafc3488..6f0a0ce5f 100644--- a/apps/mobile/src/components/SimpleList/index.js+++ b/apps/mobile/src/components/SimpleList/index.js@@ -1,5 +1,5 @@import React, { useEffect, useRef, useState } from 'react';-import { FlatList, RefreshControl, RefreshControlComponent, View } from 'react-native';+import { FlatList, RefreshControl, View } from 'react-native';import { notesnook } from '../../../e2e/test.ids';import { useTracked } from '../../provider';import { useUserStore } from '../../provider/stores';@@ -7,7 +7,6 @@ import { eSendEvent } from '../../services/EventManager';import Sync from '../../services/Sync';import { db } from '../../utils/database';import { eScrollEvent } from '../../utils/Events';-import { sleep } from '../../utils/TimeUtils';import JumpToDialog from '../JumpToDialog';import { NotebookWrapper } from '../NotebookItem/wrapper';import { NoteWrapper } from '../NoteItem/wrapper';diff --git a/apps/mobile/src/components/Walkthrough/index.tsx b/apps/mobile/src/components/Walkthrough/index.tsxindex 2f2b764a6..535aa68b5 100644--- a/apps/mobile/src/components/Walkthrough/index.tsx+++ b/apps/mobile/src/components/Walkthrough/index.tsx@@ -100,7 +100,7 @@ Walkthrough.present = async (id: 'notebooks') => {if (walkthroughState[id]) return;//@ts-ignorewalkthroughState[id] = true;- //MMKV.setItem('walkthroughState', JSON.stringify(walkthroughState));+ MMKV.setItem('walkthroughState', JSON.stringify(walkthroughState));//@ts-ignorelet walkthrough = walkthroughs[id];if (!walkthrough) return;