diff --git a/src/containers/Challenges/index.jsx b/src/containers/Challenges/index.jsx index deb1cfd..86103f4 100644 --- a/src/containers/Challenges/index.jsx +++ b/src/containers/Challenges/index.jsx @@ -14,6 +14,7 @@ import "./styles.scss"; const Challenges = ({ challenges, + challengesMeta, search, page, perPage, @@ -38,6 +39,16 @@ const Challenges = ({ checkIsLoggedIn(); }, []); + // reset pagination + if (page > 1 && challengesMeta.total && challengesMeta.total > 0 && challenges.length === 0) { + updateFilter({ + page: 1 + }) + updateQuery({ + page: 1 + }) + } + const BUCKET_OPEN_FOR_REGISTRATION = constants.FILTER_BUCKETS[1]; const isRecommended = recommended && bucket === BUCKET_OPEN_FOR_REGISTRATION; const sortByValue = isRecommended @@ -124,6 +135,7 @@ const mapStateToProps = (state) => ({ endDateStart: state.filter.challenge.endDateStart, startDateEnd: state.filter.challenge.startDateEnd, challenges: state.challenges.challenges, + challengesMeta: state.challenges.challengesMeta, bucket: state.filter.challenge.bucket, recommended: state.filter.challenge.recommended, recommendedChallenges: state.challenges.recommendedChallenges, diff --git a/src/reducers/challenges.js b/src/reducers/challenges.js index dc8d54c..37fc947 100644 --- a/src/reducers/challenges.js +++ b/src/reducers/challenges.js @@ -4,6 +4,7 @@ const defaultState = { loadingChallenges: false, loadingChallengesError: null, challenges: [], + challengesMeta: {}, total: 0, loadingRecommendedChallenges: false, loadingRecommendedChallengesError: null, @@ -31,6 +32,7 @@ function onGetChallengesDone(state, { payload }) { loadingChallenges: false, loadingChallengesError: null, challenges: payload.challenges, + challengesMeta: payload.challenges?.meta, total: payload.total, openForRegistrationCount: payload.openForRegistrationCount, initialized: true,