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
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions src/shared/components/challenge-listing/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ import './style.scss';
const CHALLENGE_PLACEHOLDER_COUNT = 8;

export default function ChallengeListing(props) {
function CheckDateTime(str) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@twicoder Ha! Love your efforts here, and most probably, this code behaves properly (have not tested), but I believe, the best way to do this check is actually just using momentjs, doing moment(date).isValid(): https://momentjs.com/docs/#/parsing/is-valid/

const reg = /^(\d{4})-(\d{1,2})-(\d{1,2})T(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{3})Z$/;
const r = str.match(reg);
if (r == null) return false;
r[2] -= 1;
const d = new Date(r[1], r[2], r[3], r[4], r[5], r[6]);
if (d.getFullYear() !== r[1]) return false;
if (d.getMonth() !== r[2]) return false;
if (d.getDate() !== r[3]) return false;
if (d.getHours() !== r[4]) return false;
if (d.getMinutes() !== r[5]) return false;
if (d.getSeconds() !== r[6]) return false;
return true;
}
const filterState = props.filterState;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@twicoder And, although it probably will do the trick, the best way to make the check and avoid using the date in filter, if it is invalid, is inside reducer (the filter query params are picked up from URL during server-side rendering, thus checking it there will guarantee that invalid dates won't be used anywhere): https://github.com/topcoder-platform/community-app/blob/develop/src/shared/reducers/challenge-listing/index.js#L272

Also, once at the client-side, we should remove invalid dates from query. This can be done at this point. To update query params use this utility function: https://github.com/topcoder-platform/community-app/blob/develop/src/shared/utils/url.js#L20

if (filterState) {
if (!!filterState.startDate && CheckDateTime(filterState.startDate) === false) {
delete filterState.startDate;
}
if (!!filterState.endDate && CheckDateTime(filterState.endDate) === false) {
delete filterState.endDate;
}
}
let challenges = props.challenges;

if (props.communityFilter) {
Expand Down