- Extract snake draft order calculation to shared getTeamForPick() helper in lib/draft-order.ts, removing the duplicated logic - Fix notification firing on user's own picks (guard with team id check) - Fix notification firing after draft is complete (early return) - Use a ref for sendNotification to prevent full socket handler re-registration every time the toggle is changed - Add permission drift listener via Permissions API so the UI reacts if the user revokes notification permission in browser settings - Add SSR guard for document.hidden in sendNotification - Remove redundant isSupported prop from NotificationSettings; derive unsupported state from permissionState === "unsupported" - Move NotificationSettings out of QueueSection prop-drilling path; render it via a new settingsSection slot on DraftSidebar instead https://claude.ai/code/session_0149MvVUYDY6pFUAV1fL4K69
18 lines
576 B
TypeScript
18 lines
576 B
TypeScript
/**
|
|
* Returns the draft slot for a given pick number in a snake draft.
|
|
*/
|
|
export function getTeamForPick<T extends { draftOrder: number }>(
|
|
pickNumber: number,
|
|
draftSlots: T[]
|
|
): T | undefined {
|
|
const totalTeams = draftSlots.length;
|
|
if (totalTeams === 0) return undefined;
|
|
|
|
const round = Math.ceil(pickNumber / totalTeams);
|
|
const isEvenRound = round % 2 === 0;
|
|
let pickInRound = ((pickNumber - 1) % totalTeams) + 1;
|
|
if (isEvenRound) {
|
|
pickInRound = totalTeams - pickInRound + 1;
|
|
}
|
|
return draftSlots.find((slot) => slot.draftOrder === pickInRound);
|
|
}
|