Skip to content

Commit c02b0f5

Browse files
committed
fix: Add base field to search worker api
1 parent d484f03 commit c02b0f5

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

src/components/Router/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import {createContext, useContext} from 'react';
44

55
export interface RouterConfig extends Router {
66
depth: number;
7+
base: string;
78
}
89

910
export const RouterContext = createContext<RouterConfig>({
1011
pathname: '/',
12+
base: './',
1113
depth: 0,
1214
});
1315

src/components/Search/provider/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export class DefaultSearchProvider implements ISearchProvider, SearchProviderExt
1515
init = () => {
1616
this.worker = initWorker({
1717
...this.config,
18-
base: this.base,
1918
mark: 'Suggest__Item__Marker',
2019
});
2120
};
@@ -38,10 +37,6 @@ export class DefaultSearchProvider implements ISearchProvider, SearchProviderExt
3837

3938
link = (query: string, page = 1) => buildSearchLink(this.base, this.config, query, page);
4039

41-
private get base() {
42-
return window.location.href.split('/').slice(0, -this.config.depth).join('/');
43-
}
44-
4540
private async request(message: object) {
4641
return request(await this.worker, message);
4742
}

src/components/Search/types.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import type {ISearchResult, SearchSuggestPageItem} from '@diplodoc/components';
22

3-
export interface AlgoliaQuerySettings {
4-
hitsPerPage?: number;
5-
facetFilters?: string[];
6-
attributesToRetrieve?: string[];
7-
attributesToHighlight?: string[];
8-
[key: string]: unknown;
9-
}
10-
113
export interface SearchData {
124
api: string;
135
link: string;
@@ -17,25 +9,14 @@ export interface SearchData {
179

1810
export interface SearchConfig extends SearchData {
1911
depth: number;
20-
appId?: string;
21-
indexName?: string;
22-
searchKey?: string;
23-
querySettings?: AlgoliaQuerySettings;
24-
search?: SearchData;
12+
base: string;
2513
}
2614

2715
export interface WorkerConfig {
2816
api?: string;
2917
base: string;
3018
mark: string;
3119
provider?: 'local' | 'algolia';
32-
33-
appId?: string;
34-
indexName?: string;
35-
searchKey?: string;
36-
querySettings?: {
37-
[key: string]: unknown;
38-
};
3920
}
4021

4122
export interface SearchResultItem {

src/components/Search/useProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {createProvider} from './provider';
99

1010
export function useProvider() {
1111
const lang = useLang();
12-
const {depth = 0} = useContext(RouterContext);
12+
const {base = './'} = useContext(RouterContext);
1313
const search = useContext(SearchContext);
1414
const [provider, setProvider] = useState<ISearchProvider | null>(null);
1515

@@ -20,10 +20,10 @@ export function useProvider() {
2020

2121
return {
2222
...search,
23-
depth,
23+
base,
2424
lang,
2525
};
26-
}, [lang, depth, search]);
26+
}, [lang, base, search]);
2727

2828
useEffect(() => {
2929
if (config) {

0 commit comments

Comments
 (0)