@@ -214,6 +214,8 @@ const ChallengeFilter = ({
214
214
< span key = { subCommunity . communityName } >
215
215
< Checkbox
216
216
checked = {
217
+ // select all if query filters neither events nor groups
218
+ events . length + groups . length === 0 ||
217
219
events . includes (
218
220
utils . challenge . getCommunityEvent ( subCommunity )
219
221
) ||
@@ -225,32 +227,42 @@ const ChallengeFilter = ({
225
227
const isTCOEvent = utils . challenge . isTCOEventCommunity (
226
228
subCommunity
227
229
) ;
228
- let filterChange ;
230
+ const filterChange = { events, groups } ;
231
+
232
+ if ( events . length + groups . length === 0 ) {
233
+ // select all if query filters neither events nor groups
234
+ filterChange . events = challengeSubCommunities
235
+ . filter ( utils . challenge . isTCOEventCommunity )
236
+ . map ( utils . challenge . getCommunityEvent ) ;
237
+ filterChange . groups = challengeSubCommunities
238
+ . filter ( utils . challenge . isGroupCommunity )
239
+ . map ( utils . challenge . getCommunityGroup ) ;
240
+ }
229
241
230
242
if ( isTCOEvent ) {
231
- const newEvents = checked
232
- ? events . concat (
233
- utils . challenge . getCommunityEvent ( subCommunity )
234
- )
235
- : events . filter (
236
- ( event ) =>
237
- event !==
238
- utils . challenge . getCommunityEvent ( subCommunity )
239
- ) ;
240
- filterChange = { events : newEvents } ;
243
+ const scEvent = utils . challenge . getCommunityEvent (
244
+ subCommunity
245
+ ) ;
246
+ filterChange . events = checked
247
+ ? _ . union ( filterChange . events , [ scEvent ] )
248
+ : _ . without ( filterChange . events , scEvent ) ;
241
249
} else {
242
- const newGroups = checked
243
- ? groups . concat (
244
- utils . challenge . getCommunityGroup ( subCommunity )
245
- )
246
- : groups . filter (
247
- ( group ) =>
248
- group !==
249
- utils . challenge . getCommunityGroup ( subCommunity )
250
- ) ;
251
- filterChange = { groups : newGroups } ;
250
+ const scGroup = utils . challenge . getCommunityGroup (
251
+ subCommunity
252
+ ) ;
253
+ filterChange . groups = checked
254
+ ? _ . union ( filterChange . groups , [ scGroup ] )
255
+ : _ . without ( filterChange . groups , scGroup ) ;
252
256
}
253
257
258
+ // clear community filters if all sub-communities are selected
259
+ if (
260
+ filterChange . groups . length + filterChange . events . length >=
261
+ challengeSubCommunities . length
262
+ ) {
263
+ filterChange . events = [ ] ;
264
+ filterChange . groups = [ ] ;
265
+ }
254
266
updateFilter ( filterChange ) ;
255
267
} }
256
268
/>
0 commit comments