@@ -22,6 +22,7 @@ import {
2222 setFilter ,
2323 setOrderBy ,
2424 setOrderReverse ,
25+ setSearchId ,
2526 setSearchText
2627} from './slice' ;
2728
@@ -34,8 +35,22 @@ export function addSearchMiddleware() {
3435 const view = state . search . views [ action . payload . view ] ;
3536
3637 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 } ) ) ;
3954 }
4055 }
4156 } ) ;
@@ -162,45 +177,26 @@ export function addSearchMiddleware() {
162177 const view = state . search . views [ action . payload . filter . viewId ] ;
163178
164179 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+ } ) ;
167199 }
168200 }
169201 } ) ;
170202}
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