brackt/app/routes/leagues
Chris Parsons 0ba2b391f8
Fix draft order initialization for teams added mid-season (#449)
* 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

* Address code review feedback on draft order bug fix

- Move buildDraftOrderTeams to app/lib/draft-order.ts so it is importable
  and testable; remove the local copy from the settings component
- Add unit tests for buildDraftOrderTeams covering the empty, full, and
  partial-slot cases
- Tighten the draft slot guard from existingSlots.length > 0 to
  existingSlots.length === currentTeamCount so partial legacy states are
  treated the same as "order not set"
- Condense the 3-line server comment to a single line per project style
- Rename getNumTeamsInSeason → getNumDraftSlotsBySeasonId to reflect what
  the function actually counts, and update its one call site
- Add tests for the server-side slot-creation guard logic

https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo

* Fix lint: move shouldAppendDraftSlots to outer scope

oxlint (consistent-function-scoping) requires functions that don't close
over any variables to be defined at the outer scope rather than inside a
describe block.

https://claude.ai/code/session_01M3H55gnMxRztJK9KMXqqZo

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-05-19 18:22:47 -07:00
..
__tests__ Fix draft order initialization for teams added mid-season (#449) 2026-05-19 18:22:47 -07:00
$leagueId.audit-log.tsx Migrate auth from Clerk to BetterAuth (#354) 2026-04-29 10:03:50 -07:00
$leagueId.draft-board.$seasonId.tsx Fix mobile spacing for draft board and dashboard layout (#13, #329) (#404) 2026-05-10 19:51:34 -07:00
$leagueId.draft-queue.$seasonId.tsx Rename queue page to Set Pre-Draft Queue, remove VORP, fix re-add race condition (#436) 2026-05-15 18:47:36 -07:00
$leagueId.draft.$seasonId.tsx fix: resolve all 48 WCAG 2.2 AA accessibility issues (#439) 2026-05-17 20:11:38 -07:00
$leagueId.server.ts Improve draft info panel formatting (#428) 2026-05-14 23:42:04 -07:00
$leagueId.settings.server.ts Fix draft order initialization for teams added mid-season (#449) 2026-05-19 18:22:47 -07:00
$leagueId.settings.tsx Fix draft order initialization for teams added mid-season (#449) 2026-05-19 18:22:47 -07:00
$leagueId.sports-seasons.$sportsSeasonId.server.ts Canonical tournament layer: schema + backfill (1/2) (#365) 2026-05-01 20:13:18 -07:00
$leagueId.sports-seasons.$sportsSeasonId.tsx Add MLS standings sync and fix simulator conference resolution (#423) 2026-05-14 15:39:40 -07:00
$leagueId.standings.$seasonId.teams.$teamId.tsx Fix draft order initialization for teams added mid-season (#449) 2026-05-19 18:22:47 -07:00
$leagueId.standings.$seasonId.tsx Fix standings page team icons to use selected team avatar (#388) 2026-05-06 18:08:46 -07:00
$leagueId.tsx Add auto-start draft at scheduled time (#437) (#438) 2026-05-16 23:37:29 -07:00
$leagueId.upcoming-events.tsx Migrate authentication from Clerk to BetterAuth (#324) 2026-04-24 22:00:49 -07:00
creating.tsx Extract reusable league wizard components; wire settings page (#350) 2026-04-28 22:24:13 -07:00
new.tsx Add auto-start draft at scheduled time (#437) (#438) 2026-05-16 23:37:29 -07:00