From 368dc4117220eb67b6000e57aa08d2a42ea96fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20S=C3=B6derberg?= Date: Wed, 11 Mar 2026 00:17:15 +0100 Subject: [PATCH] Switched to typescript instead of javascript --- .../{BracketView.jsx => BracketView.tsx} | 43 ++++--- .../Bracket/{MatchCard.jsx => MatchCard.tsx} | 24 ++-- .../Dashboard/{DashCard.jsx => DashCard.tsx} | 20 +++- ...{TournamentForm.jsx => TournamentForm.tsx} | 59 ++++++---- .../Layout/{Layout.jsx => Layout.tsx} | 37 ++++-- .../Layout/{Navbar.jsx => Navbar.tsx} | 21 ++-- .../{ScheduleRow.jsx => ScheduleRow.tsx} | 32 +++--- .../{ScheduleView.jsx => ScheduleView.tsx} | 14 ++- .../Tournament/{Podium.jsx => Podium.tsx} | 69 ++++++----- .../{ScoreModal.jsx => ScoreModal.tsx} | 62 +++++++--- .../components/UI/{Modal.jsx => Modal.tsx} | 18 ++- .../UI/{ThemeButton.jsx => ThemeButton.tsx} | 11 +- .../pages/{Dashboard.jsx => Dashboard.tsx} | 84 +++++++++----- frontend/src/pages/{Login.jsx => Login.tsx} | 20 ++-- .../pages/{Tournament.jsx => Tournament.tsx} | 108 +++++++++++++----- frontend/src/services/api.js | 48 -------- frontend/src/services/api.ts | 71 ++++++++++++ frontend/src/types.ts | 28 +++++ frontend/src/utils/helpers.js | 19 --- frontend/src/utils/helpers.ts | 25 ++++ 20 files changed, 550 insertions(+), 263 deletions(-) rename frontend/src/components/Bracket/{BracketView.jsx => BracketView.tsx} (82%) rename frontend/src/components/Bracket/{MatchCard.jsx => MatchCard.tsx} (78%) rename frontend/src/components/Dashboard/{DashCard.jsx => DashCard.tsx} (86%) rename frontend/src/components/Forms/{TournamentForm.jsx => TournamentForm.tsx} (85%) rename frontend/src/components/Layout/{Layout.jsx => Layout.tsx} (55%) rename frontend/src/components/Layout/{Navbar.jsx => Navbar.tsx} (77%) rename frontend/src/components/Schedule/{ScheduleRow.jsx => ScheduleRow.tsx} (81%) rename frontend/src/components/Schedule/{ScheduleView.jsx => ScheduleView.tsx} (85%) rename frontend/src/components/Tournament/{Podium.jsx => Podium.tsx} (66%) rename frontend/src/components/Tournament/{ScoreModal.jsx => ScoreModal.tsx} (80%) rename frontend/src/components/UI/{Modal.jsx => Modal.tsx} (64%) rename frontend/src/components/UI/{ThemeButton.jsx => ThemeButton.tsx} (57%) rename frontend/src/pages/{Dashboard.jsx => Dashboard.tsx} (69%) rename frontend/src/pages/{Login.jsx => Login.tsx} (88%) rename frontend/src/pages/{Tournament.jsx => Tournament.tsx} (69%) delete mode 100644 frontend/src/services/api.js create mode 100644 frontend/src/services/api.ts create mode 100644 frontend/src/types.ts delete mode 100644 frontend/src/utils/helpers.js create mode 100644 frontend/src/utils/helpers.ts 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 ( -
+