@@ -22,6 +22,7 @@ import {
22
22
setFilter ,
23
23
setOrderBy ,
24
24
setOrderReverse ,
25
+ setSearchId ,
25
26
setSearchText
26
27
} from './slice' ;
27
28
@@ -34,8 +35,22 @@ export function addSearchMiddleware() {
34
35
const view = state . search . views [ action . payload . view ] ;
35
36
36
37
if ( view ) {
37
- // Debounce building search text
38
- debounceBuildQuery ( view ) ;
38
+ // Immediately update search id
39
+ const newSearchId = view . data . searchId + 1 ;
40
+ store . dispatch ( setSearchId ( { view : view . id , searchId : newSearchId } ) ) ;
41
+
42
+ // Get processed query
43
+ const filter = await window . Shared . back . request ( BackIn . PARSE_QUERY_DATA , {
44
+ viewId : view . id ,
45
+ searchId : newSearchId ,
46
+ text : view . text ,
47
+ advancedFilter : view . advancedFilter ,
48
+ orderBy : view . orderBy ,
49
+ orderDirection : view . orderReverse ,
50
+ playlist : view . selectedPlaylist
51
+ } ) ;
52
+
53
+ store . dispatch ( setFilter ( { filter } ) ) ;
39
54
}
40
55
}
41
56
} ) ;
@@ -162,45 +177,26 @@ export function addSearchMiddleware() {
162
177
const view = state . search . views [ action . payload . filter . viewId ] ;
163
178
164
179
if ( view ) {
165
- // Debounce building search text
166
- debounceSearch ( view . id , view . searchFilter ) ;
180
+ log . info ( 'Launcher' , 'Performing search...' ) ;
181
+ // Request first page
182
+ window . Shared . back . request ( BackIn . BROWSE_VIEW_FIRST_PAGE , view . searchFilter )
183
+ . then ( ( data ) => {
184
+ store . dispatch ( addData ( {
185
+ view : view . id ,
186
+ data : {
187
+ searchId : view . searchFilter . searchId ,
188
+ page : 0 ,
189
+ games : data . games ,
190
+ }
191
+ } ) ) ;
192
+
193
+ // Request keyset
194
+ store . dispatch ( requestKeyset ( {
195
+ view : view . id ,
196
+ searchId : view . searchFilter . searchId ,
197
+ } ) ) ;
198
+ } ) ;
167
199
}
168
200
}
169
201
} ) ;
170
202
}
171
-
172
- const debounceBuildQuery = debounce ( async ( view : ResultsView ) => {
173
- const filter = await window . Shared . back . request ( BackIn . PARSE_QUERY_DATA , {
174
- viewId : view . id ,
175
- searchId : view . data . searchId + 1 ,
176
- text : view . text ,
177
- advancedFilter : view . advancedFilter ,
178
- orderBy : view . orderBy ,
179
- orderDirection : view . orderReverse ,
180
- playlist : view . selectedPlaylist
181
- } ) ;
182
-
183
- store . dispatch ( setFilter ( { filter } ) ) ;
184
- } , 125 ) ;
185
-
186
- const debounceSearch = debounce ( ( viewName : string , searchFilter : SearchQuery ) => {
187
- log . info ( 'Launcher' , 'Performing search...' ) ;
188
- // Request first page
189
- window . Shared . back . request ( BackIn . BROWSE_VIEW_FIRST_PAGE , searchFilter )
190
- . then ( ( data ) => {
191
- store . dispatch ( addData ( {
192
- view : viewName ,
193
- data : {
194
- searchId : searchFilter . searchId ,
195
- page : 0 ,
196
- games : data . games ,
197
- }
198
- } ) ) ;
199
-
200
- // Request keyset
201
- store . dispatch ( requestKeyset ( {
202
- view : viewName ,
203
- searchId : searchFilter . searchId ,
204
- } ) ) ;
205
- } ) ;
206
- } , 50 ) ;
0 commit comments