mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
add universal function for search
This commit is contained in:
@@ -90,24 +90,28 @@ export const Container = ({
|
|||||||
if (!text || text.length < 1) {
|
if (!text || text.length < 1) {
|
||||||
ToastEvent.show('Please enter a search keyword');
|
ToastEvent.show('Please enter a search keyword');
|
||||||
clearSearch();
|
clearSearch();
|
||||||
} else {
|
return;
|
||||||
//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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchResult && searchResult.length > 0) {
|
|
||||||
dispatch({type: ACTIONS.SEARCH_RESULTS, results: searchResult});
|
|
||||||
} else {
|
|
||||||
ToastEvent.show('No search results found', 'error', 3000, () => {}, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (!type) return;
|
||||||
|
|
||||||
|
searchResult = await db.lookup[type](
|
||||||
|
data[0].data ? db.notes.all : data,
|
||||||
|
text,
|
||||||
|
);
|
||||||
|
|
||||||
|
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 = () => {
|
const onBlur = () => {
|
||||||
@@ -122,7 +126,14 @@ export const Container = ({
|
|||||||
|
|
||||||
const clearSearch = () => {
|
const clearSearch = () => {
|
||||||
searchResult = null;
|
searchResult = null;
|
||||||
dispatch({type: ACTIONS.SEARCH_RESULTS, results: []});
|
dispatch({
|
||||||
|
type: ACTIONS.SEARCH_RESULTS,
|
||||||
|
results: {
|
||||||
|
results: [],
|
||||||
|
type: null,
|
||||||
|
keyword: null,
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ export const defaultState = {
|
|||||||
isLoginNavigator: false,
|
isLoginNavigator: false,
|
||||||
currenEditingNote: null,
|
currenEditingNote: null,
|
||||||
loading: true,
|
loading: true,
|
||||||
searchResults: [],
|
searchResults: {
|
||||||
|
results: [],
|
||||||
|
type: null,
|
||||||
|
keyword: null,
|
||||||
|
},
|
||||||
keyword: [],
|
keyword: [],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export const reducer = (state, action) => {
|
|||||||
let results = action.results;
|
let results = action.results;
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
searchResults: [...results],
|
searchResults: {...results},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user