diff --git a/src/bracket-single/connectors.tsx b/src/bracket-single/connectors.tsx index 48933b9..ebdcec3 100644 --- a/src/bracket-single/connectors.tsx +++ b/src/bracket-single/connectors.tsx @@ -25,26 +25,22 @@ const Connectors = ({ offsetY, }); const previousBottomPosition = (rowIndex + 1) * 2 - 1; - const previousTopMatchPosition = calculatePositionOfMatch( - previousBottomPosition - 1, - columnIndex - 1, - { + const previousTopMatchPosition = + bracketSnippet.previousTopMatch && + calculatePositionOfMatch(previousBottomPosition - 1, columnIndex - 1, { canvasPadding, rowHeight, columnWidth, offsetY, - } - ); - const previousBottomMatchPosition = calculatePositionOfMatch( - previousBottomPosition, - columnIndex - 1, - { + }); + const previousBottomMatchPosition = + bracketSnippet.previousBottomMatch && + calculatePositionOfMatch(previousBottomPosition, columnIndex - 1, { canvasPadding, rowHeight, columnWidth, offsetY, - } - ); + }); return ( { const previousMatchesColumn = matchesColumn.reduce((result, match) => { + const previousMatches = matches + .filter(m => m.nextMatchId === match.id) + .sort((a, b) => sortAlphanumerically(a.name, b.name)) + + if (previousMatches.length === 1) previousMatches.unshift(null); + if (previousMatches.length === 0) previousMatches.unshift(null, null); return [ ...result, - ...matches - .filter(m => m.nextMatchId === match.id) - .sort((a, b) => sortAlphanumerically(a.name, b.name)), + ...previousMatches, ]; }, []); - if (previousMatchesColumn.length > 0) { + if (previousMatchesColumn.length > 0 && previousMatchesColumn.every(Boolean)) { return [...generateColumn(previousMatchesColumn), previousMatchesColumn]; } - return [previousMatchesColumn]; + return [previousMatchesColumn.some(Boolean)? previousMatchesColumn : []]; }; const generate2DBracketArray = final => { return final @@ -123,7 +127,7 @@ const SingleEliminationBracket = ({ canvasPadding={canvasPadding} width={width} numOfRounds={columns.length} - tournamentRoundText={match.tournamentRoundText} + tournamentRoundText={match?.tournamentRoundText} columnIndex={columnIndex} /> )} @@ -143,7 +147,7 @@ const SingleEliminationBracket = ({ }} /> )} - + {match && - + } ); })