Skip to content

fix(challenge-listing): sorting functions #4725

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
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
148 changes: 112 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 16 additions & 7 deletions src/shared/utils/challenge-listing/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,35 @@ export default {
name: 'Prize high to low',
},
[SORTS.TIME_TO_REGISTER]: {
func: (a, b) => moment(a.registrationEndDate || a.submissionEndDate)
.diff(b.registrationEndDate || b.submissionEndDate),
func: (a, b) => {
const aDate = moment(a.registrationEndDate || a.submissionEndTimestamp);
const bDate = moment(b.registrationEndDate || b.submissionEndTimestamp);

if (aDate.isBefore() && bDate.isAfter()) return 1;
if (aDate.isAfter() && bDate.isBefore()) return -1;
if (aDate.isBefore() && bDate.isBefore()) return bDate.diff(aDate);

return aDate.diff(bDate);
},
name: 'Time to register',
},
[SORTS.TIME_TO_SUBMIT]: {
func: (a, b) => {
function nextSubEndDate(o) {
if (o.checkpointSubmissionEndDate && moment(o.checkpointSubmissionEndDate).isAfter()) {
return o.checkpointSubmissionEndDate;
return moment(o.checkpointSubmissionEndDate);
}
return o.submissionEndDate;
return moment(o.submissionEndTimestamp);
}

const aDate = nextSubEndDate(a);
const bDate = nextSubEndDate(b);

if (moment(aDate).isBefore()) return 1;
if (moment(bDate).isBefore()) return -1;
if (aDate.isBefore() && bDate.isAfter()) return 1;
if (aDate.isAfter() && bDate.isBefore()) return -1;
if (aDate.isBefore() && bDate.isBefore()) return bDate.diff(aDate);

return moment(aDate).diff(bDate);
return aDate.diff(bDate);
},
name: 'Time to submit',
},
Expand Down