Skip to content

Topcoder Community-App: Challenges Filter and Stats - Part 3 #3408

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

Closed
Closed
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
16 changes: 16 additions & 0 deletions src/shared/containers/challenge-listing/FilterPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Container for the header filters panel.
*/
/* global window */
/* eslint-disable max-len */

import actions from 'actions/challenge-listing/filter-panel';
import challengeListingActions from 'actions/challenge-listing';
Expand Down Expand Up @@ -66,6 +67,20 @@ export class Container extends React.Component {
}
}

componentWillUpdate(nextProps) {
const {
selectCommunity,
communityFilters,
} = this.props;

if (nextProps.communityFilters.length > 0 && communityFilters.length === 0) {
const query = qs.parse(window.location.search.slice(1));
if (query.communityId) {
selectCommunity(query.communityId);
}
}
}

render() {
const {
activeBucket,
Expand Down Expand Up @@ -144,6 +159,7 @@ Container.propTypes = {
selectedCommunityId: PT.string.isRequired,
getKeywords: PT.func.isRequired,
getSubtracks: PT.func.isRequired,
selectCommunity: PT.func.isRequired,
isSavingFilter: PT.bool,
savedFilters: PT.arrayOf(PT.shape()).isRequired,
loadingKeywords: PT.bool.isRequired,
Expand Down
6 changes: 5 additions & 1 deletion src/shared/containers/challenge-listing/Listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,12 @@ export class ListingContainer extends React.Component {
);
}

let isTrueCommunityId = true;
let communityFilter = communityFilters.find(item => item.communityId === selectedCommunityId);
if (communityFilter) communityFilter = communityFilter.challengeFilter;
if (selectedCommunityId && communityFilters.length > 0 && communityFilter === undefined) {
isTrueCommunityId = false;
}

const description = 'Join Topcoder and compete in these challenges, to learn and earn!';

Expand Down Expand Up @@ -252,7 +256,7 @@ export class ListingContainer extends React.Component {
{banner}
<ChallengeListing
activeBucket={activeBucket}
challenges={challenges}
challenges={isTrueCommunityId ? challenges : []}
challengeSubtracks={challengeSubtracks}
challengeTags={challengeTags}
challengesUrl={challengesUrl}
Expand Down
8 changes: 7 additions & 1 deletion src/shared/containers/challenge-listing/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class SidebarContainer extends React.Component {
render() {
const {
communityFilters,
challenges,
deleteSavedFilter,
extraBucket,
savedFilters: origSavedFilters,
Expand Down Expand Up @@ -80,14 +81,18 @@ export class SidebarContainer extends React.Component {
item => item.communityId === selectedCommunityId,
);
if (communityFilter) communityFilter = communityFilter.challengeFilter;

let isTrueCommunityId = true;
if (selectedCommunityId && communityFilters.length > 0 && communityFilter === undefined) {
isTrueCommunityId = false;
}
const savedFilters = checkFilterErrors(origSavedFilters, updatedCommunityFilters);

return (
<Sidebar
{...this.props}
buckets={buckets}
extraBucket={extraBucket}
challenges={isTrueCommunityId ? challenges : []}
savedFilters={savedFilters}
communityFilter={communityFilter}
deleteSavedFilter={id => deleteSavedFilter(id, tokenV2)}
Expand Down Expand Up @@ -122,6 +127,7 @@ SidebarContainer.propTypes = {
communityId: PT.string.isRequired,
})).isRequired,
deleteSavedFilter: PT.func.isRequired,
challenges: PT.arrayOf(PT.shape({})).isRequired,
extraBucket: PT.shape(),
getSavedFilters: PT.func.isRequired,
savedFilters: PT.arrayOf(PT.shape()).isRequired,
Expand Down