Skip to content

Commit

Permalink
Hot fix of sidebar challenge counts inside group challenge listing
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Jun 9, 2017
1 parent db37350 commit 1099974
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/shared/components/challenge-listing/SideBarFilters/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class SideBarFilters extends React.Component {
constructor(props) {
super(props);

const { challengeGroupId: cgi } = props;

const authToken = (props.auth && props.auth.tokenV2) || null;

this.state = {
Expand All @@ -106,7 +108,8 @@ class SideBarFilters extends React.Component {

for (let i = 0; i < this.state.filters.length; i += 1) {
const item = this.state.filters[i];
item.count = props.challenges.filter(item.getFilterFunction()).length;
item.count = props.challenges.filter(item.getFilterFunction())
.filter(it => !cgi || it.groups[cgi]).length;
}
for (let i = 0; i !== this.state.filters.length; i += 1) {
const f = this.state.filters[i];
Expand All @@ -128,7 +131,8 @@ class SideBarFilters extends React.Component {
this.state.currentFilter = DEFAULT_FILTERS[_.values(MODE).indexOf(props.filter.name)];
} else {
const f = new SideBarFilter(props.filter);
f.count = props.challenges.filter(f.getFilterFunction()).length;
f.count = props.challenges.filter(f.getFilterFunction())
.filter(it => !cgi || it.groups[cgi]).length;
this.state.currentFilter = f;
this.state.filters.push(f);
}
Expand Down Expand Up @@ -165,13 +169,15 @@ class SideBarFilters extends React.Component {
* this sidebar.
*/
componentWillReceiveProps(nextProps) {
const { challengeGroupId: cgi } = nextProps;
let currentFilter;
const filters = [];
this.state.filters.forEach((filter) => {
const filterClone = new SideBarFilter(filter);
if (this.state.currentFilter === filter) currentFilter = filterClone;
filterClone.groupId = nextProps.filter.groupId;
filterClone.count = nextProps.challenges.filter(filterClone.getFilterFunction()).length;
filterClone.count = nextProps.challenges.filter(filterClone.getFilterFunction())
.filter(it => !cgi || it.groups[cgi]).length;
filters.push(filterClone);
});
for (let i = 0; i < filters.length; i += 1) {
Expand Down Expand Up @@ -450,6 +456,7 @@ SideBarFilters.defaultProps = {
filter: new SideBarFilter(MODE.ALL_CHALLENGES),
isAuth: false,
onFilter: _.noop,
challengeGroupId: '',
config: {
MAIN_URL: '',
},
Expand All @@ -461,6 +468,7 @@ SideBarFilters.propTypes = {
registrationOpen: PT.string.isRequired,
})).isRequired,
filter: PT.instanceOf(SideBarFilter),
challengeGroupId: PT.string,
onFilter: PT.func,
isAuth: PT.bool,
config: PT.shape({
Expand Down
2 changes: 2 additions & 0 deletions src/shared/components/challenge-listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ class ChallengeFiltersExample extends React.Component {
<div styleName="sidebar-container-mobile">
{!this.props.loadingChallenges || expanded ? (<SideBarFilters
config={this.props.config}
challengeGroupId={filter.groupId}
challenges={challenges}
filter={this.getFilter()}
onFilter={topFilter => this.onFilterByTopFilter(topFilter, true)}
Expand All @@ -403,6 +404,7 @@ class ChallengeFiltersExample extends React.Component {
config={this.props.config}
challenges={challenges}
filter={this.getFilter()}
challengeGroupId={filter.groupId}
onFilter={topFilter => this.onFilterByTopFilter(topFilter, true)}
ref={(node) => {
this.sidebar = node;
Expand Down

0 comments on commit 1099974

Please sign in to comment.