Skip to content

Commit a352932

Browse files
Merge pull request topcoder-platform#5017 from gets0ul/issue_5002-fix
Fix for Issue topcoder-platform#5002 - Stays on main challenge listing when view more challenges is clicked.
2 parents c0c7eeb + db8315b commit a352932

File tree

11 files changed

+75
-26
lines changed

11 files changed

+75
-26
lines changed

__tests__/shared/components/challenge-listing/Listing/__snapshots__/Bucket.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ exports[`Matches shallow shapshot 1`] = `
8181
expandTag={null}
8282
expanded={true}
8383
expandedTags={Array []}
84+
expanding={false}
8485
loadMore={[MockFunction]}
8586
loading={false}
8687
newChallengeDetails={false}

__tests__/shared/components/challenge-listing/Sidebar/__snapshots__/index.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exports[`Matches shallow shapshot 1`] = `
1010
<BucketSelector
1111
activeBucket="activeBucket"
1212
disabled={false}
13+
expanding={false}
1314
isAuth={false}
1415
selectBucket={[MockFunction]}
1516
/>
@@ -30,6 +31,7 @@ exports[`Matches shallow shapshot 2`] = `
3031
<BucketSelector
3132
activeBucket="activeBucket"
3233
disabled={false}
34+
expanding={false}
3335
isAuth={false}
3436
selectBucket={[MockFunction]}
3537
/>

__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = `
2525
communityName={null}
2626
expandTag={null}
2727
expandedTags={Array []}
28+
expanding={false}
2829
filterState={Object {}}
2930
loadMoreActive={null}
3031
loadMoreMy={null}
@@ -55,6 +56,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = `
5556
top={20}
5657
>
5758
<Connect(SidebarContainer)
59+
expanding={false}
5860
hideTcLinksInFooter={false}
5961
/>
6062
</Sticky>
@@ -88,6 +90,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = `
8890
communityName={null}
8991
expandTag={null}
9092
expandedTags={Array []}
93+
expanding={false}
9194
filterState={Object {}}
9295
loadMoreActive={null}
9396
loadMoreMy={null}
@@ -118,6 +121,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = `
118121
top={20}
119122
>
120123
<Connect(SidebarContainer)
124+
expanding={false}
121125
hideTcLinksInFooter={false}
122126
/>
123127
</Sticky>

src/shared/actions/challenge-listing/sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export default createActions({
142142
// SAVE_FILTER_INIT: _.noop,
143143

144144
/* Pass in the bucket type. */
145-
SELECT_BUCKET: _.identity,
145+
SELECT_BUCKET: (bucket, expanding = false) => ({ bucket, expanding }),
146146
SELECT_BUCKET_DONE: _.noop,
147147

148148
/* Pass in the index of filter inside savedFilters array. */

src/shared/components/challenge-listing/Listing/Bucket/index.jsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default function Bucket({
3131
challengeTypes,
3232
challengesUrl,
3333
expanded,
34+
expanding,
3435
expand,
3536
filterState,
3637
// keepPlaceholders,
@@ -60,7 +61,18 @@ export default function Bucket({
6061
};
6162
const activeSort = sort || 'startDate';
6263

63-
const sortedChallenges = activeBucket === 'all' ? _.clone(challenges.slice(0, 10)) : _.clone(challenges);
64+
// const sortedChallenges = activeBucket === 'all' ?
65+
// _.clone(challenges.slice(0, 10)) : _.clone(challenges);
66+
let sortedChallenges;
67+
if (activeBucket === 'all' && !expanded) {
68+
if (loadMore && challenges.length > 10) {
69+
sortedChallenges = _.clone(challenges);
70+
} else {
71+
sortedChallenges = _.clone(challenges.slice(0, 10));
72+
}
73+
} else {
74+
sortedChallenges = _.clone(challenges);
75+
}
6476
// sortedChallenges.sort(Sort[activeSort].func);
6577

6678
// const bucketQuery = qs.stringify({
@@ -165,21 +177,21 @@ export default function Bucket({
165177
/>
166178
{cards}
167179
{
168-
!expandable && loadMore && !loading ? (
180+
!expanding && !expandable && loadMore && !loading && activeBucket === bucket ? (
169181
<Waypoint onEnter={loadMore} />
170182
) : null
171183
}
172184
{placeholders}
173185
{
174186
// (expandable || loadMore) && (expandable || !keepPlaceholders) && !loading && !expanded ? (
175-
(expandable || loadMore) && !loading && !expanded ? (
187+
(expanding || expandable || loadMore) && !loading && !expanded ? (
176188
<a
177189
// href={`${challengesUrl}?${bucketQuery}`}
178190
href={`${challengesUrl}`}
179191
onClick={(event) => {
180192
expand();
181-
document.body.scrollTop = 0;
182-
document.documentElement.scrollTop = 0;
193+
// document.body.scrollTop = 0;
194+
// document.documentElement.scrollTop = 0;
183195
event.preventDefault();
184196
}}
185197
role="button"
@@ -209,13 +221,15 @@ Bucket.defaultProps = {
209221
expandedTags: [],
210222
expandTag: null,
211223
activeBucket: '',
224+
expanding: false,
212225
// searchTimestamp: 0,
213226
};
214227

215228
Bucket.propTypes = {
216229
bucket: PT.string.isRequired,
217230
// bucketId: PT.string.isRequired,
218231
expanded: PT.bool,
232+
expanding: PT.bool,
219233
expand: PT.func,
220234
challenges: PT.arrayOf(PT.shape()).isRequired,
221235
challengeTypes: PT.arrayOf(PT.shape()),

src/shared/components/challenge-listing/Listing/index.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function Listing({
5555
setFilterState,
5656
setSort,
5757
sorts,
58+
expanding,
5859
expandedTags,
5960
expandTag,
6061
// pastSearchTimestamp,
@@ -141,8 +142,12 @@ function Listing({
141142
challengeTypes={challengeTypes}
142143
challengesUrl={challengesUrl}
143144
communityName={communityName}
144-
expand={() => selectBucket(bucket)}
145+
expand={() => {
146+
selectBucket(bucket, true);
147+
loadMore();
148+
}}
145149
expanded={newExpanded}
150+
expanding={expanding}
146151
expandedTags={expandedTags}
147152
expandTag={expandTag}
148153
filterState={filterState}
@@ -166,7 +171,7 @@ function Listing({
166171
);
167172
};
168173

169-
if ((activeBucket !== BUCKETS.ALL)
174+
if (!expanding && (activeBucket !== BUCKETS.ALL)
170175
&& (activeBucket !== BUCKETS.SAVED_FILTER)) {
171176
return (
172177
<div styleName="challengeCardContainer">
@@ -224,10 +229,12 @@ Listing.defaultProps = {
224229
openChallengesInNewTabs: false,
225230
// pastSearchTimestamp: 0,
226231
// userChallenges: [],
232+
expanding: false,
227233
};
228234

229235
Listing.propTypes = {
230236
activeBucket: PT.string.isRequired,
237+
expanding: PT.bool,
231238
auth: PT.shape({
232239
tokenV3: PT.string,
233240
user: PT.shape({

src/shared/components/challenge-listing/Sidebar/BucketSelector/index.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function BucketSelector({
2424
// challenges,
2525
// communityFilter,
2626
disabled,
27+
expanding,
2728
// extraBucket,
2829
// filterState,
2930
isAuth,
@@ -38,20 +39,23 @@ export default function BucketSelector({
3839
// filteredChallenges = filteredChallenges.filter(Filter.getFilterFunction(communityFilter));
3940
// }
4041

41-
const getBucket = bucket => (
42-
<Bucket
43-
active={!disabled && activeBucket === bucket}
44-
bucket={bucket}
45-
// challenges={challenges}
46-
disabled={disabled}
47-
onClick={() => {
48-
selectBucket(bucket);
49-
/* eslint-env browser */
50-
document.body.scrollTop = 0;
51-
document.documentElement.scrollTop = 0;
52-
}}
53-
/>
54-
);
42+
const getBucket = (bucket) => {
43+
const isActive = expanding ? bucket === BUCKETS.ALL : activeBucket === bucket;
44+
return (
45+
<Bucket
46+
active={!disabled && isActive}
47+
bucket={bucket}
48+
// challenges={challenges}
49+
disabled={disabled}
50+
onClick={() => {
51+
selectBucket(bucket);
52+
/* eslint-env browser */
53+
document.body.scrollTop = 0;
54+
document.documentElement.scrollTop = 0;
55+
}}
56+
/>
57+
);
58+
};
5559

5660
// const savedFiltersRender = savedFilters.map((item, index) => (
5761
// <Bucket
@@ -123,10 +127,12 @@ BucketSelector.defaultProps = {
123127
disabled: false,
124128
// extraBucket: null,
125129
isAuth: false,
130+
expanding: false,
126131
};
127132

128133
BucketSelector.propTypes = {
129134
activeBucket: PT.string.isRequired,
135+
expanding: PT.bool,
130136
// activeSavedFilter: PT.number.isRequired,
131137
// buckets: PT.shape().isRequired,
132138
// challenges: PT.arrayOf(PT.shape({

src/shared/components/challenge-listing/Sidebar/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default function SideBarFilters({
3232
// communityFilter,
3333
// deleteSavedFilter,
3434
disabled,
35+
expanding,
3536
// dragSavedFilterMove,
3637
// dragSavedFilterStart,
3738
// dragState,
@@ -72,6 +73,7 @@ export default function SideBarFilters({
7273
// challenges={challenges}
7374
// communityFilter={communityFilter}
7475
disabled={disabled}
76+
expanding={expanding}
7577
// extraBucket={extraBucket}
7678
// filterState={filterState}
7779
isAuth={isAuth}
@@ -94,10 +96,12 @@ SideBarFilters.defaultProps = {
9496
// extraBucket: null,
9597
hideTcLinksInFooter: false,
9698
isAuth: false,
99+
expanding: false,
97100
};
98101

99102
SideBarFilters.propTypes = {
100103
activeBucket: PT.string.isRequired,
104+
expanding: PT.bool,
101105
// activeSavedFilter: PT.number.isRequired,
102106
// buckets: PT.shape().isRequired,
103107
// challenges: PT.arrayOf(PT.shape({

src/shared/components/challenge-listing/index.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function ChallengeListing(props) {
3535
// communityFilter,
3636
communityName,
3737
defaultCommunityId,
38+
expanding,
3839
// extraBucket,
3940
// filterState,
4041
hideSrm,
@@ -129,6 +130,7 @@ export default function ChallengeListing(props) {
129130
setSort={props.setSort}
130131
sorts={props.sorts}
131132
loadMoreActive={props.loadMoreActive}
133+
expanding={expanding}
132134
// loadingActiveChallenges={props.loadingChallenges}
133135
// userChallenges={props.userChallenges}
134136
isLoggedIn={isLoggedIn}
@@ -161,6 +163,7 @@ export default function ChallengeListing(props) {
161163
<Sticky top={20} bottomBoundary="#challengeFilterContainer">
162164
<Sidebar
163165
// extraBucket={extraBucket}
166+
expanding={expanding}
164167
hideTcLinksInFooter={hideTcLinksInFooter}
165168
/>
166169
</Sticky>
@@ -189,12 +192,14 @@ ChallengeListing.defaultProps = {
189192
expandedTags: [],
190193
expandTag: null,
191194
loadMoreActive: null,
195+
expanding: false,
192196
// isBucketSwitching: false,
193197
// userChallenges: [],
194198
};
195199

196200
ChallengeListing.propTypes = {
197201
activeBucket: PT.string.isRequired,
202+
expanding: PT.bool,
198203
challenges: PT.arrayOf(PT.shape()).isRequired,
199204
openForRegistrationChallenges: PT.arrayOf(PT.shape()).isRequired,
200205
myChallenges: PT.arrayOf(PT.arrayOf()).isRequired,

src/shared/containers/challenge-listing/Listing/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export class ListingContainer extends React.Component {
336336
communityId,
337337
communityName,
338338
defaultCommunityId,
339+
expanding,
339340
expandTag,
340341
expandedTags,
341342
// extraBucket,
@@ -486,6 +487,7 @@ export class ListingContainer extends React.Component {
486487
communityFilter={communityFilter}
487488
communityName={communityName}
488489
defaultCommunityId={defaultCommunityId}
490+
expanding={expanding}
489491
expandedTags={expandedTags}
490492
expandTag={expandTag}
491493
// extraBucket={extraBucket}
@@ -558,6 +560,7 @@ ListingContainer.defaultProps = {
558560
prizeMode: 'money-usd',
559561
queryBucket: BUCKETS.ALL,
560562
meta: {},
563+
expanding: false,
561564
// isBucketSwitching: false,
562565
// userChallenges: [],
563566
};
@@ -630,6 +633,7 @@ ListingContainer.propTypes = {
630633
selectCommunity: PT.func.isRequired,
631634
setFilter: PT.func.isRequired,
632635
activeBucket: PT.string.isRequired,
636+
expanding: PT.bool,
633637
selectedCommunityId: PT.string,
634638
sorts: PT.shape().isRequired,
635639
setSearchText: PT.func.isRequired,
@@ -693,6 +697,7 @@ const mapStateToProps = (state, ownProps) => {
693697
selectedCommunityId: cl.selectedCommunityId,
694698
sorts: cl.sorts,
695699
activeBucket: cl.sidebar.activeBucket,
700+
expanding: cl.sidebar.expanding,
696701
// isBucketSwitching: cl.sidebar.isBucketSwitching,
697702
expandedTags: cl.expandedTags,
698703
meta: cl.meta,
@@ -752,7 +757,7 @@ function mapDispatchToProps(dispatch) {
752757
dispatch(a.getReviewOpportunitiesInit(uuid, page));
753758
dispatch(a.getReviewOpportunitiesDone(uuid, page, token));
754759
},
755-
selectBucket: bucket => dispatch(sa.selectBucket(bucket)),
760+
selectBucket: (bucket, expanding) => dispatch(sa.selectBucket(bucket, expanding)),
756761
selectBucketDone: () => dispatch(sa.selectBucketDone()),
757762
selectChallengeDetailsTab:
758763
tab => dispatch(challengeDetailsActions.page.challengeDetails.selectTab(tab)),

src/shared/reducers/challenge-listing/sidebar.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,19 @@ import { updateQuery } from 'utils/url';
120120
// }
121121

122122
function onSelectBucket(state, { payload }) {
123-
switch (payload) {
123+
switch (payload.bucket) {
124124
case BUCKETS.ALL:
125125
// case BUCKETS.SAVED_FILTER:
126126
updateQuery({ bucket: undefined });
127127
break;
128128
default:
129-
updateQuery({ bucket: payload });
129+
updateQuery({ bucket: payload.expanding ? undefined : payload.bucket });
130130
break;
131131
}
132132
return {
133133
...state,
134-
activeBucket: payload,
134+
activeBucket: payload.bucket,
135+
expanding: payload.expanding,
135136
isBucketSwitching: true,
136137
};
137138
}

0 commit comments

Comments
 (0)