mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
commit
28d858cab7
@ -21,19 +21,20 @@ export default function SearchPage({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { config } = useOcean()
|
const { config } = useOcean()
|
||||||
const parsed = queryString.parse(location.search)
|
const parsed = queryString.parse(location.search)
|
||||||
const { text, tag, page } = parsed
|
const { text, tags, page } = parsed
|
||||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||||
const [loading, setLoading] = useState<boolean>()
|
const [loading, setLoading] = useState<boolean>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initSearch() {
|
async function initSearch() {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
console.log(parsed)
|
||||||
const queryResult = await getResults(parsed, config.metadataCacheUri)
|
const queryResult = await getResults(parsed, config.metadataCacheUri)
|
||||||
setQueryResult(queryResult)
|
setQueryResult(queryResult)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
initSearch()
|
initSearch()
|
||||||
}, [text, tag, page, config.metadataCacheUri])
|
}, [text, tags, page, config.metadataCacheUri])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.grid}>
|
<section className={styles.grid}>
|
||||||
|
@ -8,14 +8,14 @@ export function getSearchQuery(
|
|||||||
page?: string | string[],
|
page?: string | string[],
|
||||||
offset?: string | string[],
|
offset?: string | string[],
|
||||||
text?: string | string[],
|
text?: string | string[],
|
||||||
tag?: string | string[]
|
tags?: string | string[]
|
||||||
): SearchQuery {
|
): SearchQuery {
|
||||||
return {
|
return {
|
||||||
page: Number(page) || 1,
|
page: Number(page) || 1,
|
||||||
offset: Number(offset) || 20,
|
offset: Number(offset) || 20,
|
||||||
query: {
|
query: {
|
||||||
text,
|
text,
|
||||||
tags: tag ? [tag] : undefined
|
tags: tags ? [tags] : undefined
|
||||||
},
|
},
|
||||||
sort: {
|
sort: {
|
||||||
created: -1
|
created: -1
|
||||||
@ -29,14 +29,16 @@ export function getSearchQuery(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getResults(
|
export async function getResults(
|
||||||
params: { text?: string; tag?: string; page?: string; offset?: string },
|
params: { text?: string; tags?: string; page?: string; offset?: string },
|
||||||
metadataCacheUri: string
|
metadataCacheUri: string
|
||||||
): Promise<QueryResult> {
|
): Promise<QueryResult> {
|
||||||
const { text, tag, page, offset } = params
|
const { text, tags, page, offset } = params
|
||||||
|
|
||||||
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
|
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
|
||||||
|
const sQuery = getSearchQuery(page, offset, text, tags)
|
||||||
|
console.log(sQuery)
|
||||||
const queryResult = await metadataCache.queryMetadata(
|
const queryResult = await metadataCache.queryMetadata(
|
||||||
getSearchQuery(page, offset, text, tag)
|
getSearchQuery(page, offset, text, tags)
|
||||||
)
|
)
|
||||||
|
|
||||||
return queryResult
|
return queryResult
|
||||||
|
Loading…
Reference in New Issue
Block a user