Skip to content

Fix issue #212 #272

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
merged 5 commits into from
Aug 30, 2017
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
9 changes: 9 additions & 0 deletions src/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import logger from 'utils/logger';
import { handleActions } from 'redux-actions';
import { combine, resolveReducers } from 'utils/redux';
import { updateQuery } from 'utils/url';
import moment from 'moment';

import filterPanel from '../challenge-listing/filter-panel';
import sidebar, { factory as sidebarFactory } from '../challenge-listing/sidebar';
Expand Down Expand Up @@ -270,6 +271,14 @@ export function factory(req) {

if (req) {
state.filter = req.query.filter;
if (!!state.filter && !!state.filter.startDate
&& moment(state.filter.startDate).isValid() === false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... It is enough to write
if (state.filter && state.filter.stateDate && moment(state.filter.startDate).isValid()) {
not sure, why you don't do it this way? Please fix.

delete state.filter.startDate;
}
if (!!state.filter && !!state.filter.endDate
&& moment(state.filter.endDate).isValid() === false) {
delete state.filter.endDate;
}
state.selectedCommunityId = req.query.communityId;
}

Expand Down
11 changes: 11 additions & 0 deletions src/shared/routes/Topcoder/ChallengeListing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import _ from 'lodash';
import LoadingIndicator from 'components/LoadingIndicator';
import qs from 'qs';
import React from 'react';
import moment from 'moment';
import { SplitRoute } from 'utils/router';
import { updateQuery } from 'utils/url';

export default function ChallengeListingRoute() {
return (
Expand All @@ -21,6 +23,15 @@ export default function ChallengeListingRoute() {
).then(({ default: ChallengeListing }) => {
const query = renderProps.location.search ?
qs.parse(renderProps.location.search.slice(1)) : null;
if (query.filter && query.filter.startDate
&& !moment(query.filter.startDate).isValid()) {
delete query.filter.startDate;
}
if (query.filter && query.filter.endDate
&& !moment(query.filter.endDate).isValid()) {
delete query.filter.endDate;
}
updateQuery({ filter: query.filter });
const currencyFromUrl = _.get(query, 'currency');
const prizeMode = currencyFromUrl && `money-${currencyFromUrl}`;
return (
Expand Down
1 change: 0 additions & 1 deletion src/shared/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function updateQuery(update) {
if (_.isUndefined(value)) delete query[key];
else query[key] = value;
});

query = `?${qs.stringify(query, { encode: false })}`;
window.history.replaceState(window.history.state, '', query);
}
Expand Down