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

Commit d624762

Browse files
committed
fix last commit breaking other filters
1 parent 29d6ccb commit d624762

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -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
) ||
@@ -227,22 +229,40 @@ const ChallengeFilter = ({
227229
);
228230
const filterChange = { events, groups };
229231

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+
}
241+
230242
if (isTCOEvent) {
231243
const scEvent = utils.challenge.getCommunityEvent(
232244
subCommunity
233245
);
234246
filterChange.events = checked
235-
? _.union(events, [scEvent])
236-
: _.without(events, scEvent);
247+
? _.union(filterChange.events, [scEvent])
248+
: _.without(filterChange.events, scEvent);
237249
} else {
238250
const scGroup = utils.challenge.getCommunityGroup(
239251
subCommunity
240252
);
241253
filterChange.groups = checked
242-
? _.union(groups, [scGroup])
243-
: _.without(groups, scGroup);
254+
? _.union(filterChange.groups, [scGroup])
255+
: _.without(filterChange.groups, scGroup);
244256
}
245257

258+
// turn off 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+
}
246266
updateFilter(filterChange);
247267
}}
248268
/>

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

+2-34
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ 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-
}
6761
updateFilter(filterChange);
6862
updateQuery(filterChange);
6963
}}
@@ -96,32 +90,6 @@ Filter.propTypes = {
9690
updateQuery: PT.func,
9791
};
9892

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-
12593
const mapStateToProps = (state) => ({
12694
state: state,
12795
bucket: state.filter.challenge.bucket,
@@ -131,8 +99,8 @@ const mapStateToProps = (state) => ({
13199
totalPrizesFrom: state.filter.challenge.totalPrizesFrom,
132100
totalPrizesTo: state.filter.challenge.totalPrizesTo,
133101
recommended: state.filter.challenge.recommended,
134-
events: getSelectedCommunityEvents(state),
135-
groups: getSelectedCommunityGroups(state),
102+
events: state.filter.challenge.events,
103+
groups: state.filter.challenge.groups,
136104
challengeBuckets: state.lookup.buckets,
137105
challengeTypes: state.lookup.types,
138106
challengeTracks: state.lookup.tracks,

0 commit comments

Comments
 (0)