Skip to content

Commit 436f070

Browse files
authored
Merge pull request #4772 from cagdas001/fix-4129
fix(challenge-listing): `CURRENT_PHASE` sorting
2 parents ea06b4b + 15a5023 commit 436f070

File tree

1 file changed

+27
-1
lines changed
  • src/shared/utils/challenge-listing

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ export const SORTS = {
2121

2222
export default {
2323
[SORTS.CURRENT_PHASE]: {
24-
func: (a, b) => a.status.localeCompare(b.status),
24+
func: (a, b) => {
25+
const aPhases = a.phases || [];
26+
const bPhases = b.phases || [];
27+
const aPhase = aPhases
28+
.filter(p => p.name !== 'Registration' && p.isOpen)
29+
.sort((p1, p2) => moment(p1.scheduledEndDate).diff(p2.scheduledEndDate))[0];
30+
const bPhase = bPhases
31+
.filter(p => p.name !== 'Registration' && p.isOpen)
32+
.sort((p1, p2) => moment(p1.scheduledEndDate).diff(p2.scheduledEndDate))[0];
33+
34+
let aPhaseName = 'Stalled';
35+
let bPhaseName = 'Stalled';
36+
if (!aPhase && a.type === 'First2Finish' && aPhases.length) {
37+
aPhaseName = 'Submission';
38+
}
39+
if (!bPhase && b.type === 'First2Finish' && bPhases.length) {
40+
bPhaseName = 'Submission';
41+
}
42+
43+
if (aPhase) aPhaseName = aPhase.name;
44+
else if (a.status === 'Draft') aPhaseName = 'Draft';
45+
46+
if (bPhase) bPhaseName = bPhase.name;
47+
else if (b.status === 'Draft') bPhaseName = 'Draft';
48+
49+
return aPhaseName.localeCompare(bPhaseName);
50+
},
2551
name: 'Current phase',
2652
},
2753
[SORTS.MOST_RECENT]: {

0 commit comments

Comments
 (0)