From 838f7b6a40a8af3b2b48e4a93fdddff77d8e32f3 Mon Sep 17 00:00:00 2001 From: gets0ul Date: Thu, 8 Oct 2020 13:09:10 +0700 Subject: [PATCH 1/2] feat: past challenges implementation https://www.topcoder.com/challenges/e661f904-9cf4-4812-ac71-1dc615d1e374 --- .../__snapshots__/index.jsx.snap | 2 + src/shared/actions/challenge-listing/index.js | 33 ++++++++++++ .../Filters/ChallengeFilters.jsx | 3 ++ .../Filters/FiltersPanel/index.jsx | 28 ++++++++++- .../Filters/FiltersPanel/style.scss | 25 ++++++++++ .../challenge-listing/Listing/index.jsx | 24 +++++++-- .../Sidebar/BucketSelector/Bucket/index.jsx | 4 +- .../components/challenge-listing/index.jsx | 8 +++ .../challenge-listing/FilterPanel.jsx | 1 + .../challenge-listing/Listing/index.jsx | 50 +++++++++++++++++++ .../reducers/challenge-listing/index.js | 46 +++++++++++++++++ src/shared/utils/challenge-listing/buckets.js | 8 ++- 12 files changed, 225 insertions(+), 7 deletions(-) diff --git a/__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap b/__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap index e8c91ea348..030c4225f1 100644 --- a/__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap +++ b/__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap @@ -28,6 +28,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = ` expanding={false} filterState={Object {}} loadMoreActive={null} + loadMoreAll={null} loadMoreMy={null} loadMoreOnGoing={null} loadMoreOpenForRegistration={null} @@ -93,6 +94,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = ` expanding={false} filterState={Object {}} loadMoreActive={null} + loadMoreAll={null} loadMoreMy={null} loadMoreOnGoing={null} loadMoreOpenForRegistration={null} diff --git a/src/shared/actions/challenge-listing/index.js b/src/shared/actions/challenge-listing/index.js index bd4d353266..62d5db8c49 100644 --- a/src/shared/actions/challenge-listing/index.js +++ b/src/shared/actions/challenge-listing/index.js @@ -87,6 +87,10 @@ function getMyChallengesInit(uuid, page, frontFilter) { return { uuid, page, frontFilter }; } +function getAllChallengesInit(uuid, page, frontFilter) { + return { uuid, page, frontFilter }; +} + /** * Get all challenges and match with user challenges * @param {String} uuid progress id @@ -270,6 +274,31 @@ function getMyChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = { })); } +function getAllChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter = {}) { + const { sorts, status } = frontFilter; + const filter = { + backendFilter, + frontFilter: { + ...frontFilter, + perPage: PAGE_SIZE, + page: page + 1, + sortBy: sorts[BUCKETS.ALL], + sortOrder: SORT[sorts[BUCKETS.ALL]].order, + }, + }; + delete filter.frontFilter.sorts; + if (status === 'All') { + delete filter.frontFilter.status; + } + const service = getService(tokenV3); + return service.getChallenges(filter).then(ch => ({ + uuid, + allChallenges: ch.challenges, + meta: ch.meta, + frontFilter, + })); +} + function getTotalChallengesCountInit(uuid) { return { uuid }; } @@ -463,6 +492,7 @@ export default createActions({ DROP_ACTIVE_CHALLENGES: _.noop, DROP_OPEN_FOR_REGISTRATION_CHALLENGES: _.noop, DROP_MY_CHALLENGES: _.noop, + DROP_ALL_CHALLENGES: _.noop, DROP_PAST_CHALLENGES: _.noop, // GET_ALL_ACTIVE_CHALLENGES_INIT: getAllActiveChallengesInit, @@ -474,6 +504,9 @@ export default createActions({ // GET_ALL_RECOMMENDED_CHALLENGES_INIT: getAllRecommendedChallengesInit, // GET_ALL_RECOMMENDED_CHALLENGES_DONE: getAllRecommendedChallengesDone, + GET_ALL_CHALLENGES_INIT: getAllChallengesInit, + GET_ALL_CHALLENGES_DONE: getAllChallengesDone, + GET_ACTIVE_CHALLENGES_INIT: getActiveChallengesInit, GET_ACTIVE_CHALLENGES_DONE: getActiveChallengesDone, diff --git a/src/shared/components/challenge-listing/Filters/ChallengeFilters.jsx b/src/shared/components/challenge-listing/Filters/ChallengeFilters.jsx index 6f5952d1dc..9f4f6f22cb 100644 --- a/src/shared/components/challenge-listing/Filters/ChallengeFilters.jsx +++ b/src/shared/components/challenge-listing/Filters/ChallengeFilters.jsx @@ -30,6 +30,7 @@ export default function ChallengeFilters({ auth, // isCardTypeSet, isReviewOpportunitiesBucket, + activeBucket, // saveFilter, searchText, selectCommunity, @@ -170,6 +171,7 @@ export default function ChallengeFilters({ isAuth={isAuth} auth={auth} isReviewOpportunitiesBucket={isReviewOpportunitiesBucket} + activeBucket={activeBucket} filterState={filterState} onClose={() => setExpanded(false)} // onSaveFilter={saveFilter} @@ -211,6 +213,7 @@ ChallengeFilters.propTypes = { communityFilters: PT.arrayOf(PT.shape()).isRequired, communityName: PT.string, defaultCommunityId: PT.string.isRequired, + activeBucket: PT.string.isRequired, // challenges: PT.arrayOf(PT.shape()), expanded: PT.bool.isRequired, filterState: PT.shape().isRequired, diff --git a/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx b/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx index 8db46340a8..39bc920a76 100644 --- a/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx +++ b/src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx @@ -32,7 +32,7 @@ import Tooltip from 'components/Tooltip'; import { config, Link } from 'topcoder-react-utils'; import { COMPOSE, PRIORITY } from 'react-css-super-themr'; import { REVIEW_OPPORTUNITY_TYPES } from 'utils/tc'; -import { isFilterEmpty } from 'utils/challenge-listing/buckets'; +import { BUCKETS, isFilterEmpty } from 'utils/challenge-listing/buckets'; import CheckmarkIcon from './CheckmarkIcon'; import DateRangePicker from '../DateRangePicker'; import style from './style.scss'; @@ -49,6 +49,7 @@ export default function FiltersPanel({ isAuth, auth, isReviewOpportunitiesBucket, + activeBucket, onClose, // onSaveFilter, selectCommunity, @@ -66,6 +67,8 @@ export default function FiltersPanel({ _.intersection(visitorGroupIds, communityGroupIds).length, ); + const isAllBucket = activeBucket === BUCKETS.ALL; + const getLabel = (community) => { const { communityName } = community; if (!isAuth) { @@ -304,6 +307,28 @@ export default function FiltersPanel({ ) : null } + {/* Only shown when the All Challenges bucket is selected */} + { isAllBucket + ? ( +
+ +