1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 09:14:52 +01:00

more search loading interaction tweaks

This commit is contained in:
Matthias Kretschmann 2020-07-15 15:47:25 +02:00
parent c1064f84f8
commit 77db807ae8
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 7 additions and 21 deletions

View File

@ -1,7 +1,6 @@
import React, { useState, ChangeEvent, FormEvent, ReactElement } from 'react'
import { useNavigate } from '@reach/router'
import styles from './SearchBar.module.css'
import Loader from '../atoms/Loader'
import Button from '../atoms/Button'
import Input from '../atoms/Input'
import InputGroup from '../atoms/Input/InputGroup'
@ -19,7 +18,6 @@ export default function SearchBar({
}): ReactElement {
const navigate = useNavigate()
const [value, setValue] = useState(initialValue || '')
const [searchStarted, setSearchStarted] = useState(false)
function handleChange(e: ChangeEvent<HTMLInputElement>) {
setValue(e.target.value)
@ -27,10 +25,7 @@ export default function SearchBar({
function startSearch(e: FormEvent<HTMLButtonElement>) {
e.preventDefault()
if (value === '') return
setSearchStarted(true)
navigate(`/search?text=${value}`)
}
@ -46,7 +41,7 @@ export default function SearchBar({
required
/>
<Button onClick={(e: FormEvent<HTMLButtonElement>) => startSearch(e)}>
{searchStarted ? <Loader /> : 'Search'}
Search
</Button>
</InputGroup>

View File

@ -14,4 +14,5 @@
.empty {
color: var(--color-secondary);
font-size: var(--font-size-small);
font-style: italic;
}

View File

@ -53,7 +53,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
})
) : (
<div className={styles.empty}>
No data sets found in {appConfig.oceanConfig.metadataStoreUri}
No results found in {appConfig.oceanConfig.metadataStoreUri}
</div>
)}
</div>

View File

@ -1,8 +1,3 @@
.empty {
color: var(--color-secondary);
font-style: italic;
}
.grid {
display: grid;
}

View File

@ -23,16 +23,17 @@ export default function SearchPage({
const parsed = queryString.parse(location.search)
const { text, tag } = parsed
const [queryResult, setQueryResult] = useState<QueryResult>()
const [loading, setLoading] = useState(true)
const [loading, setLoading] = useState<boolean>()
useEffect(() => {
async function initSearch() {
setLoading(true)
const queryResult = await getResults(parsed)
setQueryResult(queryResult)
setLoading(false)
}
initSearch()
}, [])
}, [text, tag])
return (
<section className={styles.grid}>
@ -45,13 +46,7 @@ export default function SearchPage({
</aside>
<div className={styles.results}>
{loading ? (
<Loader />
) : queryResult && queryResult.results.length > 0 ? (
<AssetList queryResult={queryResult} />
) : (
<div className={styles.empty}>No results found.</div>
)}
{loading ? <Loader /> : <AssetList queryResult={queryResult} />}
</div>
</section>
)