@@ -214,6 +214,8 @@ const ChallengeFilter = ({
214214 < span key = { subCommunity . communityName } >
215215 < Checkbox
216216 checked = {
217+ // select all if query filters neither events nor groups
218+ events . length + groups . length === 0 ||
217219 events . includes (
218220 utils . challenge . getCommunityEvent ( subCommunity )
219221 ) ||
@@ -225,32 +227,42 @@ const ChallengeFilter = ({
225227 const isTCOEvent = utils . challenge . isTCOEventCommunity (
226228 subCommunity
227229 ) ;
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+ }
229241
230242 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 ) ;
241249 } 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 ) ;
252256 }
253257
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+ }
254266 updateFilter ( filterChange ) ;
255267 } }
256268 />
0 commit comments