2025-10-18 14:55:26 -07:00
|
|
|
import { getAuth } from "@clerk/react-router/server";
|
|
|
|
|
import { database } from "~/database/context";
|
|
|
|
|
import * as schema from "~/database/schema";
|
|
|
|
|
import { eq, and } from "drizzle-orm";
|
2025-10-24 21:12:07 -07:00
|
|
|
import { calculateDraftEligibility } from "~/lib/draft-eligibility";
|
|
|
|
|
import { getDraftPicksWithSports, getTeamDraftPicksWithSports } from "~/models/draft-pick";
|
|
|
|
|
import { getParticipantsForSeasonWithSports } from "~/models/participant";
|
|
|
|
|
import { getSeasonSportsSimple } from "~/models/season-sport";
|
Improve draft room UX with better error handling and UI refinements (#17)
* Remove pause/resume controls when draft is complete, rename Live to Connected
- Hide Pause/Resume Draft buttons when isDraftComplete is true
- Change 'Live' status indicator to 'Connected' in both draft room and draft board views
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
* Fix code review issues in draft room: security, bugs, and quality
Security:
- Fix inconsistent commissioner check: draft.start, force-autopick, force-manual-pick,
and make-pick all now query the commissioners table instead of league.createdBy,
so co-commissioners have consistent access to all draft controls
Bugs:
- canPick now includes !isPaused so the UI correctly blocks picks during a pause
- isDraftComplete initial state now covers 'completed' season status, not just 'active'
- Guard JSON.parse in queue.reorder.ts with try/catch to return 400 instead of 500
Code quality:
- Add error handling (try/catch + toast) to handlePauseDraft, handleResumeDraft,
handleRemoveFromQueue, and handleReorderQueue
- Replace alert() with toast.error() in handleMakePick, handleForceAutopick,
handleForceManualPick for consistent UX
- Memoize filteredParticipants with useMemo to avoid recomputing on every render
- Replace custom force-pick dialog div with ShadCN Dialog component for proper
keyboard support (Escape to close, focus trap, accessible markup); add dialog.tsx
- Remove console.log debug statements from socket event handlers and API routes
- Replace (global as any).__socketIO with getSocketIO() across all API routes
- Replace window.location.reload() in handleStartDraft with useRevalidator
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 21:50:27 -08:00
|
|
|
import { getSocketIO } from "../../../server/socket";
|
2025-10-18 14:55:26 -07:00
|
|
|
|
|
|
|
|
export async function action(args: any) {
|
|
|
|
|
const { request } = args;
|
|
|
|
|
const auth = await getAuth(args);
|
|
|
|
|
const userId = (auth as any).userId as string | null;
|
|
|
|
|
|
|
|
|
|
if (!userId) {
|
|
|
|
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formData = await request.formData();
|
|
|
|
|
const seasonId = formData.get("seasonId") as string;
|
|
|
|
|
const participantId = formData.get("participantId") as string;
|
|
|
|
|
|
|
|
|
|
if (!seasonId || !participantId) {
|
|
|
|
|
return Response.json({ error: "Missing required fields" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const db = database();
|
|
|
|
|
|
|
|
|
|
// Get season details
|
|
|
|
|
const season = await db.query.seasons.findFirst({
|
|
|
|
|
where: eq(schema.seasons.id, seasonId),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!season) {
|
|
|
|
|
return Response.json({ error: "Season not found" }, { status: 404 });
|
|
|
|
|
}
|
|
|
|
|
|
Add draft clock UI, Fischer increment timer logic, and security fixes (#19)
- Add prominent clock badge to tab bar (lights up on your turn) with
correct Fischer increment chess-clock model: bank starts at initialTime,
+= incrementTime after each pick, other teams' banks untouched
- Extract pure timer helpers to app/lib/draft-timer.ts and add 29 unit
tests covering formatClockTime, calculateTimeAfterPick, getTimerColorClass,
and full snake-draft lifecycle regression scenarios
- Fix make-pick.ts: add status !== 'draft' and draftPaused server guards
- Fix draft-utils.ts: replace (global as any).__socketIO with getSocketIO(),
fix timeUsed to store actual timeRemaining at pick moment (not always 120),
add null timer warning, move timer fetch before pick insert
- Fix draft.start.ts: batch timer inserts, guard against empty draftSlots
- Fix DraftGridSection: memoize currentTeamId, widen teamTimers type to
Record<string, number | undefined>
- Fix duplicate animate-pulse (getTimerColorClass already includes it)
- Clamp negative seconds in formatClockTime to guard against timer drift
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 16:51:12 -08:00
|
|
|
if (season.status !== "draft") {
|
|
|
|
|
return Response.json({ error: "Draft is not currently active" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (season.draftPaused) {
|
|
|
|
|
return Response.json({ error: "Draft is currently paused" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 14:55:26 -07:00
|
|
|
// Get current draft slot (who should be picking now)
|
|
|
|
|
const currentPickNumber = season.currentPickNumber || 1;
|
|
|
|
|
const draftSlots = await db.query.draftSlots.findMany({
|
|
|
|
|
where: eq(schema.draftSlots.seasonId, seasonId),
|
|
|
|
|
orderBy: schema.draftSlots.draftOrder,
|
|
|
|
|
with: {
|
|
|
|
|
team: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const totalTeams = draftSlots.length;
|
|
|
|
|
const currentRound = Math.ceil(currentPickNumber / totalTeams);
|
|
|
|
|
const isSnakeDraft = true; // Assuming snake draft
|
|
|
|
|
const isEvenRound = currentRound % 2 === 0;
|
|
|
|
|
|
|
|
|
|
// Calculate which team should pick
|
|
|
|
|
let pickInRound = ((currentPickNumber - 1) % totalTeams) + 1;
|
|
|
|
|
if (isSnakeDraft && isEvenRound) {
|
|
|
|
|
pickInRound = totalTeams - pickInRound + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const currentDraftSlot = draftSlots.find((slot) => slot.draftOrder === pickInRound);
|
|
|
|
|
|
|
|
|
|
if (!currentDraftSlot) {
|
|
|
|
|
return Response.json({ error: "Invalid draft state" }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check permissions: must be team owner or commissioner
|
|
|
|
|
const isTeamOwner = currentDraftSlot.team.ownerId === userId;
|
Improve draft room UX with better error handling and UI refinements (#17)
* Remove pause/resume controls when draft is complete, rename Live to Connected
- Hide Pause/Resume Draft buttons when isDraftComplete is true
- Change 'Live' status indicator to 'Connected' in both draft room and draft board views
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
* Fix code review issues in draft room: security, bugs, and quality
Security:
- Fix inconsistent commissioner check: draft.start, force-autopick, force-manual-pick,
and make-pick all now query the commissioners table instead of league.createdBy,
so co-commissioners have consistent access to all draft controls
Bugs:
- canPick now includes !isPaused so the UI correctly blocks picks during a pause
- isDraftComplete initial state now covers 'completed' season status, not just 'active'
- Guard JSON.parse in queue.reorder.ts with try/catch to return 400 instead of 500
Code quality:
- Add error handling (try/catch + toast) to handlePauseDraft, handleResumeDraft,
handleRemoveFromQueue, and handleReorderQueue
- Replace alert() with toast.error() in handleMakePick, handleForceAutopick,
handleForceManualPick for consistent UX
- Memoize filteredParticipants with useMemo to avoid recomputing on every render
- Replace custom force-pick dialog div with ShadCN Dialog component for proper
keyboard support (Escape to close, focus trap, accessible markup); add dialog.tsx
- Remove console.log debug statements from socket event handlers and API routes
- Replace (global as any).__socketIO with getSocketIO() across all API routes
- Replace window.location.reload() in handleStartDraft with useRevalidator
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 21:50:27 -08:00
|
|
|
const commissionerRecord = await db.query.commissioners.findFirst({
|
|
|
|
|
where: and(
|
|
|
|
|
eq(schema.commissioners.leagueId, season.leagueId),
|
|
|
|
|
eq(schema.commissioners.userId, userId)
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
const isCommissioner = !!commissionerRecord;
|
2025-10-18 14:55:26 -07:00
|
|
|
|
|
|
|
|
if (!isTeamOwner && !isCommissioner) {
|
|
|
|
|
return Response.json({ error: "Not your turn to pick" }, { status: 403 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if participant is already drafted
|
|
|
|
|
const existingPick = await db.query.draftPicks.findFirst({
|
|
|
|
|
where: and(
|
|
|
|
|
eq(schema.draftPicks.seasonId, seasonId),
|
|
|
|
|
eq(schema.draftPicks.participantId, participantId)
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (existingPick) {
|
|
|
|
|
return Response.json({ error: "Participant already drafted" }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get participant details
|
|
|
|
|
const participant = await db.query.participants.findFirst({
|
|
|
|
|
where: eq(schema.participants.id, participantId),
|
|
|
|
|
with: {
|
|
|
|
|
sportsSeason: {
|
|
|
|
|
with: {
|
|
|
|
|
sport: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!participant) {
|
|
|
|
|
return Response.json({ error: "Participant not found" }, { status: 404 });
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-24 21:12:07 -07:00
|
|
|
// ELIGIBILITY VALIDATION: Check if team can draft from this sport
|
|
|
|
|
const allPicks = await getDraftPicksWithSports(seasonId);
|
|
|
|
|
const teamPicks = await getTeamDraftPicksWithSports(currentDraftSlot.teamId, seasonId);
|
|
|
|
|
const allParticipants = await getParticipantsForSeasonWithSports(seasonId);
|
|
|
|
|
const seasonSports = await getSeasonSportsSimple(seasonId);
|
|
|
|
|
|
|
|
|
|
// Get all teams for the season
|
|
|
|
|
const allTeams = draftSlots.map((slot) => ({ id: slot.teamId }));
|
|
|
|
|
|
|
|
|
|
const eligibility = calculateDraftEligibility(
|
|
|
|
|
currentDraftSlot.teamId,
|
|
|
|
|
teamPicks,
|
|
|
|
|
allPicks,
|
|
|
|
|
allParticipants,
|
|
|
|
|
seasonSports,
|
|
|
|
|
season.draftRounds,
|
|
|
|
|
allTeams
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const sportId = participant.sportsSeason.sport.id;
|
|
|
|
|
if (!eligibility.eligibleSportIds.has(sportId)) {
|
|
|
|
|
const reason = eligibility.ineligibleReasons[sportId] || "Cannot draft from this sport";
|
|
|
|
|
return Response.json({ error: reason }, { status: 400 });
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-18 14:55:26 -07:00
|
|
|
// Create the draft pick
|
|
|
|
|
const [draftPick] = await db
|
|
|
|
|
.insert(schema.draftPicks)
|
|
|
|
|
.values({
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId: currentDraftSlot.teamId,
|
|
|
|
|
participantId,
|
|
|
|
|
pickNumber: currentPickNumber,
|
|
|
|
|
round: currentRound,
|
|
|
|
|
pickInRound,
|
|
|
|
|
pickedByUserId: userId,
|
|
|
|
|
pickedByType: isTeamOwner ? "owner" : "commissioner",
|
|
|
|
|
})
|
|
|
|
|
.returning();
|
|
|
|
|
|
2025-10-18 23:13:04 -07:00
|
|
|
// Remove from ALL team queues in this season (participant is now drafted)
|
|
|
|
|
await db
|
|
|
|
|
.delete(schema.draftQueue)
|
|
|
|
|
.where(
|
|
|
|
|
and(
|
|
|
|
|
eq(schema.draftQueue.seasonId, seasonId),
|
|
|
|
|
eq(schema.draftQueue.participantId, participantId)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2025-10-24 21:46:55 -07:00
|
|
|
// Notify all clients that this participant was removed from queues
|
|
|
|
|
try {
|
Improve draft room UX with better error handling and UI refinements (#17)
* Remove pause/resume controls when draft is complete, rename Live to Connected
- Hide Pause/Resume Draft buttons when isDraftComplete is true
- Change 'Live' status indicator to 'Connected' in both draft room and draft board views
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
* Fix code review issues in draft room: security, bugs, and quality
Security:
- Fix inconsistent commissioner check: draft.start, force-autopick, force-manual-pick,
and make-pick all now query the commissioners table instead of league.createdBy,
so co-commissioners have consistent access to all draft controls
Bugs:
- canPick now includes !isPaused so the UI correctly blocks picks during a pause
- isDraftComplete initial state now covers 'completed' season status, not just 'active'
- Guard JSON.parse in queue.reorder.ts with try/catch to return 400 instead of 500
Code quality:
- Add error handling (try/catch + toast) to handlePauseDraft, handleResumeDraft,
handleRemoveFromQueue, and handleReorderQueue
- Replace alert() with toast.error() in handleMakePick, handleForceAutopick,
handleForceManualPick for consistent UX
- Memoize filteredParticipants with useMemo to avoid recomputing on every render
- Replace custom force-pick dialog div with ShadCN Dialog component for proper
keyboard support (Escape to close, focus trap, accessible markup); add dialog.tsx
- Remove console.log debug statements from socket event handlers and API routes
- Replace (global as any).__socketIO with getSocketIO() across all API routes
- Replace window.location.reload() in handleStartDraft with useRevalidator
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 21:50:27 -08:00
|
|
|
getSocketIO().to(`draft-${seasonId}`).emit("participant-removed-from-queues", {
|
2025-10-24 21:46:55 -07:00
|
|
|
participantId,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Socket.IO participant-removed-from-queues error:", error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 22:11:10 -07:00
|
|
|
// Calculate next pick info (before updating season)
|
|
|
|
|
const nextPickNumber = currentPickNumber + 1;
|
|
|
|
|
const totalPicks = totalTeams * season.draftRounds;
|
|
|
|
|
const isDraftComplete = nextPickNumber > totalPicks;
|
|
|
|
|
|
Add draft clock UI, Fischer increment timer logic, and security fixes (#19)
- Add prominent clock badge to tab bar (lights up on your turn) with
correct Fischer increment chess-clock model: bank starts at initialTime,
+= incrementTime after each pick, other teams' banks untouched
- Extract pure timer helpers to app/lib/draft-timer.ts and add 29 unit
tests covering formatClockTime, calculateTimeAfterPick, getTimerColorClass,
and full snake-draft lifecycle regression scenarios
- Fix make-pick.ts: add status !== 'draft' and draftPaused server guards
- Fix draft-utils.ts: replace (global as any).__socketIO with getSocketIO(),
fix timeUsed to store actual timeRemaining at pick moment (not always 120),
add null timer warning, move timer fetch before pick insert
- Fix draft.start.ts: batch timer inserts, guard against empty draftSlots
- Fix DraftGridSection: memoize currentTeamId, widen teamTimers type to
Record<string, number | undefined>
- Fix duplicate animate-pulse (getTimerColorClass already includes it)
- Clamp negative seconds in formatClockTime to guard against timer drift
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 16:51:12 -08:00
|
|
|
// Add increment to the team that just picked (post-pick reward)
|
|
|
|
|
const incrementTime = season.draftIncrementTime || 30;
|
2025-10-18 23:13:04 -07:00
|
|
|
const currentTimer = await db.query.draftTimers.findFirst({
|
|
|
|
|
where: and(
|
|
|
|
|
eq(schema.draftTimers.seasonId, seasonId),
|
|
|
|
|
eq(schema.draftTimers.teamId, currentDraftSlot.teamId)
|
|
|
|
|
),
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-22 17:27:16 -08:00
|
|
|
const newTimeRemaining = (currentTimer?.timeRemaining ?? 0) + incrementTime;
|
|
|
|
|
if (currentTimer) {
|
2025-10-18 23:13:04 -07:00
|
|
|
await db
|
|
|
|
|
.update(schema.draftTimers)
|
Add draft clock UI, Fischer increment timer logic, and security fixes (#19)
- Add prominent clock badge to tab bar (lights up on your turn) with
correct Fischer increment chess-clock model: bank starts at initialTime,
+= incrementTime after each pick, other teams' banks untouched
- Extract pure timer helpers to app/lib/draft-timer.ts and add 29 unit
tests covering formatClockTime, calculateTimeAfterPick, getTimerColorClass,
and full snake-draft lifecycle regression scenarios
- Fix make-pick.ts: add status !== 'draft' and draftPaused server guards
- Fix draft-utils.ts: replace (global as any).__socketIO with getSocketIO(),
fix timeUsed to store actual timeRemaining at pick moment (not always 120),
add null timer warning, move timer fetch before pick insert
- Fix draft.start.ts: batch timer inserts, guard against empty draftSlots
- Fix DraftGridSection: memoize currentTeamId, widen teamTimers type to
Record<string, number | undefined>
- Fix duplicate animate-pulse (getTimerColorClass already includes it)
- Clamp negative seconds in formatClockTime to guard against timer drift
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 16:51:12 -08:00
|
|
|
.set({ timeRemaining: newTimeRemaining, updatedAt: new Date() })
|
2025-10-18 23:13:04 -07:00
|
|
|
.where(eq(schema.draftTimers.id, currentTimer.id));
|
2026-02-22 17:27:16 -08:00
|
|
|
} else {
|
|
|
|
|
await db.insert(schema.draftTimers).values({
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId: currentDraftSlot.teamId,
|
|
|
|
|
timeRemaining: newTimeRemaining,
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-10-18 23:13:04 -07:00
|
|
|
|
2026-02-22 17:27:16 -08:00
|
|
|
try {
|
|
|
|
|
getSocketIO().to(`draft-${seasonId}`).emit("timer-update", {
|
|
|
|
|
seasonId,
|
|
|
|
|
teamId: currentDraftSlot.teamId,
|
|
|
|
|
timeRemaining: newTimeRemaining,
|
|
|
|
|
currentPickNumber,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Socket.IO timer-update error:", error);
|
2025-10-18 23:13:04 -07:00
|
|
|
}
|
|
|
|
|
|
Add draft clock UI, Fischer increment timer logic, and security fixes (#19)
- Add prominent clock badge to tab bar (lights up on your turn) with
correct Fischer increment chess-clock model: bank starts at initialTime,
+= incrementTime after each pick, other teams' banks untouched
- Extract pure timer helpers to app/lib/draft-timer.ts and add 29 unit
tests covering formatClockTime, calculateTimeAfterPick, getTimerColorClass,
and full snake-draft lifecycle regression scenarios
- Fix make-pick.ts: add status !== 'draft' and draftPaused server guards
- Fix draft-utils.ts: replace (global as any).__socketIO with getSocketIO(),
fix timeUsed to store actual timeRemaining at pick moment (not always 120),
add null timer warning, move timer fetch before pick insert
- Fix draft.start.ts: batch timer inserts, guard against empty draftSlots
- Fix DraftGridSection: memoize currentTeamId, widen teamTimers type to
Record<string, number | undefined>
- Fix duplicate animate-pulse (getTimerColorClass already includes it)
- Clamp negative seconds in formatClockTime to guard against timer drift
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-21 16:51:12 -08:00
|
|
|
// Next team's timer is unchanged — their bank carries forward as-is
|
|
|
|
|
// (no emit needed; the timer system will start decrementing their existing bank)
|
2025-10-25 22:11:10 -07:00
|
|
|
|
|
|
|
|
// Update season's current pick number (AFTER initializing next timer to prevent race condition)
|
2025-10-18 14:55:26 -07:00
|
|
|
await db
|
|
|
|
|
.update(schema.seasons)
|
|
|
|
|
.set({
|
|
|
|
|
currentPickNumber: isDraftComplete ? currentPickNumber : nextPickNumber,
|
|
|
|
|
status: isDraftComplete ? "active" : season.status,
|
|
|
|
|
})
|
|
|
|
|
.where(eq(schema.seasons.id, seasonId));
|
|
|
|
|
|
|
|
|
|
// Emit socket event
|
|
|
|
|
try {
|
Improve draft room UX with better error handling and UI refinements (#17)
* Remove pause/resume controls when draft is complete, rename Live to Connected
- Hide Pause/Resume Draft buttons when isDraftComplete is true
- Change 'Live' status indicator to 'Connected' in both draft room and draft board views
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
* Fix code review issues in draft room: security, bugs, and quality
Security:
- Fix inconsistent commissioner check: draft.start, force-autopick, force-manual-pick,
and make-pick all now query the commissioners table instead of league.createdBy,
so co-commissioners have consistent access to all draft controls
Bugs:
- canPick now includes !isPaused so the UI correctly blocks picks during a pause
- isDraftComplete initial state now covers 'completed' season status, not just 'active'
- Guard JSON.parse in queue.reorder.ts with try/catch to return 400 instead of 500
Code quality:
- Add error handling (try/catch + toast) to handlePauseDraft, handleResumeDraft,
handleRemoveFromQueue, and handleReorderQueue
- Replace alert() with toast.error() in handleMakePick, handleForceAutopick,
handleForceManualPick for consistent UX
- Memoize filteredParticipants with useMemo to avoid recomputing on every render
- Replace custom force-pick dialog div with ShadCN Dialog component for proper
keyboard support (Escape to close, focus trap, accessible markup); add dialog.tsx
- Remove console.log debug statements from socket event handlers and API routes
- Replace (global as any).__socketIO with getSocketIO() across all API routes
- Replace window.location.reload() in handleStartDraft with useRevalidator
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 21:50:27 -08:00
|
|
|
getSocketIO().to(`draft-${seasonId}`).emit("pick-made", {
|
2025-10-18 14:55:26 -07:00
|
|
|
pick: {
|
|
|
|
|
...draftPick,
|
|
|
|
|
team: currentDraftSlot.team,
|
|
|
|
|
participant: {
|
|
|
|
|
...participant,
|
|
|
|
|
sport: participant.sportsSeason.sport,
|
|
|
|
|
},
|
|
|
|
|
sport: participant.sportsSeason.sport,
|
|
|
|
|
},
|
|
|
|
|
nextPickNumber: isDraftComplete ? currentPickNumber : nextPickNumber,
|
|
|
|
|
isDraftComplete,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isDraftComplete) {
|
Improve draft room UX with better error handling and UI refinements (#17)
* Remove pause/resume controls when draft is complete, rename Live to Connected
- Hide Pause/Resume Draft buttons when isDraftComplete is true
- Change 'Live' status indicator to 'Connected' in both draft room and draft board views
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
* Fix code review issues in draft room: security, bugs, and quality
Security:
- Fix inconsistent commissioner check: draft.start, force-autopick, force-manual-pick,
and make-pick all now query the commissioners table instead of league.createdBy,
so co-commissioners have consistent access to all draft controls
Bugs:
- canPick now includes !isPaused so the UI correctly blocks picks during a pause
- isDraftComplete initial state now covers 'completed' season status, not just 'active'
- Guard JSON.parse in queue.reorder.ts with try/catch to return 400 instead of 500
Code quality:
- Add error handling (try/catch + toast) to handlePauseDraft, handleResumeDraft,
handleRemoveFromQueue, and handleReorderQueue
- Replace alert() with toast.error() in handleMakePick, handleForceAutopick,
handleForceManualPick for consistent UX
- Memoize filteredParticipants with useMemo to avoid recomputing on every render
- Replace custom force-pick dialog div with ShadCN Dialog component for proper
keyboard support (Escape to close, focus trap, accessible markup); add dialog.tsx
- Remove console.log debug statements from socket event handlers and API routes
- Replace (global as any).__socketIO with getSocketIO() across all API routes
- Replace window.location.reload() in handleStartDraft with useRevalidator
https://claude.ai/code/session_01AUaKzx465NrY29Qv6MVwjC
---------
Co-authored-by: Claude <noreply@anthropic.com>
2026-02-20 21:50:27 -08:00
|
|
|
getSocketIO().to(`draft-${seasonId}`).emit("draft-completed");
|
2025-10-18 14:55:26 -07:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Socket.IO error:", error);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-25 22:11:10 -07:00
|
|
|
// Check if next team has autodraft enabled and trigger immediately
|
|
|
|
|
if (!isDraftComplete) {
|
|
|
|
|
const { checkAndTriggerNextAutodraft } = await import("~/models/draft-utils");
|
|
|
|
|
await checkAndTriggerNextAutodraft({
|
|
|
|
|
seasonId,
|
|
|
|
|
nextPickNumber,
|
|
|
|
|
totalTeams,
|
|
|
|
|
draftSlots,
|
|
|
|
|
db,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response.json({
|
|
|
|
|
success: true,
|
2025-10-18 14:55:26 -07:00
|
|
|
pick: draftPick,
|
|
|
|
|
nextPickNumber: isDraftComplete ? currentPickNumber : nextPickNumber,
|
|
|
|
|
isDraftComplete,
|
|
|
|
|
});
|
|
|
|
|
}
|