Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit e6ebdfb

Browse files
committed
refactor: search context
1 parent 414a8d7 commit e6ebdfb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/components/header/components/SearchResults.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useIntl } from 'react-intl';
55
import { AppContext } from '../../contextProvider';
66
import { APISearchResponse, searchAPI, searchDoc } from '../headerUtils';
77
import DocSearchRes from './SearchResult';
8+
import { useLocation } from 'react-router-dom';
89

910
interface ISearchResProps {
1011
searchText: string;
@@ -33,8 +34,18 @@ const SearchResult = (props: ISearchResProps) => {
3334

3435
const PAGE_SIZE = '20';
3536

37+
const {pathname} = useLocation();
38+
let searchContext = 'docs';
39+
40+
if (pathname.indexOf('/api/') > -1) {
41+
searchContext = 'api';
42+
}
43+
else if (pathname.indexOf('/examples/') > -1) {
44+
searchContext = 'examples';
45+
}
46+
3647
const searchResultTab = (
37-
<Tabs defaultValue='docs' closable>
48+
<Tabs defaultValue={searchContext} closable>
3849
<StyledTabList
3950
tabs={[
4051
{

0 commit comments

Comments
 (0)