Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,16 @@ export default function FiltersPanel({
const [recommendedToggle, setRecommendedToggle] = useState(false);

useEffect(() => {
if (recommendedToggle) {
const types = _.union(filterState.types, ['REC']);
setFilterState({ ..._.clone(filterState), types });
if (!isFilterEmpty(filterState, past ? 'past' : '', activeBucket)
&& recommendedToggle
&& filterState.types.length !== _.uniq(filterState.types).length
) {
setFilterState({
...filterState,
types: _.uniq(filterState.types),
});
}
}, []);
}, [filterState]);

const onSwitchRecommendedChallenge = (on) => {
const { types } = filterState;
Expand All @@ -270,8 +275,8 @@ export default function FiltersPanel({
setSort('openForRegistration', 'bestMatch');
setFilterState({ ..._.clone(filterState), types });
} else {
setFilterState({ ..._.clone(filterState), types: ['TSK', 'CH', 'F2F'] });
setSort('openForRegistration', 'startDate');
setFilterState({ ..._.clone(filterState), types: types.filter(item => item !== 'REC') });
}
};

Expand All @@ -284,13 +289,12 @@ export default function FiltersPanel({
}

if (recommendedToggle) {
types = [...types, 'REC'];
types = _.union(types, ['REC']);
} else {
types = types.filter(type => type !== 'REC');
setSort('openForRegistration', 'startDate');
}

setFilterState({ ..._.clone(filterState), types });
setSort('openForRegistration', 'startDate');
};

const recommendedCheckboxTip = (
Expand Down Expand Up @@ -618,6 +622,8 @@ export default function FiltersPanel({
composeContextTheme={COMPOSE.SOFT}
disabled={disableClearFilterButtons}
onClick={() => {
setRecommendedToggle(false);
setSort('openForRegistration', 'startDate');
setFilterState({
tracks: {
Dev: true,
Expand All @@ -638,7 +644,6 @@ export default function FiltersPanel({
});
selectCommunity(defaultCommunityId);
setSearchText('');
setRecommendedToggle(false);
// localStorage.setItem('trackStatus', JSON.stringify({}));
}}
size="sm"
Expand Down
6 changes: 3 additions & 3 deletions src/shared/containers/challenge-listing/Listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ export class ListingContainer extends React.Component {
}
case BUCKETS.OPEN_FOR_REGISTRATION: {
if (isRecommendedChallengeType(bucket, filter)) {
dropOpenForRegistrationChallenges();
dropRecommendedChallenges();
getRecommendedChallenges(
0,
sorts,
auth.tokenV3,
filter,
);
} else {
dropRecommendedChallenges();
dropOpenForRegistrationChallenges();
getOpenForRegistrationChallenges(
0,
fA.back,
Expand Down Expand Up @@ -234,7 +234,7 @@ export class ListingContainer extends React.Component {
return;
}
if (filterChanged(filter, prevProps.filter)) {
if (isRecommendedChallengeType(bucket, prevProps.filter)) {
if (filter.types.includes('REC')) {
this.reloadRecommendedChallenges();
} else {
this.reloadChallenges();
Expand Down
1 change: 0 additions & 1 deletion src/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ function create(initialState) {
}),
[a.dropRecommendedChallenges]: state => ({
...state,
allChallenges: [],
lastRequestedPageOfRecommendedChallenges: -1,
loadingAllChallengesUUID: '',
}),
Expand Down