fix FL points defaulting to 1
All checks were successful
Deploy to Cloudflare Pages / deploy (push) Successful in 4m3s

This commit is contained in:
2026-03-01 15:07:45 +01:00
parent 8b3d8bc817
commit 3004545400
2 changed files with 76 additions and 36 deletions

View File

@@ -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 (
<div id="table-container" className="bg-gray-800/70 p-4 rounded-2xl shadow-2xl backdrop-blur-sm border border-gray-700/50 overflow-x-auto">
<table id="race-results-table" className="w-full min-w-[1200px] border-collapse text-center">
<div
id="table-container"
className="bg-gray-800/70 p-4 rounded-2xl shadow-2xl backdrop-blur-sm border border-gray-700/50 overflow-x-auto"
>
<table
id="race-results-table"
className="w-full min-w-[1200px] border-collapse text-center"
>
<thead id="race-table-head">
<tr>
<th scope="col" className="py-3 px-4 min-w-[200px]">Track</th>
<th scope="col" className="py-3 px-4 min-w-[100px]">FL</th>
<th scope="col" className="py-3 px-4 min-w-[200px]">
Track
</th>
<th scope="col" className="py-3 px-4 min-w-[100px]">
FL
</th>
{appData.drivers.map((driver) => (
<th key={driver.initials} scope="col" className="py-3 px-4 min-w-[170px]" style={{ textAlign: 'center' }}>
<th
key={driver.initials}
scope="col"
className="py-3 px-4 min-w-[170px]"
style={{ textAlign: "center" }}
>
<span>{driver.name}</span>
</th>
))}
@@ -26,13 +41,15 @@ export default function RaceResultsTable({ appData }: RaceResultsTableProps) {
<td className="font-semibold py-3 px-4 whitespace-nowrap min-w-[200px]">
<span>{track.name}</span>
</td>
<td className="py-3 px-4 font-mono min-w-[100px]">{track.fastestLapInitials || ''}</td>
<td className="py-3 px-4 font-mono min-w-[100px]">
{track.fastestLapInitials || ""}
</td>
{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 (
<td key={driverIndex} className="py-3 px-4 font-mono" style={cellStyles}>
<td
key={driverIndex}
className="py-3 px-4 font-mono"
style={cellStyles}
>
{hasFL ? (
<>
<span style={{ flexGrow: 1, textAlign: 'left' }}>{result}</span>
<span className="fl-text-only" style={{ color: appData.flPoints.textColor }}>(+1)</span>
<span style={{ flexGrow: 1, textAlign: "left" }}>
{result}
</span>
<span
className="fl-text-only"
style={{ color: appData.flPoints.textColor }}
>
(+{appData.flPoints.points})
</span>
</>
) : (
<span>{result}</span>

View File

@@ -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,
};
});