Skip to content

Commit 35d006b

Browse files
committed
support breaks inside the qual schedule
1 parent f81daf1 commit 35d006b

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

shared/DbTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export type PlayoffMatch = {
6060
export type QualMatch = {
6161
number: number;
6262
participants: Record<DriverStation, number>;
63+
type: 'match'
64+
};
65+
66+
export type QualBreak = {
67+
description: string
68+
type: 'break'
6369
};
6470

6571
export type Break = {

src/components/QualDisplay/MatchDisplay/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { h, Fragment } from 'preact';
2-
import { DriverStation, QualMatch } from '@shared/DbTypes';
2+
import { DriverStation, QualBreak, QualMatch } from '@shared/DbTypes';
33
import styles from './styles.module.scss';
44

55
type MatchDisplayProps = {
6-
match: QualMatch | null;
6+
match: QualMatch | QualBreak | null;
77
// Temp disable till I figure out what to do with avatars
88
// teamAvatars: TeamAvatars | undefined;
99
halfWidth?: boolean;
@@ -43,15 +43,22 @@ function MatchDisplay({ halfWidth, match, className }: MatchDisplayProps): JSX.E
4343
Either we're in a test match or at the end of the schedule
4444
*/}
4545
{match && (
46-
<>
47-
<span className={styles.matchNumber}>{match.number}</span>
48-
<span className={styles.red}>
49-
{[1, 2, 3].map((n) => <TeamDisplay key={`${match?.number}r${n}`} team={match?.participants[`Red${n}` as DriverStation]} />)}
50-
</span>
51-
<span className={styles.blue}>
52-
{[1, 2, 3].map((n) => <TeamDisplay key={`${match?.number}b${n}`} team={match?.participants[`Blue${n}` as DriverStation]} />)}
53-
</span>
54-
</>
46+
<>
47+
{match && match.type === 'break' && (
48+
<div className={styles.break}>{match.description}</div>
49+
)}
50+
{match?.type !== 'break' && (
51+
<>
52+
<span className={styles.matchNumber}>{match.number}</span>
53+
<span className={styles.red}>
54+
{[1, 2, 3].map((n) => <TeamDisplay key={`${match?.number}r${n}`} team={match?.participants[`Red${n}` as DriverStation]} />)}
55+
</span>
56+
<span className={styles.blue}>
57+
{[1, 2, 3].map((n) => <TeamDisplay key={`${match?.number}b${n}`} team={match?.participants[`Blue${n}` as DriverStation]} />)}
58+
</span>
59+
</>
60+
)}
61+
</>
5562
)}
5663
</div>
5764
);

src/components/QualDisplay/MatchDisplay/styles.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@
5151
font-size: min(4vh, 4vw);
5252
}
5353
}
54+
55+
.break {
56+
text-align: center;
57+
grid-column: 1/-1;
58+
grid-row: 1/-1;
59+
}
5460
}

src/components/QualDisplay/Queueing/index.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
useContext, useEffect, useState, useRef, useReducer,
77
} from 'preact/hooks';
88

9-
import { AppMode, QualMatch } from '@shared/DbTypes';
9+
import { AppMode, QualBreak, QualMatch } from '@shared/DbTypes';
1010
import { TeamRanking } from '@/types';
1111
import AppContext from '@/AppContext';
1212
import styles from './styles.module.scss';
@@ -25,9 +25,9 @@ const Queueing = () => {
2525
const dbEventRef = useRef<DatabaseReference>();
2626
const [qualMatches, setQualMatches] = useState<QualMatch[]>([]);
2727
const [displayMatches, setDisplayMatches] = useState<{
28-
currentMatch: QualMatch | null,
29-
nextMatch: QualMatch | null,
30-
queueingMatches: QualMatch[]
28+
currentMatch: QualMatch | QualBreak | null,
29+
nextMatch: QualMatch | QualBreak | null,
30+
queueingMatches: QualMatch[] | QualBreak[]
3131
}>({ currentMatch: null, nextMatch: null, queueingMatches: [] });
3232
const [rankings, setRankings] = useState<TeamRanking[]>([]);
3333

@@ -46,9 +46,13 @@ const Queueing = () => {
4646
};
4747
}, [event.eventCode, season, token]);
4848

49-
const getMatchByNumber = (matchNumber: number): QualMatch | null => qualMatches?.find(
49+
const getMatchIdxByNumber = (matchNumber: number): number | null => qualMatches?.findIndex(
5050
(x) => x.number === matchNumber,
5151
) ?? null;
52+
const getMatchByIndex = (index: number | null): QualMatch | QualBreak | null => (
53+
index && qualMatches
54+
? (qualMatches[index] ?? null)
55+
: null);
5256

5357
const updateMatches = (): void => {
5458
const matchNumber = event.currentMatchNumber;
@@ -62,13 +66,23 @@ const Queueing = () => {
6266
}
6367

6468
try {
65-
setDisplayMatches({
66-
currentMatch: getMatchByNumber(matchNumber),
67-
nextMatch: getMatchByNumber(matchNumber + 1),
68-
// By default, we'll take the three matches after the one on deck
69-
queueingMatches: [2, 3, 4].map((x) => getMatchByNumber(matchNumber + x))
70-
.filter((x) => x !== null) as QualMatch[],
71-
});
69+
const currentIdx = getMatchIdxByNumber(matchNumber);
70+
if (currentIdx !== null) {
71+
setDisplayMatches({
72+
currentMatch: getMatchByIndex(currentIdx),
73+
nextMatch: getMatchByIndex(currentIdx + 1),
74+
// By default, we'll take the three matches after the one on deck
75+
queueingMatches: [2, 3, 4].map((x) => getMatchByIndex(currentIdx + x))
76+
.filter((x) => x !== null) as QualMatch[],
77+
});
78+
} else {
79+
setDisplayMatches({
80+
currentMatch: null,
81+
nextMatch: null,
82+
queueingMatches: [],
83+
});
84+
}
85+
7286
setLoadingState('ready');
7387
} catch (e) {
7488
setLoadingState('error');

0 commit comments

Comments
 (0)