change result title display
This commit is contained in:
@@ -15,11 +15,6 @@
|
||||
],
|
||||
"rootMainFiles": [],
|
||||
"pages": {
|
||||
"/": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main.js",
|
||||
"static/chunks/pages/index.js"
|
||||
],
|
||||
"/_app": [
|
||||
"static/chunks/webpack.js",
|
||||
"static/chunks/main.js",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
self.__BUILD_MANIFEST={"polyfillFiles":["static/chunks/polyfills.js"],"devFiles":["static/chunks/react-refresh.js"],"ampDevFiles":["static/chunks/webpack.js","static/chunks/amp.js"],"lowPriorityFiles":["static/development/_buildManifest.js","static/development/_ssgManifest.js"],"rootMainFiles":[],"pages":{"/":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/index.js"],"/_app":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_app.js"],"/_error":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_error.js"],"/search":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/search.js"]},"ampFirstPages":[]}
|
||||
self.__BUILD_MANIFEST={"polyfillFiles":["static/chunks/polyfills.js"],"devFiles":["static/chunks/react-refresh.js"],"ampDevFiles":["static/chunks/webpack.js","static/chunks/amp.js"],"lowPriorityFiles":["static/development/_buildManifest.js","static/development/_ssgManifest.js"],"rootMainFiles":[],"pages":{"/_app":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_app.js"],"/_error":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/_error.js"],"/search":["static/chunks/webpack.js","static/chunks/main.js","static/chunks/pages/search.js"]},"ampFirstPages":[]}
|
||||
@@ -2,6 +2,5 @@
|
||||
"/_app": "pages/_app.js",
|
||||
"/_error": "pages/_error.js",
|
||||
"/_document": "pages/_document.js",
|
||||
"/": "pages/index.js",
|
||||
"/search": "pages/search.js"
|
||||
}
|
||||
@@ -131,7 +131,7 @@
|
||||
/******/
|
||||
/******/ /* webpack/runtime/getFullHash */
|
||||
/******/ !function() {
|
||||
/******/ __webpack_require__.h = function() { return "06125453a5487fc9"; }
|
||||
/******/ __webpack_require__.h = function() { return "93e21dfb81445514"; }
|
||||
/******/ }();
|
||||
/******/
|
||||
/******/ /* webpack/runtime/global */
|
||||
|
||||
@@ -1 +1 @@
|
||||
self.__BUILD_MANIFEST = {__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/":["static\u002Fchunks\u002Fpages\u002Findex.js"],"/_error":["static\u002Fchunks\u002Fpages\u002F_error.js"],"/search":["static\u002Fchunks\u002Fpages\u002Fsearch.js"],sortedPages:["\u002F","\u002F_app","\u002F_error","\u002Fsearch"]};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()
|
||||
self.__BUILD_MANIFEST = {__rewrites:{beforeFiles:[],afterFiles:[],fallback:[]},"/_error":["static\u002Fchunks\u002Fpages\u002F_error.js"],"/search":["static\u002Fchunks\u002Fpages\u002Fsearch.js"],sortedPages:["\u002F_app","\u002F_error","\u002Fsearch"]};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()
|
||||
File diff suppressed because one or more lines are too long
@@ -1,10 +1,35 @@
|
||||
import React from 'react'
|
||||
import { React, useEffect, useState} from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
const Result = ({result}) => {
|
||||
const Result = ({result, term}) => {
|
||||
|
||||
const router = useRouter()
|
||||
const {book, writer, text, page} = result._source
|
||||
const {book, writer, text} = result._source
|
||||
const [title, setTitle] = useState()
|
||||
let sentences
|
||||
|
||||
const checkForMatches = (props) => {
|
||||
if(props.length !== 1) return sentences.map((sentence) => {
|
||||
sentence.toLowerCase().includes(term.toLowerCase()) ? setTitle(sentence) : null
|
||||
})
|
||||
|
||||
return setTitle(text)
|
||||
|
||||
}
|
||||
|
||||
const splitText = () => {
|
||||
try{
|
||||
return text.match( /[^\.!\?]+[\.!\?]+/g)
|
||||
}catch{err => console.log(err)}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
return (
|
||||
<div onClick={() => (router.push({pathname: `/${result._type}/${result._id}`}))} className='
|
||||
@@ -21,8 +46,8 @@ const Result = ({result}) => {
|
||||
laptop:text-lg
|
||||
'
|
||||
>
|
||||
<p className='m-3'>{text}</p>
|
||||
<p className='m-3'>"{book}" - {writer} - str. {page}.</p>
|
||||
<p className='m-3'>{title}</p>
|
||||
<p className='m-3'>"{book}" - {writer} - str. {result._id}.</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import Result from './Result'
|
||||
|
||||
const Results = ({data}) => {
|
||||
const Results = ({data, term}) => {
|
||||
|
||||
|
||||
return (
|
||||
@@ -19,7 +19,7 @@ const Results = ({data}) => {
|
||||
|
||||
|
||||
'>
|
||||
{data.map((result) => <Result key={result._id} result={result}/>)}
|
||||
{data.map((result) => <Result key={result._id} result={result} term={term}/>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ const SearchPage = ({data}) => {
|
||||
<i className='rounded-3xl text-[#9aa0a6] px-3' onClick={() => setSearchInput("")}><AiOutlineClose size={25} /></i>
|
||||
</div>
|
||||
</div>
|
||||
<Results data={data.hits.hits}/>
|
||||
<Results data={data.hits.hits} term={searchInput}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user