Skip to content

Commit 52f7a01

Browse files
authored
Merge pull request #4737 from cagdas001/integration-v5-challenge-api
fix(challenge-listing): sorting functions
2 parents 1bf042d + 490c00b commit 52f7a01

File tree

1 file changed

+17
-4
lines changed
  • src/shared/utils/challenge-listing

1 file changed

+17
-4
lines changed

src/shared/utils/challenge-listing/sort.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import moment from 'moment';
6-
import { sumBy } from 'lodash';
6+
import { find, sumBy } from 'lodash';
77

88
export const SORTS = {
99
CURRENT_PHASE: 'current-phase',
@@ -25,7 +25,15 @@ export default {
2525
name: 'Current phase',
2626
},
2727
[SORTS.MOST_RECENT]: {
28-
func: (a, b) => moment(b.registrationStartDate).diff(a.registrationStartDate),
28+
func: (a, b) => {
29+
const getRegistrationStartDate = (challenge) => {
30+
const registrationPhase = find(challenge.phases, p => p.name === 'Registration');
31+
return registrationPhase.actualStartDate || registrationPhase.scheduledStartDate;
32+
};
33+
const aRegistrationStartDate = getRegistrationStartDate(a);
34+
const bRegistrationStartDate = getRegistrationStartDate(b);
35+
return moment(bRegistrationStartDate).diff(aRegistrationStartDate);
36+
},
2937
name: 'Most recent',
3038
},
3139
[SORTS.NUM_REGISTRANTS]: {
@@ -42,8 +50,13 @@ export default {
4250
},
4351
[SORTS.TIME_TO_REGISTER]: {
4452
func: (a, b) => {
45-
const aDate = moment(a.registrationEndDate || a.submissionEndTimestamp);
46-
const bDate = moment(b.registrationEndDate || b.submissionEndTimestamp);
53+
const getRegistrationEndDate = (challenge) => {
54+
const registrationPhase = find(challenge.phases, p => p.name === 'Registration');
55+
return registrationPhase.actualEndDate || registrationPhase.scheduledEndDate;
56+
};
57+
58+
const aDate = moment(getRegistrationEndDate(a) || a.submissionEndTimestamp);
59+
const bDate = moment(getRegistrationEndDate(b) || b.submissionEndTimestamp);
4760

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

0 commit comments

Comments
 (0)