@@ -3,7 +3,7 @@ import { fetchJson } from './fetchJson';
3
3
import { CmsContent } from '../../common/cms-documents/content' ;
4
4
import { CmsCategoryListItem } from '../../common/cms-documents/category' ;
5
5
import { useCallback } from 'react' ;
6
- import { ContentSearchResult } from '../../common/contentSearch' ;
6
+ import { ContentSearchParams , ContentSearchResult } from '../../common/contentSearch' ;
7
7
8
8
const fetchContent = ( basePath : string ) => async ( contentKey : string ) =>
9
9
fetchJson < CmsContent > ( `${ basePath } /api/content/${ contentKey } ` ) ;
@@ -20,37 +20,21 @@ const fetchCategories =
20
20
)
21
21
: [ ] ;
22
22
23
- export type FetchCategoryContentsParams = {
24
- categoryKey : string ;
25
- from : number ;
26
- size : number ;
27
- query ?: string ;
28
- } ;
29
-
30
- const fetchCategoryContents =
31
- ( basePath : string ) =>
32
- async ( { categoryKey, from, size, query = '' } : FetchCategoryContentsParams ) =>
33
- fetchJson < ContentSearchResult > (
34
- `${ basePath } /api/search?sort=name&from=${ from } &size=${ size } &query=${ query ?. length > 2 ? query : '' } &categoryKey=${ categoryKey } `
35
- ) ;
36
-
37
- const fetchSearchSimple = ( basePath : string ) => async ( query : string ) =>
38
- fetchJson < ContentSearchResult > ( `${ basePath } /api/search?query=${ query } ` ) ;
23
+ const fetchSearch = ( basePath : string ) => async ( params : ContentSearchParams ) =>
24
+ fetchJson < ContentSearchResult > ( `${ basePath } /api/search` , params ) ;
39
25
40
26
export const useApiFetch = ( ) => {
41
27
const { appContext } = useAppState ( ) ;
42
28
const { basePath } = appContext ;
43
29
44
30
return {
45
- // eslint-disable-next-line react-hooks/exhaustive-deps
46
- fetchCategoryContents : useCallback ( fetchCategoryContents ( basePath ) , [ basePath ] ) ,
47
31
// eslint-disable-next-line react-hooks/exhaustive-deps
48
32
fetchContent : useCallback ( fetchContent ( basePath ) , [ basePath ] ) ,
49
33
// eslint-disable-next-line react-hooks/exhaustive-deps
50
34
fetchContentVersion : useCallback ( fetchContentVersion ( basePath ) , [ basePath ] ) ,
51
35
// eslint-disable-next-line react-hooks/exhaustive-deps
52
36
fetchCategories : useCallback ( fetchCategories ( basePath ) , [ basePath ] ) ,
53
37
// eslint-disable-next-line react-hooks/exhaustive-deps
54
- fetchSearchSimple : useCallback ( fetchSearchSimple ( basePath ) , [ basePath ] ) ,
38
+ fetchSearch : useCallback ( fetchSearch ( basePath ) , [ basePath ] ) ,
55
39
} ;
56
40
} ;
0 commit comments