Draft room tweaks.
This commit is contained in:
parent
a4eaec865b
commit
09b5193f18
2 changed files with 117 additions and 89 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
import { memo, useMemo } from "react";
|
import { memo, useMemo, Fragment } from "react";
|
||||||
|
import { TeamAvatar } from "~/components/TeamAvatar";
|
||||||
import { type DraftPick, groupPicksByTeamAndSport } from "./picks-utils";
|
import { type DraftPick, groupPicksByTeamAndSport } from "./picks-utils";
|
||||||
|
|
||||||
interface DraftSummaryViewProps {
|
interface DraftSummaryViewProps {
|
||||||
draftSlots: Array<{ id: string; team: { id: string; name: string } }>;
|
draftSlots: Array<{ id: string; team: { id: string; name: string; logoUrl?: string | null } }>;
|
||||||
ownerMap?: Record<string, string>;
|
ownerMap?: Record<string, string>;
|
||||||
picks: DraftPick[];
|
picks: DraftPick[];
|
||||||
sports: Array<{ id: string; name: string }>;
|
sports: Array<{ id: string; name: string }>;
|
||||||
|
|
@ -58,90 +59,93 @@ export const DraftSummaryView = memo(function DraftSummaryView({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gridCols = `140px 96px repeat(${draftSlots.length}, minmax(80px, 1fr))`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-full overflow-auto">
|
<div className="w-full h-full overflow-auto">
|
||||||
<table className="w-full border-collapse">
|
<div className="grid w-full" style={{ gridTemplateColumns: gridCols }}>
|
||||||
<thead className="sticky top-0 bg-background z-10">
|
|
||||||
<tr>
|
{/* Header row */}
|
||||||
<th
|
<div className="sticky top-0 left-0 z-30 bg-muted border-r border-b border-border px-3 py-2 text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
||||||
scope="col"
|
Sport
|
||||||
className="border-r border-b border-border p-2 text-left font-semibold bg-muted sticky left-0 z-20 min-w-[120px]"
|
</div>
|
||||||
|
<div className="sticky top-0 z-20 bg-muted border-r border-b border-border px-2 py-2 text-center text-xs font-semibold uppercase tracking-wider text-muted-foreground">
|
||||||
|
Total
|
||||||
|
</div>
|
||||||
|
{draftSlots.map((slot, index) => {
|
||||||
|
const ownerName = ownerMap[slot.team.id];
|
||||||
|
const isLast = index === draftSlots.length - 1;
|
||||||
|
const used = flexPicksUsedByTeam.get(slot.team.id) ?? 0;
|
||||||
|
const flexesExhausted = flexPicksAvailable > 0 && used >= flexPicksAvailable;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={slot.id}
|
||||||
|
className={`sticky top-0 z-20 bg-muted/40 border-b border-border px-1 py-2 min-w-0 ${!isLast ? "border-r" : ""}`}
|
||||||
>
|
>
|
||||||
Sport
|
<div className="flex flex-col items-center gap-1">
|
||||||
</th>
|
<TeamAvatar
|
||||||
<th
|
teamId={slot.team.id}
|
||||||
scope="col"
|
teamName={ownerName || slot.team.name}
|
||||||
className="border-r border-b border-border p-2 text-center font-semibold bg-muted min-w-[48px]"
|
logoUrl={slot.team.logoUrl}
|
||||||
>
|
size="md"
|
||||||
Total
|
/>
|
||||||
</th>
|
<div className="text-xs font-semibold text-center truncate w-full">
|
||||||
{draftSlots.map((slot, index) => {
|
{ownerName || slot.team.name}
|
||||||
const displayName = ownerMap[slot.team.id] || slot.team.name;
|
</div>
|
||||||
const isLast = index === draftSlots.length - 1;
|
{flexPicksAvailable > 0 && (
|
||||||
const used = flexPicksUsedByTeam.get(slot.team.id) ?? 0;
|
<span className={`text-xs ${flexesExhausted ? "text-destructive font-medium" : "text-muted-foreground"}`}>
|
||||||
const flexesExhausted = flexPicksAvailable > 0 && used >= flexPicksAvailable;
|
{used}/{flexPicksAvailable} flex picks
|
||||||
return (
|
</span>
|
||||||
<th
|
)}
|
||||||
key={slot.id}
|
</div>
|
||||||
scope="col"
|
</div>
|
||||||
className={`border-b border-border p-2 text-center font-semibold bg-muted/50 min-w-[60px] ${!isLast ? "border-r" : ""}`}
|
);
|
||||||
>
|
})}
|
||||||
<span className="text-sm">{displayName}</span>
|
|
||||||
{flexPicksAvailable > 0 && (
|
{/* Data rows */}
|
||||||
<div className={`text-xs mt-0.5 ${flexesExhausted ? "text-destructive font-medium" : "font-normal text-muted-foreground"}`}>
|
{sports.map((sport, sportIndex) => {
|
||||||
{used} of {flexPicksAvailable} flexes
|
const isLastRow = sportIndex === sports.length - 1;
|
||||||
</div>
|
const { total: sportTotal, teams: sportTeamCount } =
|
||||||
)}
|
sportStats.get(sport.id) ?? { total: 0, teams: 0 };
|
||||||
</th>
|
return (
|
||||||
);
|
<Fragment key={sport.id}>
|
||||||
})}
|
<div className={`sticky left-0 z-10 bg-muted border-r border-border px-3 py-2.5 font-medium text-sm whitespace-nowrap ${!isLastRow ? "border-b" : ""}`}>
|
||||||
</tr>
|
{sport.name}
|
||||||
</thead>
|
</div>
|
||||||
<tbody>
|
<div className={`border-r border-border px-2 py-2.5 text-center bg-muted/20 ${!isLastRow ? "border-b" : ""}`}>
|
||||||
{sports.map((sport, sportIndex) => {
|
{sportTotal > 0 ? (
|
||||||
const isLastRow = sportIndex === sports.length - 1;
|
<>
|
||||||
const { total: sportTotal, teams: sportTeamCount } = sportStats.get(sport.id) ?? { total: 0, teams: 0 };
|
<div className="text-sm font-bold tabular-nums">{sportTotal}</div>
|
||||||
return (
|
<div className="text-xs text-muted-foreground">{sportTeamCount}/{draftSlots.length} teams</div>
|
||||||
<tr key={sport.id}>
|
</>
|
||||||
<th
|
) : (
|
||||||
scope="row"
|
<span className="text-muted-foreground/40 text-sm">—</span>
|
||||||
className={`border-r border-border p-2 font-medium text-sm text-left bg-muted sticky left-0 z-10 ${!isLastRow ? "border-b" : ""}`}
|
)}
|
||||||
>
|
</div>
|
||||||
{sport.name}
|
{draftSlots.map((slot, slotIndex) => {
|
||||||
</th>
|
const count = picksByTeamAndSport.get(slot.team.id)?.get(sport.id)?.length ?? 0;
|
||||||
<td
|
const isLast = slotIndex === draftSlots.length - 1;
|
||||||
className={`border-r border-border p-2 text-center text-sm font-semibold bg-muted/30 ${!isLastRow ? "border-b" : ""}`}
|
const isFlex = count >= 2;
|
||||||
>
|
return (
|
||||||
{sportTotal > 0 ? (
|
<div
|
||||||
<>
|
key={`${slot.team.id}-${sport.id}`}
|
||||||
<div>{sportTotal}</div>
|
className={`border-border px-3 py-2.5 text-center ${isFlex ? "bg-amber-500/10" : "bg-background"} ${!isLastRow ? "border-b" : ""} ${!isLast ? "border-r" : ""}`}
|
||||||
<div className="text-xs font-normal text-muted-foreground mt-0.5">
|
>
|
||||||
{sportTeamCount} team{sportTeamCount !== 1 ? "s" : ""}
|
{count > 0 ? (
|
||||||
</div>
|
<span className={`text-sm font-bold tabular-nums ${isFlex ? "text-amber-600 dark:text-amber-400" : ""}`}>
|
||||||
</>
|
{count}
|
||||||
) : null}
|
</span>
|
||||||
</td>
|
) : (
|
||||||
{draftSlots.map((slot, slotIndex) => {
|
<span className="text-muted-foreground/30 text-sm">—</span>
|
||||||
const count =
|
)}
|
||||||
picksByTeamAndSport.get(slot.team.id)?.get(sport.id)
|
</div>
|
||||||
?.length ?? 0;
|
);
|
||||||
const isLast = slotIndex === draftSlots.length - 1;
|
})}
|
||||||
return (
|
</Fragment>
|
||||||
<td
|
);
|
||||||
key={`${slot.team.id}-${sport.id}`}
|
})}
|
||||||
className={`border-border p-2 text-center text-sm ${
|
|
||||||
count >= 2 ? "bg-accent/30 font-semibold" : "bg-background"
|
</div>
|
||||||
} ${!isLastRow ? "border-b" : ""} ${!isLast ? "border-r" : ""}`}
|
|
||||||
>
|
|
||||||
{count > 0 ? count : null}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,24 @@
|
||||||
import { getAvatarColor } from "~/lib/color-hash";
|
const AVATAR_COLORS = [
|
||||||
|
"#adf661",
|
||||||
|
"#2ce1c1",
|
||||||
|
"#8b5cf6",
|
||||||
|
"#f59e0b",
|
||||||
|
"#ef4444",
|
||||||
|
"#3b82f6",
|
||||||
|
];
|
||||||
|
|
||||||
|
function hashName(name: string): number {
|
||||||
|
let hash = 0;
|
||||||
|
for (let i = 0; i < name.length; i++) {
|
||||||
|
hash = (hash * 31 + name.charCodeAt(i)) & 0xffff;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
interface TeamOwnerBadgeProps {
|
interface TeamOwnerBadgeProps {
|
||||||
teamName: string;
|
teamName: string;
|
||||||
ownerName?: string;
|
ownerName?: string;
|
||||||
align?: "left" | "right"; // right = avatar on the right side for the right column
|
align?: "left" | "right";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TeamOwnerBadge({
|
export function TeamOwnerBadge({
|
||||||
|
|
@ -11,14 +26,23 @@ export function TeamOwnerBadge({
|
||||||
ownerName,
|
ownerName,
|
||||||
align = "left",
|
align = "left",
|
||||||
}: TeamOwnerBadgeProps) {
|
}: TeamOwnerBadgeProps) {
|
||||||
const initial = teamName.charAt(0).toUpperCase();
|
const initials =
|
||||||
const colorClass = getAvatarColor(teamName);
|
teamName
|
||||||
|
.split(/\s+/)
|
||||||
|
.filter(Boolean)
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((w) => w[0].toUpperCase())
|
||||||
|
.join("") || "?";
|
||||||
|
const color = AVATAR_COLORS[hashName(teamName) % AVATAR_COLORS.length];
|
||||||
|
|
||||||
const avatar = (
|
const avatar = (
|
||||||
<div
|
<div
|
||||||
className={`h-6 w-6 rounded-full ${colorClass} text-white text-xs font-bold flex items-center justify-center shrink-0`}
|
role="img"
|
||||||
|
aria-label={teamName}
|
||||||
|
className="h-6 w-6 flex shrink-0 items-center justify-center font-bold text-[10px]"
|
||||||
|
style={{ backgroundColor: "#000", color }}
|
||||||
>
|
>
|
||||||
{initial}
|
{initials}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue