@@ -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