Add onEnter search

This commit is contained in:
ismailsosic
2023-03-08 12:08:29 +01:00
parent c19a3481d6
commit c39df7ec32
26 changed files with 189 additions and 252 deletions

View File

@@ -9,11 +9,14 @@ const Result = ({result, term}) => {
let sentences
const checkForMatches = (props) => {
if(props.length !== 1) return sentences.map((sentence) => {
sentence.toLowerCase().includes(term.toLowerCase()) ? setTitle(sentence) : null
if(props.length === 1) return setTitle(props)
if(props.length > 1 ){
return sentences.map((sentence) => {
if(sentence.toLowerCase().includes(term.toLowerCase())) setTitle(sentence)
else setTitle(props[0])
})
return setTitle(text)
}
}
@@ -26,7 +29,7 @@ const Result = ({result, term}) => {
useEffect(() => {
sentences = splitText()
checkForMatches(sentences)
})
}, [])
// ako term nije pronadjen u textu onda
// treba provjeriti duzinu niza, ako niz ima jednu recenicu, recenica treba biti title, ako ne, naci medju recenicama onu koja ima term u sebi

View File

@@ -3,6 +3,7 @@ import Result from './Result'
const Results = ({data, term}) => {
console.log(data)
return (
<div className='