1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

fix search by tag

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-10-22 15:46:11 +03:00
parent ff1ddb65d6
commit 9350026552
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29
2 changed files with 10 additions and 7 deletions

View File

@ -21,19 +21,20 @@ export default function SearchPage({
}): ReactElement {
const { config } = useOcean()
const parsed = queryString.parse(location.search)
const { text, tag, page } = parsed
const { text, tags, page } = parsed
const [queryResult, setQueryResult] = useState<QueryResult>()
const [loading, setLoading] = useState<boolean>()
useEffect(() => {
async function initSearch() {
setLoading(true)
console.log(parsed)
const queryResult = await getResults(parsed, config.metadataCacheUri)
setQueryResult(queryResult)
setLoading(false)
}
initSearch()
}, [text, tag, page, config.metadataCacheUri])
}, [text, tags, page, config.metadataCacheUri])
return (
<section className={styles.grid}>

View File

@ -8,14 +8,14 @@ export function getSearchQuery(
page?: string | string[],
offset?: string | string[],
text?: string | string[],
tag?: string | string[]
tags?: string | string[]
): SearchQuery {
return {
page: Number(page) || 1,
offset: Number(offset) || 20,
query: {
text,
tags: tag ? [tag] : undefined
tags: tags ? [tags] : undefined
},
sort: {
created: -1
@ -29,14 +29,16 @@ export function getSearchQuery(
}
export async function getResults(
params: { text?: string; tag?: string; page?: string; offset?: string },
params: { text?: string; tags?: string; page?: string; offset?: string },
metadataCacheUri: string
): Promise<QueryResult> {
const { text, tag, page, offset } = params
const { text, tags, page, offset } = params
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
const sQuery = getSearchQuery(page, offset, text, tags)
console.log(sQuery)
const queryResult = await metadataCache.queryMetadata(
getSearchQuery(page, offset, text, tag)
getSearchQuery(page, offset, text, tags)
)
return queryResult