@@ -71,8 +71,9 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc';
71
71
*/
72
72
73
73
function filterByGroupIds ( challenge , state ) {
74
- if ( ! state . groupIds ) return true ;
75
- return state . groupIds . some ( id => challenge . groups [ id ] ) ;
74
+ if ( _ . isEmpty ( state . groupIds ) ) return true ;
75
+ if ( _ . isEmpty ( challenge . groups ) ) return false ;
76
+ return state . groupIds . some ( id => challenge . groups . find ( gId => gId === id ) ) ;
76
77
}
77
78
78
79
function filterByRegistrationOpen ( challenge , state ) {
@@ -144,12 +145,18 @@ function filterByStatus(challenge, state) {
144
145
}
145
146
146
147
function filterByTags ( challenge , state ) {
147
- if ( ! state . tags ) return true ;
148
+ if ( _ . isEmpty ( state . tags ) ) return true ;
148
149
const { platforms, tags } = challenge ;
149
150
const str = `${ platforms } ${ tags } ` . toLowerCase ( ) ;
150
151
return state . tags . some ( tag => str . includes ( tag . toLowerCase ( ) ) ) ;
151
152
}
152
153
154
+ function filterByEvents ( challenge , state ) {
155
+ if ( _ . isEmpty ( state . events ) ) return true ;
156
+ if ( _ . isEmpty ( challenge . events ) ) return false ;
157
+ return state . events . some ( key => challenge . events . find ( e => e . key === key ) ) ;
158
+ }
159
+
153
160
function filterByText ( challenge , state ) {
154
161
if ( ! state . text ) return true ;
155
162
const str = `${ challenge . name } ${ challenge . tags } ${ challenge . platforms } ${ challenge . tags } `
@@ -173,8 +180,11 @@ function filterByUpcoming(challenge, state) {
173
180
}
174
181
175
182
function filterByUsers ( challenge , state ) {
176
- if ( ! state . userChallenges ) return true ;
177
- return state . userChallenges . find ( ch => challenge . id === ch ) ;
183
+ const userId = _ . get ( state , 'userId' , null ) ;
184
+ if ( userId ) {
185
+ return _ . get ( challenge , [ 'users' , userId ] , false ) ;
186
+ }
187
+ return true ;
178
188
}
179
189
180
190
/**
@@ -214,6 +224,7 @@ export function getFilterFunction(state) {
214
224
&& filterByGroupIds ( challenge , state )
215
225
&& filterByText ( challenge , state )
216
226
&& filterByTags ( challenge , state )
227
+ && filterByEvents ( challenge , state )
217
228
&& filterByTypes ( challenge , state )
218
229
&& filterByUsers ( challenge , state )
219
230
&& filterByEndDate ( challenge , state )
@@ -343,7 +354,7 @@ export function combine(...filters) {
343
354
const res = { } ;
344
355
filters . forEach ( ( filter ) => {
345
356
combineEndDate ( res , filter ) ;
346
- combineArrayRules ( res , filter , 'groups ' ) ;
357
+ combineArrayRules ( res , filter , 'groupIds ' ) ;
347
358
/* TODO: The registrationOpen rule is just ignored for now. */
348
359
combineStartDate ( res , filter ) ;
349
360
combineArrayRules ( res , filter , 'or' , true ) ;
@@ -380,7 +391,7 @@ export function combine(...filters) {
380
391
*/
381
392
export function mapToBackend ( filter ) {
382
393
const res = { } ;
383
- if ( filter . groups ) res . groups = filter . groups ;
394
+ if ( filter . groupIds ) res . groups = filter . groupIds ;
384
395
return res ;
385
396
}
386
397
0 commit comments