diff --git a/packages/ui/src/components/menu/filterinput.js b/packages/ui/src/components/menu/filterinput.js index c038bf6c1..db900c588 100644 --- a/packages/ui/src/components/menu/filterinput.js +++ b/packages/ui/src/components/menu/filterinput.js @@ -21,9 +21,8 @@ import { hexToRGB } from "../../utils/color"; import DatePicker from "react-datepicker"; import "react-datepicker/dist/react-datepicker.css"; import "./datepicker.css"; -import { filterSearchEngine } from "./search"; import { Text } from "@theme-ui/components"; -import { mainSearchEngine } from "./search"; +import { db } from "../../common/db"; export function FilterInput(props) { const { @@ -59,7 +58,7 @@ export function FilterInput(props) { { await checkErrors(props, e.target.innerText); setSuggestions(await getSuggestions(e.target.innerText, item.input)); @@ -171,42 +170,16 @@ const checkErrors = async (props, query) => { const { setFilters, index, item } = props; query = query.trim(); let input = item.input; - let result = await (await mainSearchEngine(input.type, query)).result; + let result = await (await db.search.filter(input.filterName, query)).result; + let error = true; + if (!input.hasSuggestions || result.length > 0) error = false; setFilters((filters) => { let _filters = [...filters]; - _filters[index].input.state = filterInputState(input, result, query); + _filters[index].input.error = error; return _filters; }); }; -const filterInputState = (input, result, query) => { - console.log( - "filterInputState", - input.id, - query, - !input.hasSuggestions, - result.length > 0 - ); - if (!input.hasSuggestions) - return { - error: false, - message: "", - result: { type: input.type, value: query } - }; - - if (result.length > 0) - return { error: false, message: "", result: result[0] }; - - return { - error: true, - message: `This ${input.type.replace( - "s", - "" - )} is not present in the database.`, - result: undefined - }; -}; - const deleteDefinition = (definitions, id) => { let index = 0; for (let definition of definitions) { @@ -243,7 +216,7 @@ const onKeyPress = async (e, props) => { Enter: async () => { props.onKeyDown(e); focusInput(index + 1); - let results = await filterSearchEngine(searchDefinitions); + let results = await db.search.filters(searchDefinitions); onSearch(results); setSuggestions([]); e.preventDefault(); diff --git a/packages/ui/src/components/menu/search.js b/packages/ui/src/components/menu/search.js index 4a735a83b..cf1048bf1 100644 --- a/packages/ui/src/components/menu/search.js +++ b/packages/ui/src/components/menu/search.js @@ -20,13 +20,13 @@ import { store } from "../../stores/note-store"; import { db } from "../../common/db"; import { filter, parse } from "liqe"; -export const mainSearchEngine = async (searchType, value) => { +export const mainSearchEngine = async (filter, query) => { //name is cumbersome // better name? fetchResults const context = store.context; - const [lookupType, allData] = await filterItemsToType(searchType, context); + const [lookupType, allData] = await filterItemsToType(filter, context); if (lookupType !== undefined && allData !== undefined) { - let result = await db.lookup[lookupType](allData, value); + let result = await db.lookup[lookupType](allData, query); return { result, allData }; } else { return { result: [], allData: [] }; @@ -65,7 +65,15 @@ const beginSearch = async (definition, type) => { console.log("beginSearch", definition); let notes = []; type = type.trim(); +<<<<<<< Updated upstream +<<<<<<< Updated upstream + db.notebooks.notebook(); +======= +>>>>>>> Stashed changes +======= + +>>>>>>> Stashed changes switch (type) { case "notebook": { console.log("beginSearch", definition.topics); @@ -78,6 +86,20 @@ const beginSearch = async (definition, type) => { } } console.log("beginSearch notebook", notes); +<<<<<<< Updated upstream +<<<<<<< Updated upstream +======= +>>>>>>> Stashed changes + return notes; + } + case "notes": { + console.log("beginSearch notes", notes); + let allNotes = db.notes.all; + let notes = await db.lookup["notes"](allNotes, definition.value); +<<<<<<< Updated upstream + return notes; + } +======= return notes; } case "notes": { @@ -86,6 +108,11 @@ const beginSearch = async (definition, type) => { let notes = await db.lookup["notes"](allNotes, definition.value); return notes; } +>>>>>>> Stashed changes +======= + return notes; + } +>>>>>>> Stashed changes case "topic": { for (let note of definition.notes) { if (db.notes.note(note)) notes.push(db.notes.note(note)._note);