@@ -12,23 +12,13 @@ import {
12
12
PUBLISHED ,
13
13
SEARCH_STRING ,
14
14
} from "@/app/(sok)/_components/searchParamNames" ;
15
- import { FetchAction , useFetchReducer } from "@/app/_common/hooks/useFetchReducer" ;
16
- import * as actions from "@/app/_common/actions" ;
17
15
import { findLabelForFilter , getSearchBoxOptions } from "@/app/(sok)/_components/searchBox/buildSearchBoxOptions" ;
18
16
import logAmplitudeEvent , { logFilterChanged } from "@/app/_common/monitoring/amplitude" ;
19
17
20
- let suggestionsCache = [ ] ;
21
- const CACHE_MAX_SIZE = 50 ;
22
- const MINIMUM_LENGTH = 1 ;
23
-
24
18
function SearchCombobox ( { aggregations, locations } ) {
25
19
const searchQuery = useSearchQuery ( ) ;
26
- const [ suggestionsResponse , suggestionsDispatch ] = useFetchReducer ( [ ] ) ;
27
20
28
- const options = useMemo (
29
- ( ) => getSearchBoxOptions ( aggregations , locations , [ ...suggestionsResponse . data ] ) ,
30
- [ aggregations , locations , suggestionsResponse . data ] ,
31
- ) ;
21
+ const options = useMemo ( ( ) => getSearchBoxOptions ( aggregations , locations ) , [ aggregations , locations ] ) ;
32
22
33
23
const selectedOptions = useMemo (
34
24
( ) => buildSelectedOptions ( searchQuery . urlSearchParams ) ,
@@ -42,30 +32,6 @@ function SearchCombobox({ aggregations, locations }) {
42
32
: { label : o . label , value : o . value } ;
43
33
} ) ;
44
34
45
- async function fetchSuggestions ( value ) {
46
- const cached = suggestionsCache . find ( ( c ) => c . value === value ) ;
47
- if ( cached ) {
48
- suggestionsDispatch ( { type : FetchAction . RESOLVE , data : cached . data } ) ;
49
- return ;
50
- }
51
- let data ;
52
- try {
53
- data = await actions . getSuggestions ( value , MINIMUM_LENGTH ) ;
54
- } catch ( err ) {
55
- // ignore fetch failed errors
56
- }
57
- if ( data ) {
58
- suggestionsCache = [ { value, data } , ...suggestionsCache ] . slice ( 0 , CACHE_MAX_SIZE ) ;
59
- suggestionsDispatch ( { type : FetchAction . RESOLVE , data } ) ;
60
- }
61
- }
62
-
63
- function handleValueChange ( value ) {
64
- if ( value && value . length >= MINIMUM_LENGTH ) {
65
- fetchSuggestions ( value ) ;
66
- }
67
- }
68
-
69
35
const handleFreeTextSearchOption = ( value , isSelected ) => {
70
36
if ( isSelected ) {
71
37
searchQuery . append ( SEARCH_STRING , value ) ;
@@ -173,7 +139,6 @@ function SearchCombobox({ aggregations, locations }) {
173
139
onToggleSelected = { onToggleSelected }
174
140
selectedOptions = { selectedOptions }
175
141
options = { optionList }
176
- onChange = { handleValueChange }
177
142
/>
178
143
) ;
179
144
}
0 commit comments