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

View File

@ -14,4 +14,5 @@
.empty { .empty {
color: var(--color-secondary); color: var(--color-secondary);
font-size: var(--font-size-small); 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}> <div className={styles.empty}>
No data sets found in {appConfig.oceanConfig.metadataStoreUri} No results found in {appConfig.oceanConfig.metadataStoreUri}
</div> </div>
)} )}
</div> </div>

View File

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

View File

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