Skip to content

Commit e747377

Browse files
committed
Fix some type errors
1 parent 19fe27c commit e747377

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/components/QualDisplay/Queueing/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Queueing = () => {
2323

2424
const [loadingState, setLoadingState] = useState<LoadingState>('loading');
2525
const dbEventRef = useRef<DatabaseReference>();
26-
const [qualMatches, setQualMatches] = useState<QualMatch[]>([]);
26+
const [qualMatches, setQualMatches] = useState<(QualMatch | QualBreak)[]>([]);
2727
const [displayMatches, setDisplayMatches] = useState<{
2828
currentMatch: QualMatch | QualBreak | null,
2929
nextMatch: QualMatch | QualBreak | null,
@@ -38,19 +38,26 @@ const Queueing = () => {
3838

3939
const matchesRef = ref(getDatabase(), `/seasons/${season}/qual/${token}`);
4040
onValue(matchesRef, (snap) => {
41-
setQualMatches(snap.val() as QualMatch[]);
41+
setQualMatches([...snap.val() as (QualMatch | QualBreak)[], { type: 'break', description: '(END)' }]);
4242
});
4343

4444
return () => {
4545
off(matchesRef);
4646
};
4747
}, [event.eventCode, season, token]);
4848

49-
const getMatchIdxByNumber = (matchNumber: number): number | null => qualMatches?.findIndex(
50-
(x) => x.number === matchNumber,
51-
) ?? null;
49+
const getMatchIdxByNumber = (matchNumber: number): number | null => {
50+
const res = qualMatches?.findIndex(
51+
(x) => x.type !== 'break' && x.number === matchNumber,
52+
) ?? null;
53+
54+
if (res === null || res === -1) return null;
55+
56+
return res;
57+
};
58+
5259
const getMatchByIndex = (index: number | null): QualMatch | QualBreak | null => (
53-
index && qualMatches
60+
index !== null && qualMatches
5461
? (qualMatches[index] ?? null)
5562
: null);
5663

0 commit comments

Comments
 (0)