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
add universal function for search
ammarahm-ed35aabf871e0c
diff --git a/apps/mobile/src/components/Container/index.js b/apps/mobile/src/components/Container/index.jsindex b440714c2..22413a87e 100644--- a/apps/mobile/src/components/Container/index.js+++ b/apps/mobile/src/components/Container/index.js@@ -90,24 +90,28 @@ export const Container = ({if (!text || text.length < 1) {ToastEvent.show('Please enter a search keyword');clearSearch();- } else {- //setKeyword(text);- if (type === 'notes') {- searchResult = await db.notes.filter(text);- } else if (type === 'notebooks') {- searchResult = await db.notebooks.filter(text);- } else if (type === 'topic') {- return;- } else {- return;- }+ return;+ }+ if (!type) return;++ searchResult = await db.lookup[type](+ data[0].data ? db.notes.all : data,+ text,+ );- if (searchResult && searchResult.length > 0) {- dispatch({type: ACTIONS.SEARCH_RESULTS, results: searchResult});- } else {- ToastEvent.show('No search results found', 'error', 3000, () => {}, '');- }+ if (!searchResults && searchResults.length < 0) {+ ToastEvent.show('No search results found', 'error', 3000, () => {}, '');+ return;}++ dispatch({+ type: ACTIONS.SEARCH_RESULTS,+ results: {+ type,+ results: searchResult,+ keyword: text,+ },+ });};const onBlur = () => {@@ -122,7 +126,14 @@ export const Container = ({const clearSearch = () => {searchResult = null;- dispatch({type: ACTIONS.SEARCH_RESULTS, results: []});+ dispatch({+ type: ACTIONS.SEARCH_RESULTS,+ results: {+ results: [],+ type: null,+ keyword: null,+ },+ });};useEffect(() => {diff --git a/apps/mobile/src/provider/defaultState.js b/apps/mobile/src/provider/defaultState.jsindex 2e01c94ba..be4d701cc 100644--- a/apps/mobile/src/provider/defaultState.js+++ b/apps/mobile/src/provider/defaultState.js@@ -45,6 +45,10 @@ export const defaultState = {isLoginNavigator: false,currenEditingNote: null,loading: true,- searchResults: [],+ searchResults: {+ results: [],+ type: null,+ keyword: null,+ },keyword: [],};diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.jsindex 8038834dc..0353539fc 100644--- a/apps/mobile/src/provider/reducer.js+++ b/apps/mobile/src/provider/reducer.js@@ -144,7 +144,7 @@ export const reducer = (state, action) => {let results = action.results;return {...state,- searchResults: [...results],+ searchResults: {...results},};}default: