diff --git a/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx b/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx index d398f44eb4..4b950690c4 100644 --- a/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx +++ b/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx @@ -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; @@ -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') }); } }; @@ -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 = ( @@ -618,6 +622,8 @@ export default function FiltersPanel({ composeContextTheme={COMPOSE.SOFT} disabled={disableClearFilterButtons} onClick={() => { + setRecommendedToggle(false); + setSort('openForRegistration', 'startDate'); setFilterState({ tracks: { Dev: true, @@ -638,7 +644,6 @@ export default function FiltersPanel({ }); selectCommunity(defaultCommunityId); setSearchText(''); - setRecommendedToggle(false); // localStorage.setItem('trackStatus', JSON.stringify({})); }} size="sm" diff --git a/src/shared/containers/challenge-listing/Listing/index.jsx b/src/shared/containers/challenge-listing/Listing/index.jsx index 0bd812b013..a511987240 100644 --- a/src/shared/containers/challenge-listing/Listing/index.jsx +++ b/src/shared/containers/challenge-listing/Listing/index.jsx @@ -169,7 +169,7 @@ export class ListingContainer extends React.Component { } case BUCKETS.OPEN_FOR_REGISTRATION: { if (isRecommendedChallengeType(bucket, filter)) { - dropOpenForRegistrationChallenges(); + dropRecommendedChallenges(); getRecommendedChallenges( 0, sorts, @@ -177,7 +177,7 @@ export class ListingContainer extends React.Component { filter, ); } else { - dropRecommendedChallenges(); + dropOpenForRegistrationChallenges(); getOpenForRegistrationChallenges( 0, fA.back, @@ -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(); diff --git a/src/shared/reducers/challenge-listing/index.js b/src/shared/reducers/challenge-listing/index.js index fd3a6b96a2..3f89b1d47f 100644 --- a/src/shared/reducers/challenge-listing/index.js +++ b/src/shared/reducers/challenge-listing/index.js @@ -806,7 +806,6 @@ function create(initialState) { }), [a.dropRecommendedChallenges]: state => ({ ...state, - allChallenges: [], lastRequestedPageOfRecommendedChallenges: -1, loadingAllChallengesUUID: '', }),