search on page load
This commit is contained in:
parent
02234fcf22
commit
0af1c625d4
1 changed files with 4 additions and 11 deletions
|
@ -106,7 +106,7 @@ export default function Search() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _Search() {
|
function _Search() {
|
||||||
const [index, setIndex] = useState({} as elasticlunr.Index<unknown>)
|
const [index] = useState(elasticlunr.Index.load(searchIndex as never))
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
const _history = useHistory()
|
const _history = useHistory()
|
||||||
|
@ -135,10 +135,6 @@ function _Search() {
|
||||||
const [searchInput, setSearchInput] = useState(query.query)
|
const [searchInput, setSearchInput] = useState(query.query)
|
||||||
|
|
||||||
function doSearch() {
|
function doSearch() {
|
||||||
// remove focus from search bar to prevent accidental multiple search
|
|
||||||
// if (document.activeElement instanceof HTMLElement)
|
|
||||||
// document.activeElement.blur()
|
|
||||||
|
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
search: queryString.stringify({
|
search: queryString.stringify({
|
||||||
|
@ -182,14 +178,11 @@ function _Search() {
|
||||||
setPostCards(_postCards)
|
setPostCards(_postCards)
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-empty
|
// eslint-disable-next-line no-empty
|
||||||
} catch (err) {}
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load search index only once
|
|
||||||
useEffect(() => {
|
|
||||||
setIndex(elasticlunr.Index.load(searchIndex as never))
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
doSearch()
|
doSearch()
|
||||||
}, [dateRange])
|
}, [dateRange])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue