@@ -87,6 +87,29 @@ function TournamentBracketPage() {
8787 const [ tournamentStarted , setTournamentStarted ] = useState ( false ) ;
8888 const [ bracket , setBracket ] = useState ( null ) ;
8989 const [ advancedMatches , setAdvancedMatches ] = useState ( { } ) ;
90+ const [ currentRoundIndex , setCurrentRoundIndex ] = useState ( 0 ) ;
91+ const [ currentMatchIndex , setCurrentMatchIndex ] = useState ( 0 ) ;
92+
93+ useEffect ( ( ) => {
94+ if ( ! bracket ) return ;
95+
96+ let foundCurrent = false ;
97+ for ( let r = 0 ; r < bracket . length ; r ++ ) {
98+ for ( let m = 0 ; m < bracket [ r ] . length ; m ++ ) {
99+ if ( ! advancedMatches [ `${ r } -${ m } ` ] ) {
100+ setCurrentRoundIndex ( r ) ;
101+ setCurrentMatchIndex ( m ) ;
102+ foundCurrent = true ;
103+ return ;
104+ }
105+ }
106+ }
107+ if ( ! foundCurrent ) {
108+ // Tournament is complete, or no matches to advance
109+ setCurrentRoundIndex ( - 1 ) ; // Indicate no current round
110+ setCurrentMatchIndex ( - 1 ) ; // Indicate no current match
111+ }
112+ } , [ bracket , advancedMatches ] ) ;
90113
91114 const startTournament = ( ) => {
92115 setTournamentStarted ( true ) ;
@@ -194,10 +217,16 @@ function TournamentBracketPage() {
194217
195218 const newBracket = JSON . parse ( JSON . stringify ( currentBracket ) ) ;
196219 let changed = false ;
220+ let updatedAdvancedMatches = { ...advancedMatches } ; // Create a mutable copy
197221
198222 newBracket [ 0 ] . forEach ( ( match , matchIndex ) => {
199223 if ( match [ 0 ] && match [ 1 ] === null ) {
200224 const winner = match [ 0 ] ;
225+ const loser = 'Bye' ; // Explicitly define 'Bye' as the loser
226+
227+ // Update advancedMatches for this bye match
228+ updatedAdvancedMatches [ `0-${ matchIndex } ` ] = { winner, loser } ;
229+
201230 if ( 0 + 1 < newBracket . length ) {
202231 const nextRoundIndex = 0 + 1 ;
203232 const nextMatchIndex = Math . floor ( matchIndex / 2 ) ;
@@ -214,6 +243,8 @@ function TournamentBracketPage() {
214243 if ( changed ) {
215244 setBracket ( newBracket ) ;
216245 }
246+ // Only update advancedMatches once after the loop
247+ setAdvancedMatches ( updatedAdvancedMatches ) ;
217248 } ;
218249
219250 const [ compactLayout , setCompactLayout ] = useState ( false ) ;
@@ -376,10 +407,10 @@ function TournamentBracketPage() {
376407 </ div >
377408 < div className = "flex space-x-4 overflow-x-auto pb-4" >
378409 { bracket && bracket . map ( ( round , roundIndex ) => (
379- < div key = { roundIndex } className = { `flex flex-col ${ compactLayout ? 'space-y-2' : 'space-y-4' } min-w-max flex-shrink-0` } >
410+ < div key = { roundIndex } className = { `flex flex-col ${ compactLayout ? 'space-y-2' : 'space-y-4' } min-w-max flex-shrink-0 ${ roundIndex === currentRoundIndex ? 'border-2 border-yellow-400 p-2 rounded-lg' : '' } ` } >
380411 < h3 className = "text-xl font-bold" > Round { roundIndex + 1 } </ h3 >
381412 { round . map ( ( match , matchIndex ) => (
382- < div key = { matchIndex } className = { `group bg-transparent border rounded-lg shadow-2xl p-6 flex flex-col justify-between relative transform transition-all duration-300 ease-in-out overflow-hidden w-80 ${ compactLayout ? 'min-h-[100px]' : 'h-full' } ` } style = { cardStyle } >
413+ < div key = { matchIndex } className = { `group bg-transparent border rounded-lg shadow-2xl p-6 flex flex-col justify-between relative transform transition-all duration-300 ease-in-out overflow-hidden w-80 ${ compactLayout ? 'min-h-[100px]' : 'h-full' } my-2 ${ roundIndex === currentRoundIndex && matchIndex === currentMatchIndex ? 'border-2 border-yellow-400' : '' } ` } style = { cardStyle } >
383414 < div className = "flex justify-between items-center mb-2" >
384415 < div className = "flex items-center gap-2" >
385416 < input
@@ -389,11 +420,11 @@ function TournamentBracketPage() {
389420 onChange = { ( e ) => handleScoreChange ( roundIndex , matchIndex , 0 , e . target . value ) }
390421 disabled = { ! match [ 0 ] || ! match [ 1 ] }
391422 />
392- < span className = { `break-words ${ match [ 1 ] === null ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. winner === match [ 0 ] ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. loser === match [ 0 ] ? 'text-gray-500 line-through' : '' } ` } > { match [ 0 ] || 'TBD' } </ span >
423+ < span className = { `break-words ${ match [ 0 ] && ( match [ 1 ] === null ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. winner === match [ 0 ] ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. loser === match [ 0 ] ? 'text-gray-500 line-through' : '' ) } ` } > { match [ 0 ] || 'TBD' } </ span >
393424 </ div >
394425 < span > vs</ span >
395426 < div className = "flex items-center gap-2" >
396- < span className = { `break-words ${ match [ 1 ] === null ? 'text-gray-500 line-through' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. winner === match [ 1 ] ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. loser === match [ 1 ] ? 'text-gray-500 line-through' : '' } ` } > { match [ 1 ] || ( roundIndex === 0 ? 'Bye' : 'TBD' ) } </ span >
427+ < span className = { `break-words ${ match [ 1 ] && ( match [ 1 ] === null ? 'text-gray-500 line-through' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. winner === match [ 1 ] ? 'text-article font-bold' : advancedMatches [ `${ roundIndex } -${ matchIndex } ` ] ?. loser === match [ 1 ] ? 'text-gray-500 line-through' : '' ) } ` } > { match [ 1 ] || ( roundIndex === 0 ? 'Bye' : 'TBD' ) } </ span >
397428 < input
398429 type = "number"
399430 className = "bg-gray-700 text-white p-1 rounded-lg w-16"
0 commit comments