diff --git a/src/app/components/RaceResultsTable.tsx b/src/app/components/RaceResultsTable.tsx index 09da688..716729c 100644 --- a/src/app/components/RaceResultsTable.tsx +++ b/src/app/components/RaceResultsTable.tsx @@ -1,5 +1,5 @@ -import { AppData } from '@/lib/types'; -import { parsePoints, findStyleByPoints } from '@/lib/leaderboard'; +import { AppData } from "@/lib/types"; +import { parsePoints, findStyleByPoints } from "@/lib/leaderboard"; interface RaceResultsTableProps { appData: AppData; @@ -7,14 +7,29 @@ interface RaceResultsTableProps { export default function RaceResultsTable({ appData }: RaceResultsTableProps) { return ( -
- +
+
- - + + {appData.drivers.map((driver) => ( - ))} @@ -26,13 +41,15 @@ export default function RaceResultsTable({ appData }: RaceResultsTableProps) { - + {appData.drivers.map((driver, driverIndex) => { const driverInitials = driver.initials; let result = track.results[driverIndex]; // DNS fallback - if (result === undefined || result === null || result === '') { - result = 'DNS'; + if (result === undefined || result === null || result === "") { + result = "DNS"; } const pointsNum = parsePoints(result); const style = findStyleByPoints(appData, pointsNum); @@ -43,7 +60,11 @@ export default function RaceResultsTable({ appData }: RaceResultsTableProps) { }; let hasFL = false; - if (track.fastestLapInitials && track.fastestLapInitials === driverInitials) { + if ( + track.fastestLapInitials && + track.fastestLapInitials === driverInitials && + appData.flPoints.points + ) { hasFL = true; const flColor = appData.flPoints.color; if (pointsNum === 0) { @@ -62,26 +83,37 @@ export default function RaceResultsTable({ appData }: RaceResultsTableProps) { if (hasFL) { cellStyles = { ...cellStyles, - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', - flexDirection: 'row', - paddingLeft: '0.75rem', - paddingRight: '0.75rem', + display: "flex", + justifyContent: "space-between", + alignItems: "center", + flexDirection: "row", + paddingLeft: "0.75rem", + paddingRight: "0.75rem", }; } else { cellStyles = { ...cellStyles, - textAlign: 'center', + textAlign: "center", }; } return ( -
TrackFL + Track + + FL + + {driver.name} {track.name} {track.fastestLapInitials || ''} + {track.fastestLapInitials || ""} + + {hasFL ? ( <> - {result} - (+1) + + {result} + + + (+{appData.flPoints.points}) + ) : ( {result} diff --git a/src/lib/leaderboard.ts b/src/lib/leaderboard.ts index eab8fed..4e6ce95 100644 --- a/src/lib/leaderboard.ts +++ b/src/lib/leaderboard.ts @@ -1,18 +1,23 @@ -import { AppData, PointStyle, DriverStanding, RaceHistoryEntry } from './types'; +import { AppData, PointStyle, DriverStanding, RaceHistoryEntry } from "./types"; export function parsePoints(value: any): number { const num = parseInt(value, 10); return isNaN(num) ? 0 : num; } -export function findStyleByPoints(appData: AppData, points: number): PointStyle { - return appData.pointsTable.find(p => p.points === points) || { - points: 0, - label: '???', - color: '#374151', - textColor: '#e5e7eb', - priority: 99 - }; +export function findStyleByPoints( + appData: AppData, + points: number, +): PointStyle { + return ( + appData.pointsTable.find((p) => p.points === points) || { + points: 0, + label: "???", + color: "#374151", + textColor: "#e5e7eb", + priority: 99, + } + ); } export function calculateStandingsData(appData: AppData): DriverStanding[] { @@ -25,19 +30,22 @@ export function calculateStandingsData(appData: AppData): DriverStanding[] { appData.tracks.forEach((track) => { let result = track.results[driverIndex]; // DNS fallback: if result is undefined, null, or empty, treat as DNS - if (result === undefined || result === null || result === '') { - result = 'DNS'; + if (result === undefined || result === null || result === "") { + result = "DNS"; } let racePoints = parsePoints(result); - if (track.fastestLapInitials && track.fastestLapInitials === driverInitials) { - racePoints += appData.flPoints.points || 1; + if ( + track.fastestLapInitials && + track.fastestLapInitials === driverInitials + ) { + racePoints += appData.flPoints.points ?? 1; } totalPoints += racePoints; cumulativePoints += racePoints; raceHistory.push({ trackName: track.name, points: racePoints, - cumulativePoints: cumulativePoints + cumulativePoints: cumulativePoints, }); }); @@ -47,7 +55,7 @@ export function calculateStandingsData(appData: AppData): DriverStanding[] { initials: driver.initials, totalPoints: totalPoints, raceHistory: raceHistory, - originalIndex: driverIndex + originalIndex: driverIndex, }; });