Skip to content

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

minor improvement in performance

ammarahm-ed445fa99daf71
diff --git a/apps/mobile/src/components/Menu/ColorSection.js b/apps/mobile/src/components/Menu/ColorSection.js
index 510d95b17..8db22ccfa 100644
--- a/apps/mobile/src/components/Menu/ColorSection.js
+++ b/apps/mobile/src/components/Menu/ColorSection.js
@@ -45,12 +45,6 @@ export const ColorSection = ({noTextMode}) => {
state: false,
});
- dispatch({
- type: Actions.CONTAINER_BOTTOM_BUTTON,
- state: {
- bottomButtonText: 'Create a new Note',
- },
- });
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
diff --git a/apps/mobile/src/components/Menu/TagsSection.js b/apps/mobile/src/components/Menu/TagsSection.js
index 678883e6d..7b1ae592e 100644
--- a/apps/mobile/src/components/Menu/TagsSection.js
+++ b/apps/mobile/src/components/Menu/TagsSection.js
@@ -36,18 +36,10 @@ export const TagsSection = () => {
tag: item,
type: 'tag',
};
-
dispatch({
type: Actions.HEADER_VERTICAL_MENU,
state: false,
});
-
- dispatch({
- type: Actions.CONTAINER_BOTTOM_BUTTON,
- state: {
- bottomButtonText:'Create a new Note',
- },
- });
dispatch({
type: Actions.HEADER_TEXT_STATE,
state: {
diff --git a/apps/mobile/src/components/SearchInput/index.js b/apps/mobile/src/components/SearchInput/index.js
index b662ce2df..f962ae314 100644
--- a/apps/mobile/src/components/SearchInput/index.js
+++ b/apps/mobile/src/components/SearchInput/index.js
@@ -2,7 +2,7 @@ import React, {useEffect, useState} from 'react';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {eSubscribeEvent, eUnSubscribeEvent, ToastEvent} from '../../services/EventManager';
-import {eClearSearch, eScrollEvent} from '../../utils/Events';
+import {eClearSearch, eScrollEvent, eUpdateSearchState} from '../../utils/Events';
import {inputRef} from '../../utils/Refs';
import {selection} from '../../utils';
import Animated, {Easing} from 'react-native-reanimated';
@@ -20,14 +20,19 @@ let timeoutAnimate = null;
let animating = false;
export const Search = (props) => {
const [state, dispatch] = useTracked();
- const {colors, searchResults,searchState} = state;
+ const {colors, searchResults} = state;
const [text, setText] = useState('');
const [focus, setFocus] = useState(false);
-
+ const [searchState,setSearchState] = useState({
+ noSearch: false,
+ data: [],
+ type: 'notes',
+ color: null,
+ placeholder: 'Search all notes',
+ })
const _marginAnim = new Value(0);
const _opacity = new Value(1);
const _borderAnim = new Value(1.5);
-
const animation = (margin, opacity, border) => {
if (animating) return;
animating = true;
@@ -82,6 +87,10 @@ export const Search = (props) => {
}
};
+ const updateSearchState = (state => {
+ setSearchState(state);
+ })
+
useEffect(() => {
selection.data = searchState.data;
selection.type = searchState.type;
@@ -89,12 +98,13 @@ export const Search = (props) => {
eSubscribeEvent('showSearch', () => {
animation(0, 1, 1.5);
});
-
+ eSubscribeEvent(eUpdateSearchState,updateSearchState)
return () => {
eUnSubscribeEvent(eScrollEvent, onScroll);
eUnSubscribeEvent('showSearch', () => {
animation(0, 1, 1.5);
});
+ eUnSubscribeEvent(eUpdateSearchState,updateSearchState)
};
}, [searchState]);
diff --git a/apps/mobile/src/utils/Events.js b/apps/mobile/src/utils/Events.js
index 5bec1e506..01d4278d1 100644
--- a/apps/mobile/src/utils/Events.js
+++ b/apps/mobile/src/utils/Events.js
@@ -109,3 +109,5 @@ export const eOpenRestoreDialog = '553';
export const eCloseRestoreDialog = '554';
export const eOnNoteEdited = '555';
+
+export const eUpdateSearchState = '556';
\ No newline at end of file
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index 131dee132..ec2efaa6c 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -4,6 +4,8 @@ import SimpleList from '../../components/SimpleList';
import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import {eSendEvent} from "../../services/EventManager";
+import {eUpdateSearchState} from "../../utils/Events";
export const Favorites = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {favorites} = state;
@@ -21,16 +23,14 @@ export const Favorites = ({route, navigation}) => {
heading: "Favorites",
},
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all favorites',
- data: favorites,
- noSearch: false,
- type: 'notes',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all favorites',
+ data: favorites,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ })
+
dispatch({
type: Actions.CURRENT_SCREEN,
screen: 'favorites',
@@ -47,16 +47,14 @@ export const Favorites = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all favorites',
- data: favorites,
- noSearch: false,
- type: 'notes',
- color: null,
- },
- });
+
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all favorites',
+ data: favorites,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ })
}
}, [favorites]);
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index 526d038bf..ba61acabb 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -6,6 +6,8 @@ import {NotebookItemWrapper} from '../../components/SimpleList/NotebookItemWrapp
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
+import {eSendEvent} from "../../services/EventManager";
+import {eUpdateSearchState} from "../../utils/Events";
export const Folders = ({route, navigation}) => {
const [state, dispatch] = useTracked();
const {notebooks} = state;
@@ -21,16 +23,15 @@ export const Folders = ({route, navigation}) => {
heading: "Notebooks",
},
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all notebooks',
- data: notebooks,
- noSearch: false,
- type: 'notebooks',
- color: null,
- },
- });
+
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all notebooks',
+ data: notebooks,
+ noSearch: false,
+ type: 'notebooks',
+ color: null,
+ },)
+
dispatch({type: Actions.NOTEBOOKS});
dispatch({
type: Actions.CURRENT_SCREEN,
@@ -47,16 +48,13 @@ export const Folders = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all notebooks',
- data: notebooks,
- noSearch: false,
- type: 'notebooks',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all notebooks',
+ data: notebooks,
+ noSearch: false,
+ type: 'notebooks',
+ color: null,
+ },)
}
}, [notebooks]);
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index 06c0bb713..98c84ceaa 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -6,7 +6,7 @@ import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {eSendEvent} from '../../services/EventManager';
-import {eOnLoadNote, eScrollEvent} from '../../utils/Events';
+import {eOnLoadNote, eScrollEvent, eUpdateSearchState} from '../../utils/Events';
import {openEditorAnimation} from '../../utils/Animations';
import {DDS} from "../../services/DeviceDetection";
@@ -33,16 +33,13 @@ export const Home = ({navigation}) => {
type: Actions.HEADER_STATE,
state: true,
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all notes',
- data: notes,
- noSearch: false,
- type: 'notes',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all notes',
+ data: notes,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ })
eSendEvent(eScrollEvent, 0);
dispatch({type: Actions.COLORS});
dispatch({type: Actions.NOTES});
@@ -62,16 +59,13 @@ export const Home = ({navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all notes',
- data: notes,
- noSearch: false,
- type: 'notes',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all notes',
+ data: notes,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ })
}
}, [notes]);
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 6b2f1c4b7..835de0487 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -11,7 +11,7 @@ import {
eSubscribeEvent,
eUnSubscribeEvent,
} from '../../services/EventManager';
-import {eOnNewTopicAdded, eScrollEvent} from '../../utils/Events';
+import {eOnNewTopicAdded, eScrollEvent, eUpdateSearchState} from '../../utils/Events';
import NavigationService from '../../services/Navigation';
import {db} from "../../utils/DB";
@@ -48,16 +48,15 @@ export const Notebook = ({route, navigation}) => {
heading: params.title,
},
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: `Search in "${params.title}"`,
- data: topics,
- noSearch: false,
- type: 'topics',
- color: null,
- },
- });
+
+ eSendEvent(eUpdateSearchState,{
+ placeholder: `Search in "${params.title}"`,
+ data: topics,
+ noSearch: false,
+ type: 'topics',
+ color: null,
+ })
+
dispatch({
type: Actions.CURRENT_SCREEN,
screen: 'notebook',
@@ -73,16 +72,13 @@ export const Notebook = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: `Search in "${params.title}"`,
- data: topics,
- noSearch: false,
- type: 'topics',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: `Search in "${params.title}"`,
+ data: topics,
+ noSearch: false,
+ type: 'topics',
+ color: null,
+ })
}
}, [topics]);
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 29c7d13a3..1f4ed6a57 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -12,7 +12,7 @@ import {
} from '../../services/EventManager';
import {
eOnLoadNote,
- eScrollEvent,
+ eScrollEvent, eUpdateSearchState,
refreshNotesPage,
} from '../../utils/Events';
import {openEditorAnimation} from '../../utils/Animations';
@@ -114,18 +114,15 @@ export const Notes = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
+ eSendEvent(eUpdateSearchState,{
placeholder: `Search in ${
- params.type === 'tag' ? '#' + params.title : params.title
+ params.type === 'tag' ? '#' + params.title : params.title
}`,
data: notes,
noSearch: false,
type: 'notes',
color: params.type === 'color' ? params.title : null,
- },
- });
+ })
}
}, [notes]);
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 14d269a02..911748087 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -19,13 +19,13 @@ import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import {eSendEvent, ToastEvent} from '../../services/EventManager';
import {
- eCloseProgressDialog,
- eOpenLoginDialog,
- eOpenPremiumDialog,
- eOpenProgressDialog,
- eOpenRecoveryKeyDialog,
- eOpenRestoreDialog,
- eResetApp,
+ eCloseProgressDialog,
+ eOpenLoginDialog,
+ eOpenPremiumDialog,
+ eOpenProgressDialog,
+ eOpenRecoveryKeyDialog,
+ eOpenRestoreDialog,
+ eResetApp, eUpdateSearchState,
} from '../../utils/Events';
import NavigationService from '../../services/Navigation';
import storage from '../../utils/storage';
@@ -71,12 +71,12 @@ export const Settings = ({ navigation}) => {
type: Actions.CURRENT_SCREEN,
screen: 'settings',
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- noSearch: true,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ type: Actions.SEARCH_STATE,
+ state: {
+ noSearch: true,
+ },
+ })
}, []);
useEffect(() => {
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index f6ab89f4b..f73c56500 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -7,6 +7,8 @@ import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
import NavigationService from '../../services/Navigation';
import {SIZE, WEIGHT} from "../../utils/SizeUtils";
+import {eSendEvent} from "../../services/EventManager";
+import {eUpdateSearchState} from "../../utils/Events";
export const Tags = ({route, navigation}) => {
const [state, dispatch] = useTracked();
@@ -24,17 +26,14 @@ export const Tags = ({route, navigation}) => {
heading:"Tags",
},
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all tags',
- data: tags,
- noSearch: false,
- type: 'tags',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all tags',
+ data: tags,
+ noSearch: false,
+ type: 'tags',
+ color: null,
+ })
dispatch({type: Actions.TAGS});
dispatch({
type: Actions.CURRENT_SCREEN,
@@ -51,16 +50,13 @@ export const Tags = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all tags',
- data: tags,
- noSearch: false,
- type: 'tags',
- color: null,
- },
- });
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all tags',
+ data: tags,
+ noSearch: false,
+ type: 'tags',
+ color: null,
+ })
}
}, [tags]);
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 7b08fb3da..231e259a4 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -8,6 +8,8 @@ import {NotebookItemWrapper} from '../../components/SimpleList/NotebookItemWrapp
import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';
import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions';
+import {eSendEvent} from "../../services/EventManager";
+import {eUpdateSearchState} from "../../utils/Events";
export const Trash = ({route, navigation}) => {
const [state, dispatch] = useTracked();
@@ -24,16 +26,14 @@ export const Trash = ({route, navigation}) => {
heading: "Trash",
},
});
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all trash',
- data: trash,
- noSearch: false,
- type: 'trash',
- color: null,
- },
- });
+
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all trash',
+ data: trash,
+ noSearch: false,
+ type: 'trash',
+ color: null,
+ })
dispatch({
type: Actions.TRASH,
@@ -53,16 +53,15 @@ export const Trash = ({route, navigation}) => {
useEffect(() => {
if (navigation.isFocused()) {
- dispatch({
- type: Actions.SEARCH_STATE,
- state: {
- placeholder: 'Search all trash',
- data: trash,
- noSearch: false,
- type: 'trash',
- color: null,
- },
- });
+
+ eSendEvent(eUpdateSearchState,{
+ placeholder: 'Search all trash',
+ data: trash,
+ noSearch: false,
+ type: 'trash',
+ color: null,
+ })
+
}
}, [trash]);