1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
market/src/pages/search.tsx
mihaisc 57be62a6b1
Refactor pricing and various components that are involved (#1046)
* update

* merge pr #1012

* fix header

* fix

* abort controller

* up next.8

* build fix

* update lock

* fix

* another fix

* ssh fix

* another ssh fix

* remove optional

* order mock

* small cleanup

* fix package

* price updates

* finish getPrice

* fix consume

* fix consume

* getConsumeDetails  comments

* restore functionality after consumeDetails

* fix some compute typings

* more price fetching updates

* 'minor' refactors and fixed build

* package-lock fix

* minor comments

* minor naming changes

* fix

* fix pool badge

* remove console.log
2022-02-03 03:29:39 -08:00

60 lines
1.8 KiB
TypeScript

import React, { ReactElement, useState } from 'react'
import Search from '../components/Search'
import Page from '@shared/Page'
import { accountTruncate } from '@utils/web3'
import { MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS } from '@utils/aquarius'
import { useRouter } from 'next/router'
import web3 from 'web3'
export default function PageSearch(): ReactElement {
const router = useRouter()
const parsed = router.query
const { text, owner, tags, categories } = parsed
const [totalResults, setTotalResults] = useState<number>()
const [totalPagesNumber, setTotalPagesNumber] = useState<number>()
const isETHAddress = web3.utils.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={
totalPagesNumber > MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS
? `>10000 results ${
searchValue && searchValue !== ' ' ? `for ${searchValue}` : ''
}`
: title
}
description={
totalPagesNumber &&
totalPagesNumber > MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS
? '**Results displayed are limited to the first 10k, please refine your search.**'
: undefined
}
uri={router.route}
>
<Search
setTotalResults={setTotalResults}
setTotalPagesNumber={setTotalPagesNumber}
/>
</Page>
)
}