From 93500265524feb2fd84c3f6aa177eafe9f1ddcac Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 22 Oct 2020 15:46:11 +0300 Subject: [PATCH] fix search by tag Signed-off-by: mihaisc --- src/components/templates/Search/index.tsx | 5 +++-- src/components/templates/Search/utils.ts | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/components/templates/Search/index.tsx b/src/components/templates/Search/index.tsx index ae7748357..629a19392 100644 --- a/src/components/templates/Search/index.tsx +++ b/src/components/templates/Search/index.tsx @@ -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() const [loading, setLoading] = useState() 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 (
diff --git a/src/components/templates/Search/utils.ts b/src/components/templates/Search/utils.ts index 6f076be2b..0ae7973ea 100644 --- a/src/components/templates/Search/utils.ts +++ b/src/components/templates/Search/utils.ts @@ -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 { - 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