From e6ebdfb2c1229c3e548bf5886495be81627ffee6 Mon Sep 17 00:00:00 2001 From: eyworldwide Date: Fri, 22 Mar 2024 16:57:40 +0800 Subject: [PATCH] refactor: search context --- src/components/header/components/SearchResults.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/header/components/SearchResults.tsx b/src/components/header/components/SearchResults.tsx index c8f88db1b..101ffae46 100644 --- a/src/components/header/components/SearchResults.tsx +++ b/src/components/header/components/SearchResults.tsx @@ -5,6 +5,7 @@ import { useIntl } from 'react-intl'; import { AppContext } from '../../contextProvider'; import { APISearchResponse, searchAPI, searchDoc } from '../headerUtils'; import DocSearchRes from './SearchResult'; +import { useLocation } from 'react-router-dom'; interface ISearchResProps { searchText: string; @@ -33,8 +34,18 @@ const SearchResult = (props: ISearchResProps) => { const PAGE_SIZE = '20'; + const {pathname} = useLocation(); + let searchContext = 'docs'; + + if (pathname.indexOf('/api/') > -1) { + searchContext = 'api'; + } + else if (pathname.indexOf('/examples/') > -1) { + searchContext = 'examples'; + } + const searchResultTab = ( - +