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

Commit 29d6ccb

Browse files
committed
start with all Sub Communities selected by default
1 parent d7de22c commit 29d6ccb

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

Diff for: src/containers/Filter/ChallengeFilter/index.jsx

+13-21
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,22 @@ const ChallengeFilter = ({
225225
const isTCOEvent = utils.challenge.isTCOEventCommunity(
226226
subCommunity
227227
);
228-
let filterChange;
228+
const filterChange = { events, groups };
229229

230230
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 };
231+
const scEvent = utils.challenge.getCommunityEvent(
232+
subCommunity
233+
);
234+
filterChange.events = checked
235+
? _.union(events, [scEvent])
236+
: _.without(events, scEvent);
241237
} 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 };
238+
const scGroup = utils.challenge.getCommunityGroup(
239+
subCommunity
240+
);
241+
filterChange.groups = checked
242+
? _.union(groups, [scGroup])
243+
: _.without(groups, scGroup);
252244
}
253245

254246
updateFilter(filterChange);

Diff for: src/containers/Filter/index.jsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ const Filter = ({
5858
updateQuery(filterChange);
5959
}}
6060
updateFilter={(filterChange) => {
61+
// turn off community filters if all sub-communities are selected
62+
const n = filterChange.groups.length + filterChange.events.length;
63+
if (n >= challengeSubCommunities.length) {
64+
filterChange.events = [];
65+
filterChange.groups = [];
66+
}
6167
updateFilter(filterChange);
6268
updateQuery(filterChange);
6369
}}
@@ -90,6 +96,32 @@ Filter.propTypes = {
9096
updateQuery: PT.func,
9197
};
9298

99+
function getSelectedCommunityEvents(state) {
100+
if (
101+
state.filter.challenge.events.length > 0 ||
102+
state.filter.challenge.groups.length > 0
103+
) {
104+
return state.filter.challenge.events;
105+
} else {
106+
return state.lookup.subCommunities
107+
.filter(utils.challenge.isTCOEventCommunity)
108+
.map(utils.challenge.getCommunityEvent);
109+
}
110+
}
111+
112+
function getSelectedCommunityGroups(state) {
113+
if (
114+
state.filter.challenge.events.length > 0 ||
115+
state.filter.challenge.groups.length > 0
116+
) {
117+
return state.filter.challenge.groups;
118+
} else {
119+
return state.lookup.subCommunities
120+
.filter(utils.challenge.isGroupCommunity)
121+
.map(utils.challenge.getCommunityGroup);
122+
}
123+
}
124+
93125
const mapStateToProps = (state) => ({
94126
state: state,
95127
bucket: state.filter.challenge.bucket,
@@ -99,8 +131,8 @@ const mapStateToProps = (state) => ({
99131
totalPrizesFrom: state.filter.challenge.totalPrizesFrom,
100132
totalPrizesTo: state.filter.challenge.totalPrizesTo,
101133
recommended: state.filter.challenge.recommended,
102-
events: state.filter.challenge.events,
103-
groups: state.filter.challenge.groups,
134+
events: getSelectedCommunityEvents(state),
135+
groups: getSelectedCommunityGroups(state),
104136
challengeBuckets: state.lookup.buckets,
105137
challengeTypes: state.lookup.types,
106138
challengeTracks: state.lookup.tracks,

0 commit comments

Comments
 (0)