Skip to content

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

show loading on search

ammarahm-ed067f69e8eed9
diff --git a/apps/mobile/src/provider/Actions.js b/apps/mobile/src/provider/Actions.js
index c835271be..2379bc06f 100644
--- a/apps/mobile/src/provider/Actions.js
+++ b/apps/mobile/src/provider/Actions.js
@@ -33,5 +33,6 @@ export const Actions = {
DEVICE_MODE:"deviceMode",
MENU_PINS:"menuPins",
LAST_SYNC:"lastSynced",
- INTENT_MODE: "intentMode"
+ INTENT_MODE: "intentMode",
+ SEARCHING:'searching'
};
diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.js
index 4c7d24366..d7380c825 100644
--- a/apps/mobile/src/provider/DefaultState.js
+++ b/apps/mobile/src/provider/DefaultState.js
@@ -83,5 +83,6 @@ export const defaultState = {
keyword: [],
menuPins:[],
lastSynced:"Never",
- intentMode:true
+ intentMode:true,
+ searching:false
};
diff --git a/apps/mobile/src/provider/Reducer.js b/apps/mobile/src/provider/Reducer.js
index 58f89afdf..2a5539902 100644
--- a/apps/mobile/src/provider/Reducer.js
+++ b/apps/mobile/src/provider/Reducer.js
@@ -58,7 +58,7 @@ export const reducer = (state, action) => {
notes: db.notes.group(
SORT[sortSettings.sort],
sortSettings.sortOrder,
- ),
+ )
};
case Actions.THEME: {
return {
@@ -275,6 +275,12 @@ export const reducer = (state, action) => {
intentMode: action.state,
};
}
+ case Actions.SEARCHING: {
+ return {
+ ...state,
+ searching: action.searching,
+ };
+ }
default:
throw new Error('unknown action type');
}
diff --git a/apps/mobile/src/services/SearchService.js b/apps/mobile/src/services/SearchService.js
index f194bbc4c..d3957b445 100644
--- a/apps/mobile/src/services/SearchService.js
+++ b/apps/mobile/src/services/SearchService.js
@@ -9,11 +9,18 @@ let searchInformation = {
type: 'notes',
};
+let keyword = null;
+
function update(data) {
searchInformation = data;
}
-async function search(term) {
+function setTerm(term) {
+ keyword = term
+}
+
+async function search() {
+ let term = keyword;
if (!term || term.length === 0) {
updateEvent({
type: Actions.SEARCH_RESULTS,
@@ -21,16 +28,20 @@ async function search(term) {
});
return;
}
+ updateEvent({type:Actions.SEARCHING, searching:true})
let results;
if (!searchInformation.type) return;
+
results = await db.lookup[searchInformation.type](
searchInformation.data,
term,
);
+
if (!results || results.length === 0) {
ToastEvent.show('No search results found for ' + term, 'error');
return;
}
+ updateEvent({type:Actions.SEARCHING, searching:false})
updateEvent({
type: Actions.SEARCH_RESULTS,
results: results,
@@ -45,4 +56,5 @@ export default {
update,
getSearchInformation,
search,
+ setTerm
};
diff --git a/apps/mobile/src/views/Search/index.js b/apps/mobile/src/views/Search/index.js
index 3f5698101..aa3197b29 100644
--- a/apps/mobile/src/views/Search/index.js
+++ b/apps/mobile/src/views/Search/index.js
@@ -8,7 +8,8 @@ import {sleep} from '../../utils/TimeUtils';
export const Search = ({route, navigation}) => {
const [state, dispatch] = useTracked();
- const {searchResults} = state;
+ const {searchResults,searching} = state;
+
let pageIsLoaded = false;
const onFocus = useCallback(() => {
@@ -45,11 +46,13 @@ export const Search = ({route, navigation}) => {
focused={() => navigation.isFocused()}
placeholderText={`Notes you write appear here`}
jumpToDialog={true}
+ loading={searching}
CustomHeader={true}
placeholderData={{
heading: 'Search',
paragraph: SearchService.getSearchInformation().placeholder,
button: null,
+ loading:"Searching..."
}}
/>
</>