diff --git a/app/routes/leagues/$leagueId.draft-queue.$seasonId.tsx b/app/routes/leagues/$leagueId.draft-queue.$seasonId.tsx index 896222f..b48f32e 100644 --- a/app/routes/leagues/$leagueId.draft-queue.$seasonId.tsx +++ b/app/routes/leagues/$leagueId.draft-queue.$seasonId.tsx @@ -64,7 +64,7 @@ export async function loader(args: Route.LoaderArgs) { type QueueItem = { id: string; participantId: string }; -export default function PreDraftRankings() { +export default function SetPreDraftQueue() { const { season, userTeam, availableParticipants, userQueue } = useLoaderData(); const { leagueId } = useParams<{ leagueId: string }>(); @@ -81,6 +81,7 @@ export default function PreDraftRankings() { const queueRef = useRef(localQueue); // Track in-flight removes to prevent add racing ahead of a pending remove const pendingRemovesRef = useRef(new Set()); + useEffect(() => { queueRef.current = localQueue; }, [localQueue]); @@ -92,7 +93,11 @@ export default function PreDraftRankings() { const handleAdd = useCallback( async (participantId: string) => { - if (queuedParticipantIds.has(participantId) || pendingRemovesRef.current.has(participantId)) return; + if (queuedParticipantIds.has(participantId)) return; + if (pendingRemovesRef.current.has(participantId)) { + toast("Player is being removed — try again in a moment"); + return; + } const tempId = `temp-${Date.now()}-${participantId}`; setLocalQueue((prev) => [...prev, { id: tempId, participantId }]); @@ -124,6 +129,10 @@ export default function PreDraftRankings() { const participantId = item?.participantId; setLocalQueue((prev) => prev.filter((q) => q.id !== queueId)); + + // Temp IDs haven't been written to the DB yet — nothing to delete server-side. + if (queueId.startsWith("temp-")) return; + if (participantId) pendingRemovesRef.current.add(participantId); const formData = new FormData(); @@ -308,7 +317,7 @@ export default function PreDraftRankings() { {/* Desktop: side-by-side */}
-
+

All Players

{allPlayersPanel} diff --git a/app/routes/leagues/__tests__/draft-queue-access.test.ts b/app/routes/leagues/__tests__/draft-queue-access.test.ts index 9cbdf5a..77c6357 100644 --- a/app/routes/leagues/__tests__/draft-queue-access.test.ts +++ b/app/routes/leagues/__tests__/draft-queue-access.test.ts @@ -71,7 +71,7 @@ function checkPreDraftRankingsAccess(opts: { // Redirect behaviour based on season status // --------------------------------------------------------------------------- -describe('Pre-Draft Rankings Access - Season Status Redirects', () => { +describe('Set Pre-Draft Queue Access - Season Status Redirects', () => { it('redirects to the draft room when status is draft', () => { const season = createMockSeason({ status: 'draft' }); const result = checkPreDraftRankingsAccess({ @@ -121,7 +121,7 @@ describe('Pre-Draft Rankings Access - Season Status Redirects', () => { // Authentication // --------------------------------------------------------------------------- -describe('Pre-Draft Rankings Access - Authentication', () => { +describe('Set Pre-Draft Queue Access - Authentication', () => { it('returns 401 when no user is logged in', () => { const season = createMockSeason({ status: 'pre_draft' }); const result = checkPreDraftRankingsAccess({ @@ -149,7 +149,7 @@ describe('Pre-Draft Rankings Access - Authentication', () => { // Team membership // --------------------------------------------------------------------------- -describe('Pre-Draft Rankings Access - Team Membership', () => { +describe('Set Pre-Draft Queue Access - Team Membership', () => { it('returns 403 for a logged-in user with no team in the season', () => { const season = createMockSeason({ status: 'pre_draft' }); const result = checkPreDraftRankingsAccess({ @@ -188,7 +188,7 @@ describe('Pre-Draft Rankings Access - Team Membership', () => { // Redirect targets use the correct leagueId and seasonId // --------------------------------------------------------------------------- -describe('Pre-Draft Rankings Access - Redirect URL Correctness', () => { +describe('Set Pre-Draft Queue Access - Redirect URL Correctness', () => { it('uses the leagueId from params in the redirect URL', () => { const season = createMockSeason({ id: 'season-99', status: 'draft' }); const result = checkPreDraftRankingsAccess({