Skip to content

Fix for Issue #5002 - Stays on main challenge listing when view more challenges is clicked. #5017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 @@ -81,6 +81,7 @@ exports[`Matches shallow shapshot 1`] = `
expandTag={null}
expanded={true}
expandedTags={Array []}
expanding={false}
loadMore={[MockFunction]}
loading={false}
newChallengeDetails={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`Matches shallow shapshot 1`] = `
<BucketSelector
activeBucket="activeBucket"
disabled={false}
expanding={false}
isAuth={false}
selectBucket={[MockFunction]}
/>
Expand All @@ -30,6 +31,7 @@ exports[`Matches shallow shapshot 2`] = `
<BucketSelector
activeBucket="activeBucket"
disabled={false}
expanding={false}
isAuth={false}
selectBucket={[MockFunction]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = `
communityName={null}
expandTag={null}
expandedTags={Array []}
expanding={false}
filterState={Object {}}
loadMoreActive={null}
loadMoreMy={null}
Expand Down Expand Up @@ -55,6 +56,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = `
top={20}
>
<Connect(SidebarContainer)
expanding={false}
hideTcLinksInFooter={false}
/>
</Sticky>
Expand Down Expand Up @@ -88,6 +90,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = `
communityName={null}
expandTag={null}
expandedTags={Array []}
expanding={false}
filterState={Object {}}
loadMoreActive={null}
loadMoreMy={null}
Expand Down Expand Up @@ -118,6 +121,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = `
top={20}
>
<Connect(SidebarContainer)
expanding={false}
hideTcLinksInFooter={false}
/>
</Sticky>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/actions/challenge-listing/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default createActions({
// SAVE_FILTER_INIT: _.noop,

/* Pass in the bucket type. */
SELECT_BUCKET: _.identity,
SELECT_BUCKET: (bucket, expanding = false) => ({ bucket, expanding }),
SELECT_BUCKET_DONE: _.noop,

/* Pass in the index of filter inside savedFilters array. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function Bucket({
challengeTypes,
challengesUrl,
expanded,
expanding,
expand,
filterState,
// keepPlaceholders,
Expand Down Expand Up @@ -60,7 +61,18 @@ export default function Bucket({
};
const activeSort = sort || 'startDate';

const sortedChallenges = activeBucket === 'all' ? _.clone(challenges.slice(0, 10)) : _.clone(challenges);
// const sortedChallenges = activeBucket === 'all' ?
// _.clone(challenges.slice(0, 10)) : _.clone(challenges);
let sortedChallenges;
if (activeBucket === 'all' && !expanded) {
if (loadMore && challenges.length > 10) {
sortedChallenges = _.clone(challenges);
} else {
sortedChallenges = _.clone(challenges.slice(0, 10));
}
} else {
sortedChallenges = _.clone(challenges);
}
// sortedChallenges.sort(Sort[activeSort].func);

// const bucketQuery = qs.stringify({
Expand Down Expand Up @@ -165,21 +177,21 @@ export default function Bucket({
/>
{cards}
{
!expandable && loadMore && !loading ? (
!expanding && !expandable && loadMore && !loading && activeBucket === bucket ? (
<Waypoint onEnter={loadMore} />
) : null
}
{placeholders}
{
// (expandable || loadMore) && (expandable || !keepPlaceholders) && !loading && !expanded ? (
(expandable || loadMore) && !loading && !expanded ? (
(expanding || expandable || loadMore) && !loading && !expanded ? (
<a
// href={`${challengesUrl}?${bucketQuery}`}
href={`${challengesUrl}`}
onClick={(event) => {
expand();
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
// document.body.scrollTop = 0;
// document.documentElement.scrollTop = 0;
event.preventDefault();
}}
role="button"
Expand Down Expand Up @@ -209,13 +221,15 @@ Bucket.defaultProps = {
expandedTags: [],
expandTag: null,
activeBucket: '',
expanding: false,
// searchTimestamp: 0,
};

Bucket.propTypes = {
bucket: PT.string.isRequired,
// bucketId: PT.string.isRequired,
expanded: PT.bool,
expanding: PT.bool,
expand: PT.func,
challenges: PT.arrayOf(PT.shape()).isRequired,
challengeTypes: PT.arrayOf(PT.shape()),
Expand Down
11 changes: 9 additions & 2 deletions src/shared/components/challenge-listing/Listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Listing({
setFilterState,
setSort,
sorts,
expanding,
expandedTags,
expandTag,
// pastSearchTimestamp,
Expand Down Expand Up @@ -141,8 +142,12 @@ function Listing({
challengeTypes={challengeTypes}
challengesUrl={challengesUrl}
communityName={communityName}
expand={() => selectBucket(bucket)}
expand={() => {
selectBucket(bucket, true);
loadMore();
}}
expanded={newExpanded}
expanding={expanding}
expandedTags={expandedTags}
expandTag={expandTag}
filterState={filterState}
Expand All @@ -166,7 +171,7 @@ function Listing({
);
};

if ((activeBucket !== BUCKETS.ALL)
if (!expanding && (activeBucket !== BUCKETS.ALL)
&& (activeBucket !== BUCKETS.SAVED_FILTER)) {
return (
<div styleName="challengeCardContainer">
Expand Down Expand Up @@ -224,10 +229,12 @@ Listing.defaultProps = {
openChallengesInNewTabs: false,
// pastSearchTimestamp: 0,
// userChallenges: [],
expanding: false,
};

Listing.propTypes = {
activeBucket: PT.string.isRequired,
expanding: PT.bool,
auth: PT.shape({
tokenV3: PT.string,
user: PT.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function BucketSelector({
// challenges,
// communityFilter,
disabled,
expanding,
// extraBucket,
// filterState,
isAuth,
Expand All @@ -38,20 +39,23 @@ export default function BucketSelector({
// filteredChallenges = filteredChallenges.filter(Filter.getFilterFunction(communityFilter));
// }

const getBucket = bucket => (
<Bucket
active={!disabled && activeBucket === bucket}
bucket={bucket}
// challenges={challenges}
disabled={disabled}
onClick={() => {
selectBucket(bucket);
/* eslint-env browser */
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}}
/>
);
const getBucket = (bucket) => {
const isActive = expanding ? bucket === BUCKETS.ALL : activeBucket === bucket;
return (
<Bucket
active={!disabled && isActive}
bucket={bucket}
// challenges={challenges}
disabled={disabled}
onClick={() => {
selectBucket(bucket);
/* eslint-env browser */
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}}
/>
);
};

// const savedFiltersRender = savedFilters.map((item, index) => (
// <Bucket
Expand Down Expand Up @@ -123,10 +127,12 @@ BucketSelector.defaultProps = {
disabled: false,
// extraBucket: null,
isAuth: false,
expanding: false,
};

BucketSelector.propTypes = {
activeBucket: PT.string.isRequired,
expanding: PT.bool,
// activeSavedFilter: PT.number.isRequired,
// buckets: PT.shape().isRequired,
// challenges: PT.arrayOf(PT.shape({
Expand Down
4 changes: 4 additions & 0 deletions src/shared/components/challenge-listing/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function SideBarFilters({
// communityFilter,
// deleteSavedFilter,
disabled,
expanding,
// dragSavedFilterMove,
// dragSavedFilterStart,
// dragState,
Expand Down Expand Up @@ -72,6 +73,7 @@ export default function SideBarFilters({
// challenges={challenges}
// communityFilter={communityFilter}
disabled={disabled}
expanding={expanding}
// extraBucket={extraBucket}
// filterState={filterState}
isAuth={isAuth}
Expand All @@ -94,10 +96,12 @@ SideBarFilters.defaultProps = {
// extraBucket: null,
hideTcLinksInFooter: false,
isAuth: false,
expanding: false,
};

SideBarFilters.propTypes = {
activeBucket: PT.string.isRequired,
expanding: PT.bool,
// activeSavedFilter: PT.number.isRequired,
// buckets: PT.shape().isRequired,
// challenges: PT.arrayOf(PT.shape({
Expand Down
5 changes: 5 additions & 0 deletions src/shared/components/challenge-listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function ChallengeListing(props) {
// communityFilter,
communityName,
defaultCommunityId,
expanding,
// extraBucket,
// filterState,
hideSrm,
Expand Down Expand Up @@ -129,6 +130,7 @@ export default function ChallengeListing(props) {
setSort={props.setSort}
sorts={props.sorts}
loadMoreActive={props.loadMoreActive}
expanding={expanding}
// loadingActiveChallenges={props.loadingChallenges}
// userChallenges={props.userChallenges}
isLoggedIn={isLoggedIn}
Expand Down Expand Up @@ -161,6 +163,7 @@ export default function ChallengeListing(props) {
<Sticky top={20} bottomBoundary="#challengeFilterContainer">
<Sidebar
// extraBucket={extraBucket}
expanding={expanding}
hideTcLinksInFooter={hideTcLinksInFooter}
/>
</Sticky>
Expand Down Expand Up @@ -189,12 +192,14 @@ ChallengeListing.defaultProps = {
expandedTags: [],
expandTag: null,
loadMoreActive: null,
expanding: false,
// isBucketSwitching: false,
// userChallenges: [],
};

ChallengeListing.propTypes = {
activeBucket: PT.string.isRequired,
expanding: PT.bool,
challenges: PT.arrayOf(PT.shape()).isRequired,
openForRegistrationChallenges: PT.arrayOf(PT.shape()).isRequired,
myChallenges: PT.arrayOf(PT.arrayOf()).isRequired,
Expand Down
7 changes: 6 additions & 1 deletion src/shared/containers/challenge-listing/Listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export class ListingContainer extends React.Component {
communityId,
communityName,
defaultCommunityId,
expanding,
expandTag,
expandedTags,
// extraBucket,
Expand Down Expand Up @@ -486,6 +487,7 @@ export class ListingContainer extends React.Component {
communityFilter={communityFilter}
communityName={communityName}
defaultCommunityId={defaultCommunityId}
expanding={expanding}
expandedTags={expandedTags}
expandTag={expandTag}
// extraBucket={extraBucket}
Expand Down Expand Up @@ -558,6 +560,7 @@ ListingContainer.defaultProps = {
prizeMode: 'money-usd',
queryBucket: BUCKETS.ALL,
meta: {},
expanding: false,
// isBucketSwitching: false,
// userChallenges: [],
};
Expand Down Expand Up @@ -630,6 +633,7 @@ ListingContainer.propTypes = {
selectCommunity: PT.func.isRequired,
setFilter: PT.func.isRequired,
activeBucket: PT.string.isRequired,
expanding: PT.bool,
selectedCommunityId: PT.string,
sorts: PT.shape().isRequired,
setSearchText: PT.func.isRequired,
Expand Down Expand Up @@ -693,6 +697,7 @@ const mapStateToProps = (state, ownProps) => {
selectedCommunityId: cl.selectedCommunityId,
sorts: cl.sorts,
activeBucket: cl.sidebar.activeBucket,
expanding: cl.sidebar.expanding,
// isBucketSwitching: cl.sidebar.isBucketSwitching,
expandedTags: cl.expandedTags,
meta: cl.meta,
Expand Down Expand Up @@ -752,7 +757,7 @@ function mapDispatchToProps(dispatch) {
dispatch(a.getReviewOpportunitiesInit(uuid, page));
dispatch(a.getReviewOpportunitiesDone(uuid, page, token));
},
selectBucket: bucket => dispatch(sa.selectBucket(bucket)),
selectBucket: (bucket, expanding) => dispatch(sa.selectBucket(bucket, expanding)),
selectBucketDone: () => dispatch(sa.selectBucketDone()),
selectChallengeDetailsTab:
tab => dispatch(challengeDetailsActions.page.challengeDetails.selectTab(tab)),
Expand Down
7 changes: 4 additions & 3 deletions src/shared/reducers/challenge-listing/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ import { updateQuery } from 'utils/url';
// }

function onSelectBucket(state, { payload }) {
switch (payload) {
switch (payload.bucket) {
case BUCKETS.ALL:
// case BUCKETS.SAVED_FILTER:
updateQuery({ bucket: undefined });
break;
default:
updateQuery({ bucket: payload });
updateQuery({ bucket: payload.expanding ? undefined : payload.bucket });
break;
}
return {
...state,
activeBucket: payload,
activeBucket: payload.bucket,
expanding: payload.expanding,
isBucketSwitching: true,
};
}
Expand Down