Fix draft order showing only new team when league size increased before order was set
When a commissioner increased the team count on a league that had teams but no draft order set yet, the server created draft slots only for the newly-added teams. This left the DB with N+K teams but only K slots, causing the drag-and-drop list to display only the K new teams. Two fixes: 1. Server: only append new draft slots when an order was already set (existingSlots.length > 0). If no order exists yet, skip slot creation so the page correctly treats the order as unset for all teams. 2. Frontend: buildDraftOrderTeams() appends any unslotted teams after the slotted ones, so a partially-corrupt DB state still shows all teams. https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo
This commit is contained in:
parent
06d415d95c
commit
a7248c48e6
2 changed files with 24 additions and 12 deletions
|
|
@ -751,13 +751,18 @@ export async function action(args: Route.ActionArgs) {
|
||||||
.insert(schema.teams)
|
.insert(schema.teams)
|
||||||
.values(teamsToAdd)
|
.values(teamsToAdd)
|
||||||
.returning();
|
.returning();
|
||||||
await tx.insert(schema.draftSlots).values(
|
// Only append draft slots if a draft order was already set for existing teams.
|
||||||
newTeams.map((team, i) => ({
|
// When existingSlots is empty, draft order was never configured — don't create
|
||||||
seasonId: season.id,
|
// partial slots for only the new teams (that would break the order UI).
|
||||||
teamId: team.id,
|
if (existingSlots.length > 0) {
|
||||||
draftOrder: maxOrder + i + 1,
|
await tx.insert(schema.draftSlots).values(
|
||||||
}))
|
newTeams.map((team, i) => ({
|
||||||
);
|
seasonId: season.id,
|
||||||
|
teamId: team.id,
|
||||||
|
draftOrder: maxOrder + i + 1,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
await syncPrivateBracktParticipants(season.id);
|
await syncPrivateBracktParticipants(season.id);
|
||||||
} else if (newTeamCount < currentTeamCount) {
|
} else if (newTeamCount < currentTeamCount) {
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,16 @@ const UPDATE_SECTIONS: SettingsSectionId[] = [
|
||||||
"notifications",
|
"notifications",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function buildDraftOrderTeams(
|
||||||
|
slots: { teamId: string }[],
|
||||||
|
allTeams: { id: string }[]
|
||||||
|
): string[] {
|
||||||
|
if (slots.length === 0) return allTeams.map((t) => t.id);
|
||||||
|
const slottedIds = new Set(slots.map((s) => s.teamId));
|
||||||
|
const unslotted = allTeams.filter((t) => !slottedIds.has(t.id)).map((t) => t.id);
|
||||||
|
return [...slots.map((s) => s.teamId), ...unslotted];
|
||||||
|
}
|
||||||
|
|
||||||
export default function LeagueSettings({ loaderData, actionData }: Route.ComponentProps) {
|
export default function LeagueSettings({ loaderData, actionData }: Route.ComponentProps) {
|
||||||
const {
|
const {
|
||||||
league, season, teams, teamCount, teamsWithOwners, allSportsSeasons,
|
league, season, teams, teamCount, teamsWithOwners, allSportsSeasons,
|
||||||
|
|
@ -165,17 +175,14 @@ export default function LeagueSettings({ loaderData, actionData }: Route.Compone
|
||||||
|
|
||||||
// Draft order state (separate form, separate dirty flag)
|
// Draft order state (separate form, separate dirty flag)
|
||||||
const [draftOrderTeams, setDraftOrderTeams] = useState<string[]>(
|
const [draftOrderTeams, setDraftOrderTeams] = useState<string[]>(
|
||||||
draftSlots.length > 0 ? draftSlots.map((slot) => slot.teamId) : teams.map((team) => team.id)
|
() => buildDraftOrderTeams(draftSlots, teams)
|
||||||
);
|
);
|
||||||
|
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
|
|
||||||
// Sync draft order from loader after randomization or other server updates
|
// Sync draft order from loader after randomization or other server updates
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedOrder = draftSlots.length > 0
|
setDraftOrderTeams(buildDraftOrderTeams(draftSlots, teams));
|
||||||
? draftSlots.map((slot) => slot.teamId)
|
|
||||||
: teams.map((team) => team.id);
|
|
||||||
setDraftOrderTeams(savedOrder);
|
|
||||||
setHasDraftOrderChanges(false);
|
setHasDraftOrderChanges(false);
|
||||||
}, [draftSlots, teams]);
|
}, [draftSlots, teams]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue