@@ -14,11 +14,12 @@ const search = instantsearch({
14
14
routing : {
15
15
stateMapping : {
16
16
stateToRoute : function ( uiState ) {
17
+ const state = uiState [ algoliaConfig . index_name ] ;
17
18
return {
18
- query : uiState . query && uiState . query . replace ( new RegExp ( '([^\\s])--' , 'g' ) , '$1-' ) ,
19
- type : uiState . menu && uiState . menu . type ,
20
- tags : uiState . refinementList && uiState . refinementList . tags && uiState . refinementList . tags . join ( '~' ) ,
21
- page : uiState . page ,
19
+ query : state . query && state . query . replace ( new RegExp ( '([^\\s])--' , 'g' ) , '$1-' ) ,
20
+ type : state . menu && state . menu . type ,
21
+ tags : state . refinementList && state . refinementList . tags && state . refinementList . tags . join ( '~' ) ,
22
+ page : state . page ,
22
23
} ;
23
24
} ,
24
25
routeToState : function ( routeState ) {
@@ -35,24 +36,27 @@ const search = instantsearch({
35
36
}
36
37
37
38
return {
38
- query : routeState . query || '' ,
39
- menu : {
40
- type : routeState . type
41
- } ,
42
- refinementList : {
43
- tags : routeState . tags && routeState . tags . replace ( / [ \s - ] + / g, ' ' ) . split ( '~' ) ,
44
- } ,
45
- page : routeState . page
46
- } ;
39
+ [ algoliaConfig . index_name ] : {
40
+ query : routeState . query || '' ,
41
+ menu : {
42
+ type : routeState . type
43
+ } ,
44
+ refinementList : {
45
+ tags : routeState . tags && routeState . tags . replace ( / [ \s - ] + / g, ' ' ) . split ( '~' ) ,
46
+ } ,
47
+ page : routeState . page
48
+ }
49
+ }
47
50
} ,
48
51
} ,
49
52
} ,
50
- searchFunction : function ( helper ) {
51
- var searchResults = document . querySelector ( '#search-container' ) ;
53
+ onStateChange : function ( { uiState, setUiState} ) {
54
+ const searchResults = document . querySelector ( '#search-container' ) ;
55
+ const state = uiState [ algoliaConfig . index_name ] ;
52
56
53
- if ( helper . state . query === ''
54
- && helper . state . hierarchicalFacetsRefinements . type === undefined
55
- && ( helper . state . disjunctiveFacetsRefinements . tags === undefined || helper . state . disjunctiveFacetsRefinements . tags . length === 0 )
57
+ if ( state . query === ''
58
+ && state . hierarchicalFacetsRefinements . type === undefined
59
+ && ( state . disjunctiveFacetsRefinements . tags === undefined || state . disjunctiveFacetsRefinements . tags . length === 0 )
56
60
) {
57
61
searchResults . classList . add ( 'hidden' ) ;
58
62
return ;
@@ -65,18 +69,18 @@ const search = instantsearch({
65
69
}
66
70
67
71
// force focus to prevent algolia from updating the search field input with the modified value
68
- if ( helper . state . query . match ( / - / ) ) {
72
+ if ( state . query . match ( / - / ) ) {
69
73
document . getElementById ( 'search_query_query' ) . focus ( ) ;
70
74
}
71
75
72
- if ( helper . state . query . match ( / ^ P K S A - .{ 14 } $ / ) || helper . state . query . match ( / ^ G H S A - .{ 14 } $ / ) || helper . state . query . match ( / ^ C V E - \d { 4 } - \d + $ / ) ) {
73
- document . location . href = "/security-advisories/" + helper . state . query ;
76
+ if ( state . query . match ( / ^ P K S A - .{ 14 } $ / ) || state . query . match ( / ^ G H S A - .{ 14 } $ / ) || state . query . match ( / ^ C V E - \d { 4 } - \d + $ / ) ) {
77
+ document . location . href = "/security-advisories/" + state . query ;
74
78
}
75
79
76
- helper . state . query = helper . state . query . replace ( new RegExp ( '([^\\s])-' , 'g' ) , '$1--' ) ;
80
+ state . query = state . query . replace ( new RegExp ( '([^\\s])-' , 'g' ) , '$1--' ) ;
77
81
78
- searchThrottle = setTimeout ( function ( ) {
79
- helper . search ( ) ;
82
+ searchThrottle = setTimeout ( ( ) => {
83
+ setUiState ( { [ algoliaConfig . index_name ] : state } ) ;
80
84
} , 300 ) ;
81
85
} ,
82
86
} ) ;
0 commit comments