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
improve drawer navigation performance
ammarahm-edfc5cc2a3be0d
diff --git a/apps/mobile/src/components/Menu/ColorSection.js b/apps/mobile/src/components/Menu/ColorSection.jsindex 8bea7a5d3..e6fae7585 100644--- a/apps/mobile/src/components/Menu/ColorSection.js+++ b/apps/mobile/src/components/Menu/ColorSection.js@@ -1,8 +1,12 @@-import React, {useEffect} from 'react';+import React, {useEffect, useState} from 'react';import {View} from 'react-native';import {useTracked} from '../../provider';import {Actions} from '../../provider/Actions';-import {eSendEvent} from '../../services/EventManager';+import {+ eSendEvent,+ eSubscribeEvent,+ eUnSubscribeEvent,+} from '../../services/EventManager';import Navigation from '../../services/Navigation';import {COLORS_NOTE} from '../../utils/Colors';import {refreshNotesPage} from '../../utils/Events';@@ -12,12 +16,44 @@ import Paragraph from '../Typography/Paragraph';export const ColorSection = ({noTextMode}) => {const [state, dispatch] = useTracked();- const {colors, colorNotes, headerTextState} = state;+ const {colorNotes} = state;useEffect(() => {dispatch({type: Actions.COLORS});}, []);+ return (+ <View+ style={{+ width: '100%',+ }}>+ {colorNotes.map((item, index) => (+ <ColorItem item={item} index={index} />+ ))}+ </View>+ );+};++const ColorItem = ({item, index}) => {+ const [state, dispatch] = useTracked();+ const {colors} = state;+ const [headerTextState, setHeaderTextState] = useState(null);++ const onHeaderStateChange = (event) => {+ if (event.id === item.name) {+ setHeaderTextState(event);+ } else {+ setHeaderTextState(null);+ }+ };++ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, []);+const onPress = (item) => {let params = {type: 'color',@@ -35,65 +71,58 @@ export const ColorSection = ({noTextMode}) => {};return (- <View- style={{+ <PressableButton+ key={item.id}+ color={+ headerTextState?.id === item.id && item.type === headerTextState?.type+ ? COLORS_NOTE[item.title]+ : 'transparent'+ }+ selectedColor={COLORS_NOTE[item.title]}+ alpha={!colors.night ? -0.02 : 0.02}+ opacity={0.12}+ onPress={() => onPress(item)}+ customStyle={{+ flexDirection: 'row',+ justifyContent: noTextMode ? 'center' : 'flex-start',+ alignItems: 'center',width: '100%',+ borderRadius: 0,+ paddingHorizontal: 10,+ height: 50,}}>- {colorNotes.map((item) => (- <PressableButton- key={item.id}- color={- headerTextState.id === item.id && item.type === headerTextState.type- ? COLORS_NOTE[item.title]- : 'transparent'- }- selectedColor={COLORS_NOTE[item.title]}- alpha={!colors.night ? -0.02 : 0.02}- opacity={0.12}- onPress={() => onPress(item)}- customStyle={{+ <View+ style={{+ width: 35,+ height: 35,+ justifyContent: 'center',+ alignItems: 'flex-start',+ }}>+ <View+ style={{+ width: SIZE.md,+ height: SIZE.md,+ backgroundColor: COLORS_NOTE[item.title],+ borderRadius: 100,+ justifyContent: 'center',+ marginRight: 10,+ }}+ />+ </View>++ {noTextMode ? null : (+ <View+ style={{flexDirection: 'row',- justifyContent: noTextMode ? 'center' : 'flex-start',+ justifyContent: 'space-between',alignItems: 'center',- width: '100%',- borderRadius: 0,- paddingHorizontal: 10,- height: 50,+ width: '85%',}}>- <View- style={{- width: 35,- height: 35,- justifyContent: 'center',- alignItems: 'flex-start',- }}>- <View- style={{- width: SIZE.md,- height: SIZE.md,- backgroundColor: COLORS_NOTE[item.title],- borderRadius: 100,- justifyContent: 'center',- marginRight: 10,- }}- />- </View>-- {noTextMode ? null : (- <View- style={{- flexDirection: 'row',- justifyContent: 'space-between',- alignItems: 'center',- width: '85%',- }}>- <Paragraph color={colors.heading} size={SIZE.md}>- {item.title.slice(0, 1).toUpperCase() + item.title.slice(1)}- </Paragraph>- </View>- )}- </PressableButton>- ))}- </View>+ <Paragraph color={colors.heading} size={SIZE.md}>+ {item.title.slice(0, 1).toUpperCase() + item.title.slice(1)}+ </Paragraph>+ </View>+ )}+ </PressableButton>);};diff --git a/apps/mobile/src/components/Menu/MenuListItem.js b/apps/mobile/src/components/Menu/MenuListItem.jsindex 076955d41..b92fe10c8 100644--- a/apps/mobile/src/components/Menu/MenuListItem.js+++ b/apps/mobile/src/components/Menu/MenuListItem.js@@ -1,15 +1,17 @@-import React from 'react';-import { View } from 'react-native';+import React, {useEffect, useState} from 'react';+import {View} from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { useTracked } from '../../provider';+import {useTracked} from '../../provider';+import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';-import { SIZE } from '../../utils/SizeUtils';-import { PressableButton } from '../PressableButton';+import {SIZE} from '../../utils/SizeUtils';+import {PressableButton} from '../PressableButton';import Paragraph from '../Typography/Paragraph';-export const MenuListItem = ({item, index, noTextMode, ignore, testID}) => {+export const MenuListItem = ({item, index, noTextMode, testID}) => {const [state, dispatch] = useTracked();- const {headerTextState, colors} = state;+ const {colors} = state;+ const [headerTextState, setHeaderTextState] = useState(null);const _onPress = (event) => {if (item.func) {@@ -31,13 +33,30 @@ export const MenuListItem = ({item, index, noTextMode, ignore, testID}) => {}};+ const onHeaderStateChange = (event) => {+ if (event.id === item.name.toLowerCase() + '_navigation') {+ setHeaderTextState(event);+ } else {+ setHeaderTextState(null);+ }+ };++ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, []);+return (<PressableButtontestID={testID}key={item.name + index}onPress={_onPress}color={- headerTextState.id === item.name.toLowerCase() + "_navigation" ? colors.shade : 'transparent'+ headerTextState?.id === item.name.toLowerCase() + '_navigation'+ ? colors.shade+ : 'transparent'}selectedColor={colors.accent}alpha={!colors.night ? -0.02 : 0.02}diff --git a/apps/mobile/src/components/Menu/TagsSection.js b/apps/mobile/src/components/Menu/TagsSection.jsindex 44719b97f..6b79fde33 100644--- a/apps/mobile/src/components/Menu/TagsSection.js+++ b/apps/mobile/src/components/Menu/TagsSection.js@@ -4,7 +4,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';import {useTracked} from '../../provider';import {Actions} from '../../provider/Actions';import {DDS} from '../../services/DeviceDetection';-import {eSendEvent} from '../../services/EventManager';+import {eSendEvent, eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';import {getElevation} from '../../utils';import {db} from '../../utils/DB';@@ -20,12 +20,13 @@ import Paragraph from '../Typography/Paragraph';export const TagsSection = () => {const [state, dispatch] = useTracked();- const {colors, menuPins, currentScreen} = state;+ const {colors, menuPins} = state;useEffect(() => {dispatch({type: Actions.MENU_PINS});}, []);+const onPress = (item) => {let params;if (item.type === 'notebook') {@@ -35,15 +36,13 @@ export const TagsSection = () => {menu: true,};- if (currentScreen === 'notebook') {- rootNavigatorRef.current?.setParams(params);- } else {- Navigation.navigate('Notebook', params, {- heading: item.title,- id: item.id,- type: item.type,- });- }+ Navigation.navigate('Notebook', params, {+ heading: item.title,+ id: item.id,+ type: item.type,+ });+ rootNavigatorRef.current?.setParams(params);+} else if (item.type === 'tag') {params = params = {title: item.title,@@ -115,9 +114,26 @@ export const TagsSection = () => {const PinItem = ({item, index, onPress}) => {const [state, dispatch] = useTracked();- const {colors, headerTextState, currentScreen} = state;+ const {colors} = state;const [visible, setVisible] = useState(false);+ const [headerTextState, setHeaderTextState] = useState(null);+++ const onHeaderStateChange = (event) => {+ if (event?.id === item.name) {+ setHeaderTextState(event);+ } else {+ setHeaderTextState(null);+ }+ };++ useEffect(() => {+ eSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ return () => {+ eUnSubscribeEvent('onHeaderStateChange', onHeaderStateChange);+ };+ }, []);return (<>{visible && (@@ -147,7 +163,7 @@ const PinItem = ({item, index, onPress}) => {)}<PressableButtoncolor={- headerTextState.id === item.id && headerTextState.type === item.type+ headerTextState?.id === item.id && headerTextState?.type === item.type? colors.shade: 'transparent'}diff --git a/apps/mobile/src/components/Menu/TimeSince.js b/apps/mobile/src/components/Menu/TimeSince.jsindex b405a3d8a..fa6646437 100644--- a/apps/mobile/src/components/Menu/TimeSince.js+++ b/apps/mobile/src/components/Menu/TimeSince.js@@ -1,5 +1,4 @@import React, {useEffect, useState} from 'react';-import {Text} from 'react-native';import {timeSince} from "../../utils/TimeUtils";import Paragraph from '../Typography/Paragraph';diff --git a/apps/mobile/src/components/Menu/UserSection.js b/apps/mobile/src/components/Menu/UserSection.jsindex 4b8a3f683..b23de3e40 100644--- a/apps/mobile/src/components/Menu/UserSection.js+++ b/apps/mobile/src/components/Menu/UserSection.js@@ -1,16 +1,16 @@import React from 'react';-import {ActivityIndicator, TouchableOpacity, View} from 'react-native';+import { ActivityIndicator, TouchableOpacity, View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import {useTracked} from '../../provider';-import {Actions} from '../../provider/Actions';-import {eSendEvent, ToastEvent} from '../../services/EventManager';-import {showContext, SUBSCRIPTION_STATUS_STRINGS} from '../../utils';-import {db} from '../../utils/DB';-import {eOpenLoginDialog} from '../../utils/Events';-import {pv, SIZE} from '../../utils/SizeUtils';-import {PressableButton} from '../PressableButton';+import { useTracked } from '../../provider';+import { Actions } from '../../provider/Actions';+import { eSendEvent, ToastEvent } from '../../services/EventManager';+import { SUBSCRIPTION_STATUS_STRINGS } from '../../utils';+import { db } from '../../utils/DB';+import { eOpenLoginDialog } from '../../utils/Events';+import { pv, SIZE } from '../../utils/SizeUtils';+import { PressableButton } from '../PressableButton';import Paragraph from '../Typography/Paragraph';-import {TimeSince} from './TimeSince';+import { TimeSince } from './TimeSince';export const UserSection = ({noTextMode}) => {const [state, dispatch] = useTracked();diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.jsindex f20bb8454..8e2fa8d87 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, { useEffect } from 'react';import {FlatList, ScrollView, View} from 'react-native';import {useSafeAreaInsets} from 'react-native-safe-area-context';import {useTracked} from '../../provider';@@ -53,13 +53,14 @@ export const Menu = React.memo(close: true,},];-++return (<Viewstyle={{height: '100%',width: '100%',- backgroundColor: DDS.isLargeTablet() ? colors.nav : colors.bg,+ backgroundColor: "white",paddingTop: insets.top,}}><FlatList@@ -74,11 +75,8 @@ export const Menu = React.memo(<>{MenuItemsList.map((item, index) => (<MenuListItem- testID={item.name}- key={item.name}item={item}index={index}- noTextMode={noTextMode}/>))}<ColorSection noTextMode={noTextMode} />diff --git a/apps/mobile/src/navigation/NavigatorStack.js b/apps/mobile/src/navigation/NavigatorStack.jsindex a6aab66d0..a318ac5cb 100644--- a/apps/mobile/src/navigation/NavigatorStack.js+++ b/apps/mobile/src/navigation/NavigatorStack.js@@ -1,16 +1,20 @@-import { NavigationContainer } from '@react-navigation/native';-import { createStackNavigator } from '@react-navigation/stack';+import {NavigationContainer} from '@react-navigation/native';+import {createStackNavigator} from '@react-navigation/stack';import * as React from 'react';-import { Animated } from 'react-native';+import {Animated} from 'react-native';import Container from '../components/Container';-import { useTracked } from '../provider';-import { rootNavigatorRef } from '../utils/Refs';+import {updateEvent} from '../components/DialogManager/recievers';+import {Actions} from '../provider/Actions';+import {eSendEvent} from '../services/EventManager';+import SettingsService from '../services/SettingsService';+import {rootNavigatorRef} from '../utils/Refs';+import {sleep} from '../utils/TimeUtils';import Favorites from '../views/Favorites';import Folders from '../views/Folders';import Home from '../views/Home';import Notebook from '../views/Notebook';import Notes from '../views/Notes';-import { Search } from '../views/Search';+import {Search} from '../views/Search';import Settings from '../views/Settings';import Tags from '../views/Tags';import Trash from '../views/Trash';@@ -63,14 +67,23 @@ const forSlide = ({current, next, inverted, layouts: {screen}}) => {export const NavigatorStack = React.memo(() => {- const [state] = useTracked();- const {settings} = state;-+ React.useEffect(() => {+ sleep(1000).then(() => {+ console.log(SettingsService.get().homepage)+ let headerState = {+ heading: SettingsService.get().homepage,+ id: SettingsService.get().homepage.toLowerCase() + '_navigation',+ };+ updateEvent({type: Actions.HEADER_TEXT_STATE, state: headerState});+ eSendEvent('onHeaderStateChange', headerState);+ });+ }, []);+return (<Container root={true}><NavigationContainer independent={true} ref={rootNavigatorRef}><Stack.Navigator- initialRouteName={settings.homepage}+ initialRouteName={SettingsService.get().homepage}screenOptions={{headerShown: false,cardStyleInterpolator: forFade,diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.jsindex 28376deba..2f7785cab 100644--- a/apps/mobile/src/provider/DefaultState.js+++ b/apps/mobile/src/provider/DefaultState.js@@ -26,13 +26,13 @@ export const defaultState = {useSystemTheme: false,reminder: 'off',encryptedBackups: false,- homepage: 'Home',+ homepage: 'Notes',sort: 'default',sortOrder: 'des',screenshotMode: true,privacyScreen: false,},- currentScreen: 'home',+ currentScreen: 'notes',deviceMode:null,colors: {night: false,@@ -60,7 +60,7 @@ export const defaultState = {searchResults: [],headerMenuState: true,headerTextState: {- heading: 'Home',+ heading: 'Notes',color: null,},headerVerticalMenu: false,diff --git a/apps/mobile/src/services/Navigation.js b/apps/mobile/src/services/Navigation.jsindex 451d100c7..aef84bc6d 100755--- a/apps/mobile/src/services/Navigation.js+++ b/apps/mobile/src/services/Navigation.js@@ -2,6 +2,7 @@ import {DrawerActions, StackActions} from '@react-navigation/native';import {updateEvent} from '../components/DialogManager/recievers';import {Actions} from '../provider/Actions';import {rootNavigatorRef, sideMenuRef} from '../utils/Refs';+import {eSendEvent} from './EventManager';let currentScreen = null;@@ -43,7 +44,9 @@ function setHeaderState(name, params, item) {type: Actions.HEADER_TEXT_STATE,state: item,});+ eSendEvent('onHeaderStateChange', item);}+if (name) {updateEvent({type: Actions.CURRENT_SCREEN,diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex 86132b251..f40121fe2 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -19,6 +19,7 @@ export const Home = ({route, navigation}) => {const onFocus = useCallback(() => {updateSearch();eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});+if (DDS.isLargeTablet()) {dispatch({type: Actions.CONTAINER_BOTTOM_BUTTON,diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.jsindex e906366a3..a1923be1d 100644--- a/apps/mobile/src/views/Settings/index.js+++ b/apps/mobile/src/views/Settings/index.js@@ -94,7 +94,6 @@ export const Settings = ({navigation}) => {const onFocus = useCallback(() => {eSendEvent(eScrollEvent, {name: 'Settings', type: 'in'});-if (DDS.isLargeTablet()) {dispatch({type: Actions.CONTAINER_BOTTOM_BUTTON,