diff --git a/frontend/src/components/Bracket/BracketView.jsx b/frontend/src/components/Bracket/BracketView.tsx similarity index 82% rename from frontend/src/components/Bracket/BracketView.jsx rename to frontend/src/components/Bracket/BracketView.tsx index 6e77f22..7463061 100644 --- a/frontend/src/components/Bracket/BracketView.jsx +++ b/frontend/src/components/Bracket/BracketView.tsx @@ -1,18 +1,24 @@ -// frontend/src/components/Bracket/BracketView.jsx +// frontend/src/components/Bracket/BracketView.tsx -import { useEffect, useRef, useState } from 'react'; -import MatchCard from "./MatchCard"; +import React, { useEffect, useRef, useState } from 'react'; +import { MatchData } from '../../types'; import Podium from "../Tournament/Podium"; +import MatchCard from "./MatchCard"; -export default function BracketView({ matches, onMatchClick }) { - const containerRef = useRef(null); - const [lines, setLines] = useState([]); +interface BracketViewProps { + matches: MatchData[]; + onMatchClick: (match: MatchData) => void; +} + +export default function BracketView({ matches, onMatchClick }: BracketViewProps) { + const containerRef = useRef(null); + const [lines, setLines] = useState([]); useEffect(() => { const draw = () => { if (!containerRef.current) return; const container = containerRef.current.getBoundingClientRect(); - const newLines = []; + const newLines: React.ReactElement[] = []; matches.forEach(m => { if (m.winner_next_match_id) { @@ -24,7 +30,7 @@ export default function BracketView({ matches, onMatchClick }) { const ex = r2.left - container.left, ey = r2.top + r2.height / 2 - container.top; const c1 = sx + (ex - sx) / 2; newLines.push( - + ); } } @@ -40,7 +46,7 @@ export default function BracketView({ matches, onMatchClick }) { const ex = r2.left - container.left, ey = r2.top + r2.height / 2 - container.top; const c1 = sx + (ex - sx) / 2; newLines.push( - + ); } } @@ -67,10 +73,12 @@ export default function BracketView({ matches, onMatchClick }) { }; }, [matches]); - const renderRound = (list) => { - const rounds = {}; + const renderRound = (list: MatchData[]) => { + const rounds: Record = {}; list.forEach(m => (rounds[m.round] = rounds[m.round] || []).push(m)); - const roundKeys = Object.keys(rounds).sort((a, b) => Number(a) - Number(b)); + + const roundKeys = Object.keys(rounds).map(Number).sort((a, b) => a - b); + return roundKeys.map((r) => { let matchesInRound = rounds[r]; matchesInRound.sort((a, b) => a.number - b.number); @@ -101,7 +109,7 @@ export default function BracketView({ matches, onMatchClick }) { } return ( -
+