Compare commits
2 Commits
v0.22.1
...
3ba68ac973
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ba68ac973 | |||
| 67a72f9a92 |
@@ -40,13 +40,17 @@ export function LeaderboardManager({ serverId, initialData }: LeaderboardManager
|
||||
const handleDriversChange = (newDrivers: LeaderboardDriver[]) => {
|
||||
const oldDrivers = draft.drivers;
|
||||
|
||||
// Build index map: for each position in newDrivers, what was the old index?
|
||||
const indexMap = newDrivers.map((d) => oldDrivers.indexOf(d));
|
||||
// Build index map by matching drivers by initials (their stable identifier)
|
||||
// For each position in newDrivers, find where that driver was in oldDrivers
|
||||
const indexMap = newDrivers.map((d) => {
|
||||
const oldIndex = oldDrivers.findIndex((old) => old.initials === d.initials);
|
||||
return oldIndex; // -1 if new driver, otherwise the old index
|
||||
});
|
||||
|
||||
// If a driver was added (indexOf returns -1), it's new
|
||||
// If a driver was added (findIndex returns -1), it's new, start with DNS
|
||||
const newTracks = draft.tracks.map((t) => ({
|
||||
...t,
|
||||
results: indexMap.map((i) => (i === -1 ? 0 : (t.results[i] ?? 0)))
|
||||
results: indexMap.map((i) => (i === -1 ? 'DNS' : (t.results[i] ?? 'DNS')))
|
||||
}));
|
||||
|
||||
setDraft({ ...draft, drivers: newDrivers, tracks: newTracks });
|
||||
|
||||
@@ -10,20 +10,27 @@ interface ResultInputProps {
|
||||
|
||||
function ResultInput({ value, pointsTable, onChange }: ResultInputProps) {
|
||||
const knownPoints = Array.from(new Set(pointsTable.map((e) => e.points))).sort((a, b) => b - a);
|
||||
// Fallback 0 to DNS if 0 is not a valid points option
|
||||
const displayValue = value === 0 && !knownPoints.includes(0) ? 'DNS' : value;
|
||||
// Ensure the current numeric value is always included in options
|
||||
const allPoints = typeof displayValue === 'number'
|
||||
? Array.from(new Set([...knownPoints, displayValue])).sort((a, b) => b - a)
|
||||
: knownPoints;
|
||||
|
||||
const handleChange = (raw: string) => {
|
||||
if (raw === 'DNF') return onChange('DNF');
|
||||
if (raw === 'DNS') return onChange('DNS');
|
||||
onChange(parseInt(raw) || 0);
|
||||
const parsed = parseInt(raw);
|
||||
onChange(isNaN(parsed) ? 0 : parsed);
|
||||
};
|
||||
|
||||
return (
|
||||
<select
|
||||
value={String(value)}
|
||||
value={String(displayValue)}
|
||||
onChange={(e) => handleChange(e.target.value)}
|
||||
className="w-full rounded bg-gray-600 px-1 py-1 text-xs text-white"
|
||||
>
|
||||
{knownPoints.map((p) => (
|
||||
{allPoints.map((p) => (
|
||||
<option key={p} value={String(p)}>
|
||||
{p}
|
||||
</option>
|
||||
|
||||
Reference in New Issue
Block a user