Skip to content

Commit 2c292d5

Browse files
author
任庆伟
committed
update the date time check logic as suggested
1 parent b50589c commit 2c292d5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/shared/routes/Topcoder/ChallengeListing.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import _ from 'lodash';
77
import LoadingIndicator from 'components/LoadingIndicator';
88
import qs from 'qs';
99
import React from 'react';
10+
import moment from 'moment';
1011
import { SplitRoute } from 'utils/router';
1112
import { updateQuery } from 'utils/url';
1213

@@ -20,9 +21,17 @@ export default function ChallengeListingRoute() {
2021
/* webpackChunkName: "challenge-listing" */
2122
'containers/challenge-listing/Listing',
2223
).then(({ default: ChallengeListing }) => {
23-
updateQuery({ });
2424
const query = renderProps.location.search ?
2525
qs.parse(renderProps.location.search.slice(1)) : null;
26+
if (query.filter && query.filter.startDate
27+
&& !moment(query.filter.startDate).isValid()) {
28+
delete query.filter.startDate;
29+
}
30+
if (query.filter && query.filter.endDate
31+
&& !moment(query.filter.endDate).isValid()) {
32+
delete query.filter.endDate;
33+
}
34+
updateQuery({ filter: query.filter });
2635
const currencyFromUrl = _.get(query, 'currency');
2736
const prizeMode = currencyFromUrl && `money-${currencyFromUrl}`;
2837
return (

src/shared/utils/url.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import _ from 'lodash';
88
import qs from 'qs';
9-
import moment from 'moment';
109

1110
/**
1211
* If executed client-side (determined in this case by the presence of global
@@ -29,14 +28,6 @@ export function updateQuery(update) {
2928
if (_.isUndefined(value)) delete query[key];
3029
else query[key] = value;
3130
});
32-
if (!!query.filter && !!query.filter.startDate
33-
&& moment(query.filter.startDate).isValid() === false) {
34-
delete query.filter.startDate;
35-
} else if (!!query.filter && !!query.filter.endDate
36-
&& moment(query.filter.endDate).isValid() === false) {
37-
delete query.filter.endDate;
38-
}
39-
4031
query = `?${qs.stringify(query, { encode: false })}`;
4132
window.history.replaceState(window.history.state, '', query);
4233
}

0 commit comments

Comments
 (0)