Skip to content

Commit 7b5d63c

Browse files
committed
Fixed bugs with rankings page
1 parent e228e6a commit 7b5d63c

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const PsychSheet = () => {
6666
const { wcif } = useWCIF();
6767

6868
useEffect(() => {
69-
if (wcif) {
69+
if (wcif && wcif.events?.length > 0) {
7070
navigate(`/competitions/${competitionId}/psych-sheet/${wcif.events[0].id}`, {
7171
replace: true,
7272
});

src/lib/sort.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import { EventId, Person } from '@wca/helpers';
22
import { findPR } from './activities';
33
import { isRankedBySingle } from './events';
44

5-
export const byWorldRanking = (eventId: EventId): ((a: Person, b: Person) => number) => {
5+
export const byWorldRanking = (
6+
eventId: EventId,
7+
resultType: 'average' | 'single' = 'average',
8+
): ((a: Person, b: Person) => number) => {
69
// const byEventRanking = byRanking(eventId);
710
const findEventPR = findPR(eventId);
811

912
return (a, b) => {
1013
if (!isRankedBySingle(eventId)) {
11-
const aPRAverage = findEventPR(a.personalBests || [], 'average');
12-
const bPRAverage = findEventPR(b.personalBests || [], 'average');
14+
const aPRAverage = findEventPR(a.personalBests || [], resultType);
15+
const bPRAverage = findEventPR(b.personalBests || [], resultType);
1316

1417
if (aPRAverage && bPRAverage) {
1518
const diff = aPRAverage.worldRanking - bPRAverage.worldRanking;
@@ -23,20 +26,24 @@ export const byWorldRanking = (eventId: EventId): ((a: Person, b: Person) => num
2326
}
2427
}
2528

26-
const aPRSingle = findEventPR(a.personalBests || [], 'single');
27-
const bPRSingle = findEventPR(b.personalBests || [], 'single');
29+
if (resultType === 'average') {
30+
const aPRSingle = findEventPR(a.personalBests || [], 'single');
31+
const bPRSingle = findEventPR(b.personalBests || [], 'single');
2832

29-
if (aPRSingle && bPRSingle) {
30-
const diff = aPRSingle.worldRanking - bPRSingle.worldRanking;
31-
if (diff !== 0) {
32-
return diff;
33+
if (aPRSingle && bPRSingle) {
34+
const diff = aPRSingle.worldRanking - bPRSingle.worldRanking;
35+
if (diff !== 0) {
36+
return diff;
37+
}
38+
} else if (aPRSingle && !bPRSingle) {
39+
return -1;
40+
} else if (!aPRSingle && bPRSingle) {
41+
return 1;
3342
}
34-
} else if (aPRSingle && !bPRSingle) {
35-
return -1;
36-
} else if (!aPRSingle && bPRSingle) {
37-
return 1;
43+
44+
return a.name.localeCompare(b.name);
3845
}
3946

40-
return a.name.localeCompare(b.name);
47+
return 0;
4148
};
4249
};

src/pages/Competition/PsychSheet/PsychSheetEvent.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const PsychSheetEvent = () => {
4646
const sortedPersons = useMemo(
4747
() =>
4848
eventId &&
49-
persons.sort(byWorldRanking(eventId)).map((person) => {
49+
persons.sort(byWorldRanking(eventId, resultType)).map((person) => {
5050
return {
5151
...person,
5252
pr: person.personalBests?.find(
@@ -132,7 +132,7 @@ export const PsychSheetEvent = () => {
132132
: rankings.length) + 1;
133133

134134
const prAverage = person.personalBests?.find(
135-
(pr) => pr.eventId === eventId && pr.type === 'average',
135+
(pr) => pr.eventId === eventId && pr.type === resultType,
136136
);
137137

138138
return (
@@ -148,7 +148,7 @@ export const PsychSheetEvent = () => {
148148
</span>
149149
<span className="px-3 py-2.5 text-left truncate">{person.name}</span>
150150
<span className="px-3 py-2.5 text-right [font-variant-numeric:tabular-nums]">
151-
{prAverage ? renderResultByEventId(eventId, 'average', prAverage.best) : ''}
151+
{prAverage ? renderResultByEventId(eventId, resultType, prAverage.best) : ''}
152152
</span>
153153
<span className="px-3 py-2.5 text-right [font-variant-numeric:tabular-nums]">
154154
{prAverage

0 commit comments

Comments
 (0)