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:
parent
ff1ddb65d6
commit
9350026552
@ -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}>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user