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

Merge pull request #118 from oceanprotocol/fix/113

Fixes search by tag
This commit is contained in:
Matthias Kretschmann 2020-10-22 16:26:27 +02:00 committed by GitHub
commit 28d858cab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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