Skip to content

Commit 2212ee0

Browse files
committed
Merge branch 'main' of github.com:coder13/Competitor-groups
2 parents f1bd8e3 + dc197a1 commit 2212ee0

File tree

7 files changed

+115
-69
lines changed

7 files changed

+115
-69
lines changed

src/components/AssignmentLabel/AssignmentLabel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default function AssignmentLabel({ assignmentCode }: AssignmentLabelProps
3434
return <Container className="bg-violet-200">Announcer</Container>;
3535
case 'staff-delegate':
3636
return <Container className="bg-purple-200">Delegate</Container>;
37+
case 'staff-stagelead':
38+
return <Container className="bg-purple-800">Stage Lead</Container>;
3739
default:
3840
return <Container>{assignmentCode.replace('staff-', '')}</Container>;
3941
}

src/hooks/useWCAFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default function useWCAFetch() {
66
const { accessToken } = useAuth();
77

88
return useCallback(
9-
async <T>(path, fetchOptions = {}) => {
9+
async <T>(path, fetchOptions: RequestInit = {}) => {
1010
const baseApiUrl = `${WCA_ORIGIN}`;
1111

1212
const res = await fetch(

src/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import '@cubing/icons';
33
import reportWebVitals from './reportWebVitals';
44
import App from './App';
55
import './index.css';
6-
// import * as serviceWorkerRegistration from './serviceWorkerRegistration';
76
import '@total-typescript/ts-reset';
87

98
const container = document.getElementById('root');
@@ -16,5 +15,3 @@ root.render(<App />);
1615
// to log results (for example: reportWebVitals(console.log))
1716
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
1817
reportWebVitals(undefined);
19-
20-
// serviceWorkerRegistration.register();

src/pages/Competition/Activity/EventActivity.tsx

Lines changed: 97 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Activity, AssignmentCode, EventId, Person } from '@wca/helpers';
22
import classNames from 'classnames';
3-
import { useEffect, useMemo } from 'react';
3+
import { useCallback, useEffect, useMemo } from 'react';
44
import { Link } from 'react-router-dom';
55
import tw from 'tailwind-styled-components/dist/tailwind';
66
import {
@@ -47,9 +47,11 @@ interface EventGroupProps {
4747
export default function EventGroup({ competitionId, activity, persons }: EventGroupProps) {
4848
const { setTitle, wcif } = useWCIF();
4949
const { eventId, roundNumber } = parseActivityCode(activity?.activityCode || '');
50-
const event = wcif?.events.find((e) => e.id === eventId);
51-
const prevRound =
52-
roundNumber && event?.rounds?.find((r) => r.id === `${eventId},r${roundNumber - 1}`);
50+
const event = useMemo(() => wcif?.events.find((e) => e.id === eventId), [wcif]);
51+
const prevRound = useMemo(
52+
() => roundNumber && event?.rounds?.find((r) => r.id === `${eventId}-r${roundNumber - 1}`),
53+
[event]
54+
);
5355

5456
useEffect(() => {
5557
if (activity) {
@@ -85,9 +87,7 @@ export default function EventGroup({ competitionId, activity, persons }: EventGr
8587
[persons, eventId]
8688
);
8789

88-
const competitors = everyoneInActivity
89-
.filter(isAssignment('competitor'))
90-
.sort(byWorldRanking(eventId as EventId));
90+
const competitors = everyoneInActivity.filter(isAssignment('competitor'));
9191

9292
const assignments = new Set(
9393
everyoneInActivity.map((person) => person.assignments?.map((a) => a.assignmentCode)).flat()
@@ -100,34 +100,67 @@ export default function EventGroup({ competitionId, activity, persons }: EventGr
100100
return acc;
101101
}, {}) as Record<AssignmentCode, Person[]>;
102102

103-
// TODO: Calculate seed result from previous round results when available.
104-
const seedResult = (person) => {
105-
if (prevRound) {
106-
const prevRoundResults = prevRound.results?.find((r) => r.personId === person.registrantId);
107-
if (!prevRoundResults) {
103+
const seedResult = useCallback(
104+
(person) => {
105+
if (prevRound) {
106+
const prevRoundResults = prevRound.results?.find(
107+
(r) => r.personId?.toString() === person.registrantId?.toString()
108+
);
109+
if (!prevRoundResults) {
110+
return '';
111+
}
112+
113+
if (['a' || 'm'].includes(prevRound.format)) {
114+
return renderResultByEventId(eventId, 'average', prevRoundResults.average);
115+
}
116+
117+
return renderResultByEventId(eventId, 'single', prevRoundResults.best);
118+
}
119+
120+
const averagePr = person.prAverage?.best;
121+
const singlePr = person.prSingle?.best;
122+
const shouldShowAveragePr = !isRankedBySingle(eventId);
123+
if ((shouldShowAveragePr && !averagePr) || !singlePr) {
108124
return '';
109125
}
110126

111-
if (prevRound.format === 'a' || 'm') {
112-
return renderResultByEventId(eventId, 'average', prevRoundResults.average);
127+
return renderResultByEventId(
128+
eventId,
129+
shouldShowAveragePr ? 'average' : 'single',
130+
shouldShowAveragePr ? averagePr : singlePr
131+
);
132+
},
133+
[prevRound]
134+
);
135+
136+
const seedRank = useCallback(
137+
(person) => {
138+
if (prevRound) {
139+
const prevRoundResults = prevRound.results?.find(
140+
(r) => r.personId?.toString() === person.registrantId?.toString()
141+
);
142+
if (!prevRoundResults) {
143+
return '';
144+
}
145+
146+
return prevRoundResults.ranking;
113147
}
114148

115-
return renderResultByEventId(eventId, 'single', prevRoundResults.average);
116-
}
149+
const averagePr = person.prAverage;
150+
const singlePr = person.prSingle;
151+
const shouldShowAveragePr = !isRankedBySingle(eventId);
152+
if ((shouldShowAveragePr && !averagePr) || !singlePr) {
153+
return '';
154+
}
117155

118-
const averagePr = person.prAverage?.best;
119-
const singlePr = person.prSingle?.best;
120-
const shouldShowAveragePr = !isRankedBySingle(eventId);
121-
if ((shouldShowAveragePr && !averagePr) || !singlePr) {
122-
return '';
123-
}
156+
if (averagePr) {
157+
return averagePr.worldRanking;
158+
}
124159

125-
return renderResultByEventId(
126-
eventId,
127-
shouldShowAveragePr ? 'average' : 'single',
128-
shouldShowAveragePr ? averagePr : singlePr
129-
);
130-
};
160+
return singlePr.worldRanking;
161+
},
162+
[prevRound]
163+
);
131164

132165
const stationNumber = (assignmentCode) => (person) => {
133166
const assignment = person.assignments.find(
@@ -140,21 +173,24 @@ export default function EventGroup({ competitionId, activity, persons }: EventGr
140173

141174
return (
142175
<>
143-
<div className="p-2">
144-
<h3 className="font-bold" style={{ lineHeight: 2 }}>
145-
<span
146-
className="px-3 py-2 rounded mr-2"
147-
style={{
148-
backgroundColor: `${room?.color}70`,
149-
}}>
150-
{room?.name}
151-
</span>
152-
<span>{activityCodeToName(activity?.activityCode)}</span>
153-
</h3>
154-
<p className="p-2">
155-
{formatDateTimeRange(activity.startTime, activity.endTime, 5, timeZone)}
156-
</p>
157-
</div>
176+
{wcif && (
177+
<div className="p-2">
178+
<h3 className="font-bold" style={{ lineHeight: 2 }}>
179+
<Link
180+
className="px-3 py-2 rounded mr-2"
181+
style={{
182+
backgroundColor: `${room?.color}70`,
183+
}}
184+
to={`/competitions/${wcif.id}/rooms/${room?.id}`}>
185+
{room?.name}
186+
</Link>
187+
<span>{activityCodeToName(activity?.activityCode)}</span>
188+
</h3>
189+
<p className="p-2">
190+
{formatDateTimeRange(activity.startTime, activity.endTime, 5, timeZone)}
191+
</p>
192+
</div>
193+
)}
158194
<hr className="mb-2" />
159195
<div>
160196
<AssignmentCategoryHeader className="bg-green-200 pb-1">
@@ -169,17 +205,24 @@ export default function EventGroup({ competitionId, activity, persons }: EventGr
169205
</tr>
170206
</thead>
171207
<tbody>
172-
{competitors.map((person) => (
173-
<Link
174-
className="table-row even:bg-green-50 hover:opacity-80"
175-
to={`/competitions/${competitionId}/persons/${person.registrantId}`}>
176-
<td className="py-3 px-6">{person.name}</td>
177-
<td className="py-3 px-6">{seedResult(person)}</td>
178-
{anyCompetitorHasStationNumber && (
179-
<td className="py-3 px-6">{stationNumber('competitor')(person)}</td>
180-
)}
181-
</Link>
182-
))}
208+
{competitors
209+
.map((person) => ({
210+
...person,
211+
seedResult: seedResult(person),
212+
seedRank: seedRank(person),
213+
}))
214+
.sort((a, b) => a.seedRank - b.seedRank)
215+
.map((person) => (
216+
<Link
217+
className="table-row even:bg-green-50 hover:opacity-80"
218+
to={`/competitions/${competitionId}/persons/${person.registrantId}`}>
219+
<td className="py-3 px-6">{person.name}</td>
220+
<td className="py-3 px-6">{person.seedResult}</td>
221+
{anyCompetitorHasStationNumber && (
222+
<td className="py-3 px-6">{stationNumber('competitor')(person)}</td>
223+
)}
224+
</Link>
225+
))}
183226
</tbody>
184227
</table>
185228
</div>

src/pages/Competition/Room.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useEffect, useMemo } from 'react';
2-
import { useParams } from 'react-router-dom';
2+
import { Link, useParams } from 'react-router-dom';
33
import { allChildActivities } from '../../lib/activities';
44
import { useWCIF } from './WCIFProvider';
55
import ActivityRow from '../../components/ActivitiyRow';
@@ -81,6 +81,14 @@ export default function Round() {
8181
</div>
8282
</div>
8383
))}
84+
<hr className="my-2" />
85+
<div className="flex flex-row justify-between">
86+
<Link
87+
to={`/competitions/${wcif?.id}/rooms`}
88+
className="w-full border bg-blue-200 rounded-md p-2 px-1 flex cursor-pointer hover:bg-blue-400 group transition-colors my-1 flex-row">
89+
Back to list of Rooms
90+
</Link>
91+
</div>
8492
</div>
8593
);
8694
}

src/pages/Competition/WCIFProvider.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useQuery } from '@tanstack/react-query';
88
import { GlobalStateContext } from '../../App';
99
import NoteBox from '../../components/Notebox';
1010
import { streamActivities } from './../../lib/activities';
11+
import { WCA_ORIGIN } from '../../lib/wca-env';
1112

1213
const StyledNavLink = ({ to, text }) => (
1314
<NavLink
@@ -54,8 +55,11 @@ export default function WCIFProvider({ competitionId, children }) {
5455
isFetching,
5556
} = useQuery<Competition>({
5657
queryKey: ['wcif', competitionId],
57-
queryFn: () => wcaApiFetch(`/competitions/${competitionId}/wcif/public`),
58-
networkMode: 'online',
58+
queryFn: () =>
59+
wcaApiFetch(`/competitions/${competitionId}/wcif/public`, {
60+
cache: 'no-store',
61+
}),
62+
networkMode: 'always',
5963
});
6064

6165
useEffect(() => {

src/providers/AuthProvider.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,6 @@ export default function AuthProvider({ children }) {
144144
return true;
145145
}
146146

147-
console.log(
148-
181,
149-
expirationTime,
150-
new Date(expirationTime).getTime(),
151-
Date.now(),
152-
Date.now() >= new Date(expirationTime).getTime()
153-
);
154-
155147
return Date.now() >= new Date(expirationTime).getTime();
156148
}, [user, expirationTime]);
157149

0 commit comments

Comments
 (0)