2025-11-12 23:44:33 -08:00
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "~/components/ui/card";
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "~/components/ui/table";
|
|
|
|
|
import { Badge } from "~/components/ui/badge";
|
2026-03-07 21:59:29 -08:00
|
|
|
import { TrendingUp, TrendingDown, Minus, Flag, CheckCircle2, Star } from "lucide-react";
|
User/chris/bracket UI redesign (#95)
* feat: redesign playoff bracket UI with compact layout and owner display
- Replace per-match Card wrappers with compact left-vs-right rows (stacks on mobile)
- Add TeamOwnerBadge component (colored avatar + team name + username), matching the standings "Drafted By" style
- Show owner info below each participant name in bracket matches
- Add TBD forward-reference labels ("Winner of Quarterfinals M1") computed via buildFeederMap
- Add Final Rankings table below bracket showing all participants ranked by elimination round
- Fix round ordering in loader: sort by match count descending (more matches = earlier round)
- Add loser relation to playoff matches query for elimination tracking
- Extract getAvatarColor to app/lib/color-hash.ts (shared across GroupStageDisplay, SeasonStandings, TeamOwnerBadge)
- Extract groupMatchesByRound helper; share grouped map between feeder computation and render
- Remove dead getTeamAvatar from SeasonStandings after TeamOwnerBadge adoption
- Add tests for groupMatchesByRound and buildFeederMap (7 tests)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat: add draft order card to league home page
Show draft order on the league home page when order is set and season
is in pre_draft or draft status. Includes team name, owner name, and
a link to the draft room.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat: enhance playoff bracket with eliminated teams, points, and ownership highlights
- Show eliminated teams (including group-stage losers) in Final Rankings card
- Display computed fantasy points per participant in rankings table
- Card title switches between "Eliminated Teams" and "Final Rankings" based on bracket completion
- Highlight owned participants with electric blue name, dot indicator, and card border in bracket matches
- Highlight owned rows with electric border/background in rankings table
- Suppress EventSchedule for playoff_bracket sports seasons
- Fix title redundancy: bracket section title no longer repeats sport name
- Two-column match grid on desktop (md:grid-cols-2)
- Code review fixes: parallel DB fetches, targeted query for pre-eliminated, single-pass parseFloat, remove IIFE
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 22:44:33 -07:00
|
|
|
import { TeamOwnerBadge } from "~/components/ui/team-owner-badge";
|
2025-11-12 23:44:33 -08:00
|
|
|
|
|
|
|
|
interface SeasonStanding {
|
|
|
|
|
id: string;
|
|
|
|
|
championshipPoints: string; // Decimal as string
|
|
|
|
|
position: number;
|
|
|
|
|
previousPosition?: number | null; // For showing movement
|
|
|
|
|
participant: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface TeamOwnership {
|
|
|
|
|
participantId: string;
|
|
|
|
|
teamName: string;
|
|
|
|
|
teamId: string;
|
|
|
|
|
ownerName?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface SeasonStandingsProps {
|
|
|
|
|
standings: SeasonStanding[];
|
|
|
|
|
teamOwnerships?: TeamOwnership[]; // Which teams own which participants
|
2026-03-07 21:59:29 -08:00
|
|
|
userParticipantIds?: string[]; // Participants drafted by the current user
|
2025-11-12 23:44:33 -08:00
|
|
|
showOwnership?: boolean;
|
|
|
|
|
isFinalized?: boolean; // Whether season is complete
|
|
|
|
|
title?: string;
|
|
|
|
|
description?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SeasonStandings component - Displays F1-style championship standings
|
|
|
|
|
*
|
|
|
|
|
* Features:
|
|
|
|
|
* - Shows participants ranked by championship points
|
|
|
|
|
* - Positions auto-calculated from points (highest = 1st)
|
|
|
|
|
* - Optional ownership hints with team avatars
|
|
|
|
|
* - Movement indicators (position changes)
|
|
|
|
|
* - Handles ties (same points = same position)
|
|
|
|
|
*/
|
Fix oxlint warnings: no-shadow, consistent-function-scoping, no-non-null-assertion, and others (#196)
* Fix no-shadow and consistent-function-scoping lint violations
Resolves all 11 no-shadow and 16 consistent-function-scoping oxlint
warnings and promotes both rules to errors in .oxlintrc.json.
no-shadow: renamed Drizzle callback params (sports→s, matches→m,
seasons→s) to avoid shadowing outer imports; removed shadowed
destructures (eq, inArray) from where callbacks; renamed inner
template→bracketTemplate, prev→currentTimers, season→ss, name→teamName
(with name: teamName fix to preserve semantics).
consistent-function-scoping: moved formatDate, getRankBadge,
getMovementIndicator, getPositionBadge, getStatusBadge, toDateStr,
elo (×2), weightedPick, sortByMatchNumber (×2) to module scope;
moved formatTime (×2), isValidLeagueName, getDraftTimes,
makeSeasonQueues to file scope in test files.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix no-non-null-assertion lint violations and promote to error
Eliminates all 208 no-non-null-assertion warnings across 38 files.
Promotes typescript/no-non-null-assertion from warn to error in
.oxlintrc.json.
Fix patterns applied:
- Map.get(key)! after .has() check → extract with get() + null guard
- Map.get(key)! on pre-populated count maps → ?? 0 default
- .set(id, map.get(id)! + 1) increment → ?? 0 before adding
- participant1Id!/participant2Id! on DB matches → ?? "" fallback
- array.find()! in tests → guard + throw or expect().toBeDefined()
- bracketTemplateCache.get(id)! → null guard extract
- Various nullable field accesses → optional chain or ?? default
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix prefer-add-event-listener, no-unassigned-import, require-module-specifiers
Resolves all 9 remaining non-console lint warnings and promotes all
three rules to errors in .oxlintrc.json.
- prefer-add-event-listener: converted onchange/onclick/onload
assignments to addEventListener in useDraftNotifications.ts and
admin.data-sync.tsx; stored changeHandler ref for proper cleanup
with removeEventListener
- no-unassigned-import: configured rule with allow list for legitimate
side-effect imports (*.css, @testing-library/jest-dom,
@testing-library/cypress/add-commands)
- require-module-specifiers: removed redundant `export {}` from
cypress/support/e2e.ts (file already has an import)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Fix TypeScript errors from no-non-null-assertion fixes
Two fixes introduced by the non-null assertion cleanup produced type
errors:
- scoring-event.ts: `?? ""` was wrong type for a participant object map;
restructured to explicit null guards so TypeScript can narrow correctly
- standings-sync/index.ts: `?? null` after name-match lookup lost the
truthy guarantee, causing TS18047 on the write-back block; added
`participant &&` guard before accessing its properties
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Add npm run typecheck as Stop hook in Claude settings
Runs a full project typecheck at the end of each Claude turn so type
errors surface as feedback before the next message.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 10:59:51 -07:00
|
|
|
function getMovementIndicator(
|
|
|
|
|
currentPosition: number,
|
|
|
|
|
previousPosition?: number | null
|
|
|
|
|
) {
|
|
|
|
|
if (!previousPosition) return null;
|
|
|
|
|
|
|
|
|
|
const change = previousPosition - currentPosition; // Positive means moved up
|
|
|
|
|
|
|
|
|
|
if (change > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center gap-1 text-emerald-400">
|
|
|
|
|
<TrendingUp className="h-3 w-3" />
|
|
|
|
|
<span className="text-xs">+{change}</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else if (change < 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center gap-1 text-coral-accent">
|
|
|
|
|
<TrendingDown className="h-3 w-3" />
|
|
|
|
|
<span className="text-xs">{change}</span>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex items-center gap-1 text-muted-foreground">
|
|
|
|
|
<Minus className="h-3 w-3" />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPositionBadge(position: number, isTied: boolean) {
|
|
|
|
|
const suffix = position === 1 ? "st" : position === 2 ? "nd" : position === 3 ? "rd" : "th";
|
|
|
|
|
const positionText = isTied ? `T${position}` : `${position}${suffix}`;
|
|
|
|
|
return <span className="font-medium">{positionText}</span>;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-12 23:44:33 -08:00
|
|
|
export function SeasonStandings({
|
|
|
|
|
standings,
|
|
|
|
|
teamOwnerships = [],
|
2026-03-07 21:59:29 -08:00
|
|
|
userParticipantIds = [],
|
2025-11-12 23:44:33 -08:00
|
|
|
showOwnership = true,
|
|
|
|
|
isFinalized = false,
|
|
|
|
|
title = "Championship Standings",
|
2026-03-21 09:44:05 -07:00
|
|
|
description: _description,
|
2025-11-12 23:44:33 -08:00
|
|
|
}: SeasonStandingsProps) {
|
2026-03-07 21:59:29 -08:00
|
|
|
const userParticipantSet = new Set(userParticipantIds);
|
2025-11-12 23:44:33 -08:00
|
|
|
// Create ownership map for fast lookup
|
|
|
|
|
const ownershipMap = new Map<string, TeamOwnership>();
|
|
|
|
|
teamOwnerships.forEach((ownership) => {
|
|
|
|
|
ownershipMap.set(ownership.participantId, ownership);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Get ownership info for a participant
|
|
|
|
|
const getOwnership = (participantId: string): TeamOwnership | null => {
|
|
|
|
|
if (!showOwnership) return null;
|
|
|
|
|
return ownershipMap.get(participantId) || null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Check if multiple participants share the same position
|
|
|
|
|
const checkIfTied = (standing: SeasonStanding): boolean => {
|
|
|
|
|
return standings.some(
|
|
|
|
|
(other) =>
|
|
|
|
|
other.id !== standing.id && other.position === standing.position
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Count top 8 finishers (those who will get fantasy points)
|
|
|
|
|
const top8Count = standings.filter((s) => s.position <= 8).length;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card
|
|
|
|
|
className={
|
|
|
|
|
isFinalized
|
2026-02-20 19:26:11 -08:00
|
|
|
? "border-emerald-500/30"
|
|
|
|
|
: "border-electric/30"
|
2025-11-12 23:44:33 -08:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle
|
|
|
|
|
className={
|
|
|
|
|
isFinalized
|
2026-02-20 19:26:11 -08:00
|
|
|
? "text-emerald-400"
|
|
|
|
|
: "text-electric"
|
2025-11-12 23:44:33 -08:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Flag className="inline mr-2 h-5 w-5" />
|
|
|
|
|
{title}
|
|
|
|
|
</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{isFinalized ? (
|
2026-02-20 19:26:11 -08:00
|
|
|
<span className="text-emerald-400 font-semibold">
|
2025-11-12 23:44:33 -08:00
|
|
|
<CheckCircle2 className="inline h-4 w-4 mr-1" />
|
|
|
|
|
Season complete - Fantasy points assigned to top 8 finishers
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
Current championship standings. Positions calculated from points
|
|
|
|
|
(highest = 1st).
|
|
|
|
|
{top8Count > 0 && (
|
|
|
|
|
<span className="block mt-1">
|
|
|
|
|
Top 8 finishers will receive fantasy points when season completes.
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{standings.length === 0 ? (
|
|
|
|
|
<div className="text-center py-8 text-muted-foreground">
|
|
|
|
|
<p className="text-sm">No standings data available yet.</p>
|
|
|
|
|
<p className="text-xs mt-1">
|
|
|
|
|
Championship points will appear here once results are entered.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead className="w-20">Pos</TableHead>
|
|
|
|
|
{standings.some((s) => s.previousPosition) && (
|
|
|
|
|
<TableHead className="w-20">Change</TableHead>
|
|
|
|
|
)}
|
|
|
|
|
<TableHead>Participant</TableHead>
|
2026-03-07 21:59:29 -08:00
|
|
|
<TableHead className="text-right w-20">Points</TableHead>
|
2025-11-12 23:44:33 -08:00
|
|
|
{showOwnership && (
|
2026-03-07 21:59:29 -08:00
|
|
|
<TableHead className="w-40 pl-6">Drafted By</TableHead>
|
2025-11-12 23:44:33 -08:00
|
|
|
)}
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{standings
|
2026-03-21 09:44:05 -07:00
|
|
|
.toSorted((a, b) => a.position - b.position)
|
2025-11-12 23:44:33 -08:00
|
|
|
.map((standing) => {
|
|
|
|
|
const ownership = getOwnership(standing.participant.id);
|
|
|
|
|
const isTied = checkIfTied(standing);
|
|
|
|
|
const isTop8 = standing.position <= 8;
|
2026-03-07 21:59:29 -08:00
|
|
|
const isOwned = userParticipantSet.has(standing.participant.id);
|
|
|
|
|
|
|
|
|
|
let rowClass = "";
|
|
|
|
|
if (isOwned && isTop8) {
|
|
|
|
|
rowClass = "bg-electric/8 border-l-2 border-l-electric font-medium";
|
|
|
|
|
} else if (isOwned && !isTop8) {
|
|
|
|
|
rowClass = "bg-muted/20 border-l-2 border-l-muted-foreground/40 opacity-80";
|
|
|
|
|
} else if (isTop8) {
|
|
|
|
|
rowClass = standing.position <= 3 ? "bg-muted/30 font-medium" : "";
|
|
|
|
|
} else {
|
|
|
|
|
rowClass = "opacity-60";
|
|
|
|
|
}
|
2025-11-12 23:44:33 -08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<TableRow
|
|
|
|
|
key={standing.id}
|
2026-03-07 21:59:29 -08:00
|
|
|
className={rowClass}
|
2025-11-12 23:44:33 -08:00
|
|
|
>
|
|
|
|
|
<TableCell>
|
|
|
|
|
{getPositionBadge(standing.position, isTied)}
|
|
|
|
|
</TableCell>
|
|
|
|
|
{standings.some((s) => s.previousPosition) && (
|
|
|
|
|
<TableCell>
|
|
|
|
|
{getMovementIndicator(
|
|
|
|
|
standing.position,
|
|
|
|
|
standing.previousPosition
|
|
|
|
|
)}
|
|
|
|
|
</TableCell>
|
|
|
|
|
)}
|
|
|
|
|
<TableCell className="font-medium">
|
2026-03-07 21:59:29 -08:00
|
|
|
<span>{standing.participant.name}</span>
|
|
|
|
|
{isOwned && (
|
|
|
|
|
<Star
|
|
|
|
|
className={`inline ml-1.5 h-3 w-3 fill-current ${isTop8 ? "text-electric" : "text-muted-foreground"}`}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-11-12 23:44:33 -08:00
|
|
|
</TableCell>
|
|
|
|
|
<TableCell className="text-right">
|
|
|
|
|
<span
|
|
|
|
|
className={`font-semibold ${
|
|
|
|
|
isTop8
|
2026-02-20 19:26:11 -08:00
|
|
|
? "text-electric"
|
2025-11-12 23:44:33 -08:00
|
|
|
: "text-muted-foreground"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
2026-03-07 21:59:29 -08:00
|
|
|
{Math.round(parseFloat(standing.championshipPoints))}
|
2025-11-12 23:44:33 -08:00
|
|
|
</span>
|
|
|
|
|
</TableCell>
|
|
|
|
|
{showOwnership && (
|
2026-03-07 21:59:29 -08:00
|
|
|
<TableCell className="pl-6">
|
2025-11-12 23:44:33 -08:00
|
|
|
{ownership ? (
|
User/chris/bracket UI redesign (#95)
* feat: redesign playoff bracket UI with compact layout and owner display
- Replace per-match Card wrappers with compact left-vs-right rows (stacks on mobile)
- Add TeamOwnerBadge component (colored avatar + team name + username), matching the standings "Drafted By" style
- Show owner info below each participant name in bracket matches
- Add TBD forward-reference labels ("Winner of Quarterfinals M1") computed via buildFeederMap
- Add Final Rankings table below bracket showing all participants ranked by elimination round
- Fix round ordering in loader: sort by match count descending (more matches = earlier round)
- Add loser relation to playoff matches query for elimination tracking
- Extract getAvatarColor to app/lib/color-hash.ts (shared across GroupStageDisplay, SeasonStandings, TeamOwnerBadge)
- Extract groupMatchesByRound helper; share grouped map between feeder computation and render
- Remove dead getTeamAvatar from SeasonStandings after TeamOwnerBadge adoption
- Add tests for groupMatchesByRound and buildFeederMap (7 tests)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat: add draft order card to league home page
Show draft order on the league home page when order is set and season
is in pre_draft or draft status. Includes team name, owner name, and
a link to the draft room.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat: enhance playoff bracket with eliminated teams, points, and ownership highlights
- Show eliminated teams (including group-stage losers) in Final Rankings card
- Display computed fantasy points per participant in rankings table
- Card title switches between "Eliminated Teams" and "Final Rankings" based on bracket completion
- Highlight owned participants with electric blue name, dot indicator, and card border in bracket matches
- Highlight owned rows with electric border/background in rankings table
- Suppress EventSchedule for playoff_bracket sports seasons
- Fix title redundancy: bracket section title no longer repeats sport name
- Two-column match grid on desktop (md:grid-cols-2)
- Code review fixes: parallel DB fetches, targeted query for pre-eliminated, single-pass parseFloat, remove IIFE
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 22:44:33 -07:00
|
|
|
<TeamOwnerBadge
|
|
|
|
|
teamName={ownership.teamName}
|
|
|
|
|
ownerName={ownership.ownerName}
|
|
|
|
|
/>
|
2025-11-12 23:44:33 -08:00
|
|
|
) : (
|
|
|
|
|
<span className="text-xs text-muted-foreground">-</span>
|
|
|
|
|
)}
|
|
|
|
|
</TableCell>
|
|
|
|
|
)}
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
|
|
|
|
|
{!isFinalized && top8Count > 0 && (
|
|
|
|
|
<div className="mt-4 p-3 border-t">
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
<Badge variant="secondary" className="text-xs">
|
|
|
|
|
{top8Count}
|
|
|
|
|
</Badge>{" "}
|
|
|
|
|
participant{top8Count !== 1 ? "s" : ""} currently in top 8 will
|
|
|
|
|
receive fantasy points when season completes.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|