@@ -164,9 +164,9 @@ const select = (state: StoreState, filters: SelectFilterParams = {}) => {
164164 const guide = state . previewGuides [ guideKey ] || state . guides [ guideKey ] ;
165165 if ( ! guide ) continue ;
166166
167- const affirmed = predicate ( guide , {
167+ const affirmed = predicate ( guide , filters , {
168168 location,
169- filters ,
169+ ineligibleGuides : state . ineligibleGuides ,
170170 debug : state . debug ,
171171 } ) ;
172172
@@ -179,15 +179,15 @@ const select = (state: StoreState, filters: SelectFilterParams = {}) => {
179179 return result ;
180180} ;
181181
182- type PredicateOpts = {
183- location ?: string | undefined ;
184- filters ?: SelectFilterParams | undefined ;
185- debug : DebugState ;
186- } ;
182+ type PredicateOpts = Pick <
183+ StoreState ,
184+ "location" | "ineligibleGuides" | "debug"
185+ > ;
187186
188187const predicate = (
189188 guide : KnockGuide ,
190- { location, filters = { } , debug = { } } : PredicateOpts ,
189+ filters : SelectFilterParams ,
190+ { location, ineligibleGuides = { } , debug = { } } : PredicateOpts ,
191191) => {
192192 if ( filters . type && filters . type !== guide . type ) {
193193 return false ;
@@ -204,6 +204,11 @@ const predicate = (
204204 return debug . forcedGuideKey === guide . key ;
205205 }
206206
207+ const ineligible = ineligibleGuides [ guide . key ] ;
208+ if ( ineligible ) {
209+ return false ;
210+ }
211+
207212 if ( ! guide . active ) {
208213 return false ;
209214 }
@@ -277,6 +282,7 @@ export class KnockGuideClient {
277282 guideGroups : [ ] ,
278283 guideGroupDisplayLogs : { } ,
279284 guides : { } ,
285+ ineligibleGuides : { } ,
280286 previewGuides : { } ,
281287 queries : { } ,
282288 location,
@@ -358,14 +364,20 @@ export class KnockGuideClient {
358364 > ( this . channelId , queryParams ) ;
359365 queryStatus = { status : "ok" } ;
360366
361- const { entries, guide_groups : groups , guide_group_display_logs } = data ;
367+ const {
368+ entries,
369+ guide_groups : groups ,
370+ guide_group_display_logs,
371+ ineligible_guides,
372+ } = data ;
362373
363374 this . knock . log ( "[Guide] Loading fetched guides" ) ;
364375 this . store . setState ( ( state ) => ( {
365376 ...state ,
366377 guideGroups : groups ?. length > 0 ? groups : [ mockDefaultGroup ( entries ) ] ,
367378 guideGroupDisplayLogs : guide_group_display_logs || { } ,
368379 guides : byKey ( entries . map ( ( g ) => this . localCopy ( g ) ) ) ,
380+ ineligibleGuides : byKey ( ineligible_guides || [ ] ) ,
369381 queries : { ...state . queries , [ queryKey ] : queryStatus } ,
370382 } ) ) ;
371383 } catch ( e ) {
@@ -466,6 +478,8 @@ export class KnockGuideClient {
466478 private handleSocketEvent ( payload : GuideSocketEvent ) {
467479 const { event, data } = payload ;
468480
481+ // TODO(KNO-11489): Include an ineligible guide in the socket payload too
482+ // and process it when handling socket events in real time.
469483 switch ( event ) {
470484 case "guide.added" :
471485 return this . addOrReplaceGuide ( payload ) ;
0 commit comments