mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
displayed search results count (#312)
* displayed search results count * updated unit test for Search component * account for singular & plural, display message if there's no result
This commit is contained in:
parent
50f15fa294
commit
b5f6f9c9c1
@ -9,9 +9,11 @@ import Loader from '../../atoms/Loader'
|
|||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
|
|
||||||
export default function SearchPage({
|
export default function SearchPage({
|
||||||
location
|
location,
|
||||||
|
setTotalResults
|
||||||
}: {
|
}: {
|
||||||
location: Location
|
location: Location
|
||||||
|
setTotalResults: (totalResults: number) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { config } = useOcean()
|
const { config } = useOcean()
|
||||||
const parsed = queryString.parse(location.search)
|
const parsed = queryString.parse(location.search)
|
||||||
@ -24,8 +26,10 @@ export default function SearchPage({
|
|||||||
|
|
||||||
async function initSearch() {
|
async function initSearch() {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
setTotalResults(undefined)
|
||||||
const queryResult = await getResults(parsed, config.metadataCacheUri)
|
const queryResult = await getResults(parsed, config.metadataCacheUri)
|
||||||
setQueryResult(queryResult)
|
setQueryResult(queryResult)
|
||||||
|
setTotalResults(queryResult.totalResults)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
initSearch()
|
initSearch()
|
||||||
@ -38,7 +42,6 @@ export default function SearchPage({
|
|||||||
<SearchBar initialValue={(text || owner) as string} />
|
<SearchBar initialValue={(text || owner) as string} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.results}>
|
<div className={styles.results}>
|
||||||
{loading ? <Loader /> : <AssetQueryList queryResult={queryResult} />}
|
{loading ? <Loader /> : <AssetQueryList queryResult={queryResult} />}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useState } from 'react'
|
||||||
import PageSearch from '../components/templates/Search'
|
import PageSearch from '../components/templates/Search'
|
||||||
import { PageProps } from 'gatsby'
|
import { PageProps } from 'gatsby'
|
||||||
import Page from '../components/templates/Page'
|
import Page from '../components/templates/Page'
|
||||||
@ -9,6 +9,7 @@ import ethereumAddress from 'ethereum-address'
|
|||||||
export default function PageGatsbySearch(props: PageProps): ReactElement {
|
export default function PageGatsbySearch(props: PageProps): ReactElement {
|
||||||
const parsed = queryString.parse(props.location.search)
|
const parsed = queryString.parse(props.location.search)
|
||||||
const { text, owner, tags, categories } = parsed
|
const { text, owner, tags, categories } = parsed
|
||||||
|
const [totalResults, setTotalResults] = useState<number>()
|
||||||
|
|
||||||
const isETHAddress = ethereumAddress.isAddress(text as string)
|
const isETHAddress = ethereumAddress.isAddress(text as string)
|
||||||
const searchValue =
|
const searchValue =
|
||||||
@ -17,11 +18,25 @@ export default function PageGatsbySearch(props: PageProps): ReactElement {
|
|||||||
categories
|
categories
|
||||||
const title = owner
|
const title = owner
|
||||||
? `Published by ${accountTruncate(owner as string)}`
|
? `Published by ${accountTruncate(owner as string)}`
|
||||||
: `Search for ${searchValue || 'all data sets'}`
|
: `${
|
||||||
|
totalResults !== undefined
|
||||||
|
? searchValue
|
||||||
|
? totalResults === 0
|
||||||
|
? 'No results'
|
||||||
|
: totalResults +
|
||||||
|
(totalResults > 1 ? ' results' : ' result') +
|
||||||
|
' for ' +
|
||||||
|
searchValue
|
||||||
|
: totalResults + ' datasets'
|
||||||
|
: 'Searching...'
|
||||||
|
}`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page title={title} uri={props.uri}>
|
<Page title={title} uri={props.uri}>
|
||||||
<PageSearch location={props.location} />
|
<PageSearch
|
||||||
|
location={props.location}
|
||||||
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
||||||
|
/>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,16 @@ import {
|
|||||||
describe('Search', () => {
|
describe('Search', () => {
|
||||||
it('renders without crashing', async () => {
|
it('renders without crashing', async () => {
|
||||||
const history = createHistory(createMemorySource('/search?text=water'))
|
const history = createHistory(createMemorySource('/search?text=water'))
|
||||||
|
const setTotalResults = (totalResults: number) => {
|
||||||
|
const results = totalResults
|
||||||
|
}
|
||||||
|
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<LocationProvider history={history}>
|
<LocationProvider history={history}>
|
||||||
<Search location={{ search: '?text=water' } as any} />
|
<Search
|
||||||
|
location={{ search: '?text=water' } as any}
|
||||||
|
setTotalResults={(totalResults) => setTotalResults(totalResults)}
|
||||||
|
/>
|
||||||
</LocationProvider>
|
</LocationProvider>
|
||||||
)
|
)
|
||||||
expect(container.firstChild).toBeInTheDocument()
|
expect(container.firstChild).toBeInTheDocument()
|
||||||
|
Loading…
Reference in New Issue
Block a user