1
0
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:
Jamie Hewitt 2021-05-10 12:38:24 +03:00 committed by GitHub
parent 96a32242fd
commit f5da6e4b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -17,20 +17,30 @@ export default function SearchBar({
filters?: boolean
size?: 'small' | 'large'
}): ReactElement {
const [value, setValue] = useState(initialValue || '')
function handleChange(e: ChangeEvent<HTMLInputElement>) {
setValue(e.target.value)
}
let [value, setValue] = useState(initialValue || '')
async function startSearch(e: FormEvent<HTMLButtonElement>) {
e.preventDefault()
if (value === '') return
if (value === '') value = ' '
const urlEncodedValue = encodeURIComponent(value)
const url = await addExistingParamsToUrl(location, 'text')
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 (
<form className={styles.form}>
<InputGroup>

View File

@ -20,7 +20,7 @@ export default function PageGatsbySearch(props: PageProps): ReactElement {
? `Published by ${accountTruncate(owner as string)}`
: `${
totalResults !== undefined
? searchValue
? searchValue && searchValue !== ' '
? totalResults === 0
? 'No results'
: totalResults +