mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Issue 560 empty search (#561)
* upgrading to ocean.js 0.14.6 * Empty search gives all results * Using ocean.js 13.0 * onBlur empty search when deleting text * making empty search automatic on change * removing console log messages * including the search bar on results page * keeping searchbox visible after an empty search * refactoring If statement
This commit is contained in:
parent
96a32242fd
commit
f5da6e4b0b
@ -17,20 +17,30 @@ export default function SearchBar({
|
|||||||
filters?: boolean
|
filters?: boolean
|
||||||
size?: 'small' | 'large'
|
size?: 'small' | 'large'
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [value, setValue] = useState(initialValue || '')
|
let [value, setValue] = useState(initialValue || '')
|
||||||
|
|
||||||
function handleChange(e: ChangeEvent<HTMLInputElement>) {
|
|
||||||
setValue(e.target.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startSearch(e: FormEvent<HTMLButtonElement>) {
|
async function startSearch(e: FormEvent<HTMLButtonElement>) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (value === '') return
|
if (value === '') value = ' '
|
||||||
const urlEncodedValue = encodeURIComponent(value)
|
const urlEncodedValue = encodeURIComponent(value)
|
||||||
const url = await addExistingParamsToUrl(location, 'text')
|
const url = await addExistingParamsToUrl(location, 'text')
|
||||||
navigate(`${url}&text=${urlEncodedValue}`)
|
navigate(`${url}&text=${urlEncodedValue}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function emptySearch() {
|
||||||
|
const searchParams = new URLSearchParams(window.location.href)
|
||||||
|
const text = searchParams.get('text')
|
||||||
|
if (text !== ('' || undefined || null)) {
|
||||||
|
const url = await addExistingParamsToUrl(location, 'text')
|
||||||
|
navigate(`${url}&text=%20`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChange(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
setValue(e.target.value)
|
||||||
|
e.target.value === '' && emptySearch()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className={styles.form}>
|
<form className={styles.form}>
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
|
@ -20,7 +20,7 @@ export default function PageGatsbySearch(props: PageProps): ReactElement {
|
|||||||
? `Published by ${accountTruncate(owner as string)}`
|
? `Published by ${accountTruncate(owner as string)}`
|
||||||
: `${
|
: `${
|
||||||
totalResults !== undefined
|
totalResults !== undefined
|
||||||
? searchValue
|
? searchValue && searchValue !== ' '
|
||||||
? totalResults === 0
|
? totalResults === 0
|
||||||
? 'No results'
|
? 'No results'
|
||||||
: totalResults +
|
: totalResults +
|
||||||
|
Loading…
Reference in New Issue
Block a user