## Summary
- **Discord snake draft fix**: pick notifications now show the sequential pick-in-round (e.g. "Round 2, Pick 9") rather than the snake-adjusted slot position ("Round 2, Pick 5"). Also removes the now-unused \`pickInRound\` param from \`notifyPickMadeOnDiscord\` and adds a regression test for the 13-team case.
- **League card**: league name in draft-in-progress cards is now a link to the league homepage (the Enter Draft button still goes to the draft room).
- **Overnight pause label**: shortened to "🌙 Pause" — the "Resumes 4:00 AM" line below already provides context, so "Overnight" was just causing wrapping.
- **Queue & Picks backgrounds**: items use \`bg-card\` instead of \`bg-muted\` for better visual separation from the panel background.
## Test plan
- [x] Discord: in a snake draft, verify pick #22 of 13 shows "Round 2, Pick 9" in Discord
- [x] League card: dashboard with a draft-in-progress league — click name → league homepage, click Enter Draft → draft room
- [x] Overnight pause: pause a draft overnight — cell shows "🌙 Pause" on one line, "Resumes X:XX" below
- [x] Queue/Picks: open draft room and confirm queue items and recent picks visually pop from the sidebar background
- [x] Unit tests: `npm run test:run` passes (13 discord tests)
Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com>
Reviewed-on: #2
101 lines
3.1 KiB
TypeScript
101 lines
3.1 KiB
TypeScript
import { eq } from "drizzle-orm";
|
|
import * as schema from "~/database/schema";
|
|
import type { database } from "~/database/context";
|
|
import { findDiscordIdsByUserIds } from "~/models/account";
|
|
import { sendPickAnnouncementNotification } from "~/services/discord";
|
|
|
|
type DraftSlot = { teamId: string; draftOrder: number };
|
|
|
|
// Inline snake-draft pick calculation — mirrors calculatePickInfo in draft-utils.ts
|
|
// without creating a circular import (draft-utils imports this module).
|
|
function pickInRoundFor(pickNumber: number, teamCount: number): number {
|
|
const round = Math.ceil(pickNumber / teamCount);
|
|
const rawPickInRound = ((pickNumber - 1) % teamCount) + 1;
|
|
const isOddRound = round % 2 === 1;
|
|
const teamIndex = isOddRound ? rawPickInRound - 1 : teamCount - rawPickInRound;
|
|
return teamIndex + 1;
|
|
}
|
|
|
|
export async function notifyPickMadeOnDiscord(params: {
|
|
seasonId: string;
|
|
leagueId: string;
|
|
pickedTeamName: string;
|
|
participantName: string;
|
|
sportName: string;
|
|
pickNumber: number;
|
|
round: number;
|
|
rawPickInRound: number;
|
|
isDraftComplete: boolean;
|
|
totalTeams: number;
|
|
draftSlots: DraftSlot[];
|
|
db: ReturnType<typeof database>;
|
|
}): Promise<void> {
|
|
const {
|
|
seasonId,
|
|
leagueId,
|
|
pickedTeamName,
|
|
participantName,
|
|
sportName,
|
|
pickNumber,
|
|
round,
|
|
rawPickInRound,
|
|
isDraftComplete,
|
|
totalTeams,
|
|
draftSlots,
|
|
db,
|
|
} = params;
|
|
|
|
const league = await db.query.leagues.findFirst({
|
|
where: eq(schema.leagues.id, leagueId),
|
|
});
|
|
if (!league?.discordWebhookUrl || !league.discordPicksAnnouncementEnabled) return;
|
|
|
|
const appUrl = process.env.APP_URL ?? "https://brackt.com";
|
|
const draftUrl = `${appUrl}/leagues/${leagueId}/draft/${seasonId}`;
|
|
|
|
let nextTeamName: string | undefined;
|
|
let nextOwnerDiscordId: string | undefined;
|
|
|
|
if (!isDraftComplete) {
|
|
// Read currentPickNumber fresh from DB so we see the post-autodraft-chain state,
|
|
// matching the same guarantee sendOnTheClockEmail provides.
|
|
const freshSeason = await db.query.seasons.findFirst({
|
|
where: eq(schema.seasons.id, seasonId),
|
|
});
|
|
if (freshSeason) {
|
|
const nextPickInRound = pickInRoundFor(freshSeason.currentPickNumber ?? 1, totalTeams);
|
|
const nextSlot = draftSlots.find((s) => s.draftOrder === nextPickInRound);
|
|
if (nextSlot) {
|
|
const nextTeam = await db.query.teams.findFirst({
|
|
where: eq(schema.teams.id, nextSlot.teamId),
|
|
});
|
|
if (nextTeam) {
|
|
nextTeamName = nextTeam.name;
|
|
if (nextTeam.ownerId) {
|
|
const owner = await db.query.users.findFirst({
|
|
where: eq(schema.users.id, nextTeam.ownerId),
|
|
});
|
|
if (owner?.discordPingEnabled) {
|
|
const discordIds = await findDiscordIdsByUserIds([owner.id]);
|
|
nextOwnerDiscordId = discordIds.get(owner.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
await sendPickAnnouncementNotification({
|
|
webhookUrl: league.discordWebhookUrl,
|
|
draftUrl,
|
|
pickNumber,
|
|
round,
|
|
pickInRound: rawPickInRound,
|
|
pickedTeamName,
|
|
participantName,
|
|
sportName,
|
|
nextTeamName,
|
|
nextOwnerDiscordId,
|
|
isDraftComplete,
|
|
});
|
|
}
|