Skip to content

Commit 4d81d90

Browse files
Merge pull request #5077 from PrakashDurlabhji/f2f-filterfix
f2f filterfix
2 parents 52d9250 + 0336140 commit 4d81d90

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

src/shared/components/challenge-detail/Header/ChallengeTags.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default function ChallengeTags(props) {
6666
setImmediate(() => setChallengeListingFilter({ types: [challengeType.abbreviation] }))
6767
)
6868
}
69-
to={`${challengesUrl}?filter[types][0]=${encodeURIComponent(challengeType.abbreviation)}`}
69+
to={`${challengesUrl}?types[]=${encodeURIComponent(challengeType.abbreviation)}`}
7070
>
7171
{challengeType.name}
7272
</TrackTag>
@@ -90,7 +90,7 @@ export default function ChallengeTags(props) {
9090
key={tag}
9191
onClick={() => setImmediate(() => setChallengeListingFilter({ tags: [tag] }))
9292
}
93-
to={`${challengesUrl}?filter[tags][0]=${
93+
to={`${challengesUrl}?tags[]=${
9494
encodeURIComponent(tag)}`}
9595
>
9696
{tag}

src/shared/components/challenge-listing/Filters/ChallengeFilters.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import React from 'react';
55
import PT from 'prop-types';
66
import SwitchWithLabel from 'components/SwitchWithLabel';
7-
// import { challenge as challengeUtils } from 'topcoder-react-lib';
7+
import { challenge as challengeUtils } from 'topcoder-react-lib';
88
// import { COMPETITION_TRACKS as TRACKS } from 'utils/tc';
99
import _ from 'lodash';
1010

@@ -17,7 +17,7 @@ import FiltersSwitch from './FiltersSwitch';
1717

1818
import './ChallengeFilters.scss';
1919

20-
// const Filter = challengeUtils.filter;
20+
const Filter = challengeUtils.filter;
2121

2222
export default function ChallengeFilters({
2323
communityFilters,
@@ -56,9 +56,9 @@ export default function ChallengeFilters({
5656
const isTrackOn = track => filterState.tracks && filterState.tracks[track];
5757

5858
const switchTrack = (track, on) => {
59-
const newFilter = _.cloneDeep(filterState);
60-
newFilter.tracks[track] = on;
61-
setFilterState({ ...newFilter });
59+
const act = on ? Filter.addTrack : Filter.removeTrack;
60+
const filterObj = act(filterState, track);
61+
setFilterState({ ...filterObj });
6262
};
6363

6464
const clearSearch = () => {

src/shared/containers/challenge-listing/FilterPanel.jsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import React from 'react';
1616
import { isReviewOpportunitiesBucket } from 'utils/challenge-listing/buckets';
1717
import { bindActionCreators } from 'redux';
1818
import { connect } from 'react-redux';
19-
// import qs from 'qs';
19+
import qs from 'qs';
20+
import _ from 'lodash';
2021

2122
/* The default name for user-saved challenge filters. An integer
2223
* number will be appended to it, when necessary, to keep filter
@@ -47,8 +48,8 @@ export class Container extends React.Component {
4748
getTypes,
4849
loadingKeywords,
4950
loadingTypes,
50-
// setFilterState,
51-
// filterState,
51+
setFilterState,
52+
filterState,
5253
communityList,
5354
getCommunityList,
5455
auth,
@@ -62,10 +63,10 @@ export class Container extends React.Component {
6263
if (!loadingKeywords) getKeywords();
6364

6465

65-
// const query = qs.parse(window.location.search.slice(1));
66-
// if (query.filter && !filterState.track) {
67-
// setFilterState(query.filter);
68-
// } else {
66+
const query = qs.parse(window.location.search.slice(1));
67+
if (!_.isEmpty(query) && !filterState.track) {
68+
setFilterState(query);
69+
}
6970
// const trackStatus = localStorage.getItem('trackStatus');
7071
// const filterObj = trackStatus ? JSON.parse(trackStatus) : null;
7172
// if (filterObj) {
@@ -189,7 +190,7 @@ function mapDispatchToProps(dispatch) {
189190
// },
190191
// selectBucket: bucket => dispatch(sa.selectBucket(bucket)),
191192
selectCommunity: id => dispatch(cla.selectCommunity(id)),
192-
// setFilterState: s => dispatch(cla.setFilter(s)),
193+
setFilterState: s => dispatch(cla.setFilter(s)),
193194
};
194195
}
195196

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ function onSetFilter(state, { payload }) {
409409
* do it very carefuly (many params are not validated). */
410410
const filter = _.pickBy(_.pick(
411411
payload,
412-
['tags', 'types', 'name', 'startDateEnd', 'endDateStart', 'groups'],
412+
['tags', 'types', 'name', 'startDateEnd', 'endDateStart', 'groups', 'tracks'],
413413
), value => (!_.isArray(value) && value && value !== '') || (_.isArray(value) && value.length > 0));
414414
// if (_.isPlainObject(filter.tags)) {
415415
// filter.tags = _.values(filter.tags);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function onSelectBucket(state, { payload }) {
123123
switch (payload.bucket) {
124124
case BUCKETS.ALL:
125125
// case BUCKETS.SAVED_FILTER:
126-
updateQuery({ bucket: undefined });
126+
updateQuery({ bucket: payload.bucket });
127127
break;
128128
default:
129129
updateQuery({ bucket: payload.expanding ? undefined : payload.bucket });

src/shared/utils/url.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import _ from 'lodash';
88
import qs from 'qs';
99
import { isomorphy } from 'topcoder-react-utils';
10-
10+
import { BUCKETS } from 'utils/challenge-listing/buckets';
1111
/**
1212
* Get current URL hash parameters as object
1313
*/
@@ -37,19 +37,40 @@ export function getQuery() {
3737
export function updateQuery(update) {
3838
if (isomorphy.isServerSide()) return;
3939

40-
// let query = qs.parse(window.location.search.slice(1));
40+
let filterObj = {};
41+
// check if bucket is selected
42+
if (update.bucket) {
43+
// fetching everything else from url except bucket
44+
filterObj = {
45+
...qs.parse(window.location.search.slice(1)),
46+
...update,
47+
};
48+
if (update.bucket === BUCKETS.ALL) {
49+
delete filterObj.bucket; // delete bucket field for all challenges
50+
}
51+
} else {
52+
// fetch only bucket from url
53+
const query = qs.parse(window.location.search.slice(1));
54+
filterObj = {
55+
...(query.bucket && { bucket: query.bucket }), // fetch only bucket from url
56+
...update,
57+
};
58+
}
4159
let query = '?';
4260
const { hash } = window.location;
4361
const filterArray = [];
4462

4563
/* _.merge won't work here, because it just ignores the fields explicitely
4664
* set as undefined in the objects to be merged, rather than deleting such
4765
* fields in the target object. */
48-
_.forIn(update, (value, key) => {
66+
_.forIn(filterObj, (value, key) => {
4967
if (_.isArray(value) && value.length > 0) filterArray.push(value.map(item => `${key}[]=${item}`).join('&'));
5068
// eslint-disable-next-line max-len
5169
else if (_.isUndefined(value) || _.isEmpty(value) || (_.isArray(value) && value.length === 0)) delete query[key];
52-
else {
70+
else if (typeof value === 'object') {
71+
const separator = query === '?' ? '' : '&';
72+
query += `${separator}${qs.stringify({ tracks: value }, { encodeValuesOnly: true })}`;
73+
} else {
5374
const separator = query === '?' ? '' : '&';
5475
query += `${separator}${key}=${value}`;
5576
}

0 commit comments

Comments
 (0)