Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

start with all Sub Communities selected by default #89

Open
wants to merge 2 commits into
base: bugbash
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions src/containers/Filter/ChallengeFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ const ChallengeFilter = ({
<span key={subCommunity.communityName}>
<Checkbox
checked={
// select all if query filters neither events nor groups
events.length + groups.length === 0 ||
events.includes(
utils.challenge.getCommunityEvent(subCommunity)
) ||
Expand All @@ -225,32 +227,42 @@ const ChallengeFilter = ({
const isTCOEvent = utils.challenge.isTCOEventCommunity(
subCommunity
);
let filterChange;
const filterChange = { events, groups };

if (events.length + groups.length === 0) {
// select all if query filters neither events nor groups
filterChange.events = challengeSubCommunities
.filter(utils.challenge.isTCOEventCommunity)
.map(utils.challenge.getCommunityEvent);
filterChange.groups = challengeSubCommunities
.filter(utils.challenge.isGroupCommunity)
.map(utils.challenge.getCommunityGroup);
}

if (isTCOEvent) {
const newEvents = checked
? events.concat(
utils.challenge.getCommunityEvent(subCommunity)
)
: events.filter(
(event) =>
event !==
utils.challenge.getCommunityEvent(subCommunity)
);
filterChange = { events: newEvents };
const scEvent = utils.challenge.getCommunityEvent(
subCommunity
);
filterChange.events = checked
? _.union(filterChange.events, [scEvent])
: _.without(filterChange.events, scEvent);
} else {
const newGroups = checked
? groups.concat(
utils.challenge.getCommunityGroup(subCommunity)
)
: groups.filter(
(group) =>
group !==
utils.challenge.getCommunityGroup(subCommunity)
);
filterChange = { groups: newGroups };
const scGroup = utils.challenge.getCommunityGroup(
subCommunity
);
filterChange.groups = checked
? _.union(filterChange.groups, [scGroup])
: _.without(filterChange.groups, scGroup);
}

// clear community filters if all sub-communities are selected
if (
filterChange.groups.length + filterChange.events.length >=
challengeSubCommunities.length
) {
filterChange.events = [];
filterChange.groups = [];
}
updateFilter(filterChange);
}}
/>
Expand Down