1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
market/src/pages/search.tsx
Jamie Hewitt f5da6e4b0b
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
2021-05-10 12:38:24 +03:00

43 lines
1.4 KiB
TypeScript

import React, { ReactElement, useState } from 'react'
import PageSearch from '../components/templates/Search'
import { PageProps } from 'gatsby'
import Page from '../components/templates/Page'
import queryString from 'query-string'
import { accountTruncate } from '../utils/web3'
import ethereumAddress from 'ethereum-address'
export default function PageGatsbySearch(props: PageProps): ReactElement {
const parsed = queryString.parse(props.location.search)
const { text, owner, tags, categories } = parsed
const [totalResults, setTotalResults] = useState<number>()
const isETHAddress = ethereumAddress.isAddress(text as string)
const searchValue =
(isETHAddress ? accountTruncate(text as string) : text) ||
tags ||
categories
const title = owner
? `Published by ${accountTruncate(owner as string)}`
: `${
totalResults !== undefined
? searchValue && searchValue !== ' '
? totalResults === 0
? 'No results'
: totalResults +
(totalResults > 1 ? ' results' : ' result') +
' for ' +
searchValue
: totalResults + ' results'
: 'Searching...'
}`
return (
<Page title={title} uri={props.uri}>
<PageSearch
location={props.location}
setTotalResults={(totalResults) => setTotalResults(totalResults)}
/>
</Page>
)
}