added query string to url and fixed test and clear buttons
This commit is contained in:
parent
1fdd5dcc0c
commit
493e43b38b
1 changed files with 28 additions and 19 deletions
|
@ -114,7 +114,7 @@ function _Search() {
|
||||||
|
|
||||||
const [postCards, setPostCards] = useState<unknown[]>([])
|
const [postCards, setPostCards] = useState<unknown[]>([])
|
||||||
|
|
||||||
const [searchInput, setSearchInput] = useState("")
|
const [searchInput, setSearchInput] = useState(query.query)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -165,12 +165,29 @@ function _Search() {
|
||||||
<StyledSearchControlContainer>
|
<StyledSearchControlContainer>
|
||||||
<StyledInput
|
<StyledInput
|
||||||
type="text"
|
type="text"
|
||||||
|
value={searchInput}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setSearchInput(event.target.value)
|
setSearchInput(event.target.value)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
_history.push({
|
||||||
|
pathname: "/search",
|
||||||
|
search: queryString.stringify({
|
||||||
|
...(query.from && {
|
||||||
|
from: query.from,
|
||||||
|
}),
|
||||||
|
...(query.to && {
|
||||||
|
to: query.to,
|
||||||
|
}),
|
||||||
|
...(query.tags.length > 0 && {
|
||||||
|
tags: query.tags.join(","),
|
||||||
|
}),
|
||||||
|
query: searchInput,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const _postCards: unknown[] = []
|
const _postCards: unknown[] = []
|
||||||
for (const res of index.search(
|
for (const res of index.search(
|
||||||
|
@ -205,22 +222,6 @@ function _Search() {
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-empty
|
// eslint-disable-next-line no-empty
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
_history.push({
|
|
||||||
pathname: "/search",
|
|
||||||
search: queryString.stringify({
|
|
||||||
...(query.from && {
|
|
||||||
from: query.from,
|
|
||||||
}),
|
|
||||||
...(query.to && {
|
|
||||||
to: query.to,
|
|
||||||
}),
|
|
||||||
...(query.tags && {
|
|
||||||
tags: query.tags.join(","),
|
|
||||||
}),
|
|
||||||
query: searchInput,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Search
|
Search
|
||||||
|
@ -244,6 +245,9 @@ function _Search() {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
search: queryString.stringify({
|
search: queryString.stringify({
|
||||||
|
...(query.query && {
|
||||||
|
query: query.query,
|
||||||
|
}),
|
||||||
...(query.from && {
|
...(query.from && {
|
||||||
from: query.from,
|
from: query.from,
|
||||||
}),
|
}),
|
||||||
|
@ -263,6 +267,9 @@ function _Search() {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
search: queryString.stringify({
|
search: queryString.stringify({
|
||||||
|
...(query.query && {
|
||||||
|
query: query.query,
|
||||||
|
}),
|
||||||
...(query.from && {
|
...(query.from && {
|
||||||
from: query.from,
|
from: query.from,
|
||||||
}),
|
}),
|
||||||
|
@ -282,8 +289,10 @@ function _Search() {
|
||||||
_history.push({
|
_history.push({
|
||||||
pathname: "/search",
|
pathname: "/search",
|
||||||
search: queryString.stringify({
|
search: queryString.stringify({
|
||||||
query: query.query,
|
...(query.query && {
|
||||||
...(query.tags && {
|
query: query.query,
|
||||||
|
}),
|
||||||
|
...(query.tags.length > 0 && {
|
||||||
tags: query.tags.join(","),
|
tags: query.tags.join(","),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue