* Redesign home page with new layout and component system - Two-column layout (My Leagues 2/3, Upcoming Events 1/3) with mobile stack - LeagueRow: square avatar, gradient draft highlight, rank/points display, progress bar - MyLeaguesCard, CreateLeagueCard with shared SectionCardHeader - UpcomingEventsCard: vertical timeline with grouped multi-league events - Shared gradient system: BracktGradients SVG defs, GradientIcon wrapper, brand.ts constants - Button default variant updated to green→cyan gradient - Navbar: plain nav links with gradient hover, support/admin icon buttons - Accessibility fixes: semantic h2 headings, aria-label on LeagueAvatar and nav elements - Storybook stories for all new components Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Responsive league row layout and mobile polish - League rows stack avatar+name on top, stats full-width below on mobile - Stats spread to right side on sm+ screens with border separator on mobile - Tighter padding on mobile (px-3/py-3), full padding on sm+ - Card headers and content use px-3 sm:px-6 to reduce mobile gutters - Two-column home layout deferred to lg breakpoint (tablet gets stacked) - Active leagues sorted by completion percentage descending - Default rank 1 / 0 points for active leagues with no scoring events yet - Fix ordinal bug for 11th/12th/13th; add aria-labels to rank change indicators - Remove dead StatDivider className prop Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Improve claude file. * Add StandingsPreview card component with podium row styling - New StandingsPreview component with gold/silver/bronze row tints for top 3, team avatar, and LeagueRow-style stat columns (Ranking + Points) with rank and 7-day point change indicators - Fix GradientIcon in Storybook by adding BracktGradients decorator to preview.tsx (renamed from .ts to support JSX) - Fix degenerate SVG gradient on horizontal strokes by switching BracktGradients to gradientUnits="userSpaceOnUse" with Lucide-space coordinates (0→24) - Revert erroneous fill: url(#gradient) from GradientIcon; stroke-only fix was sufficient once gradientUnits was corrected Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update components on league homepage. * Finish up league page styling. * Work on standings page. * Add story for RecentScoresCard * Update Point Progression Chart. * Sort point progression legend by ranking and add team links to standings rows * Fix standings discrepancy on change. * Create draft cell component. * Update draft board page * Draft room improvements. * Update some draft room styling. * Fix context menu missing. * Move tab navigation and autodraft to header row, narrow sidebar * Virtualize available participants list, memoize draft room props Adds @tanstack/react-virtual to replace separate mobile/desktop lists with a single unified virtual scroll loop. Also memoizes miniDraftGrid and availableParticipantsSectionProps, and switches pick lookup from Array.find to a Map for O(1) access. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update draft room UI. * More draft room fixes. * Draft room tweaks. * Fix Rosters page. * Queue Section fixes. * Mobile Draft fixes. * Fix draft board page. * Create bracket look. * Bracket work. * Finish bracket page. * Homepage initial styling * homepage copy * Add privacy policy. Fixes #88. * how to play copy * rules copy * Fix brackets on homepage. * Add footer to website. * Glow on dots. * Landing page copy. * Fix sidebar. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
205 lines
7 KiB
TypeScript
205 lines
7 KiB
TypeScript
import { useLoaderData, Link } from "react-router";
|
|
import { getAuth } from "@clerk/react-router/server";
|
|
import { database } from "~/database/context";
|
|
import { eq, and } from "drizzle-orm";
|
|
import * as schema from "~/database/schema";
|
|
import { Button } from "~/components/ui/button";
|
|
import { logger } from "~/lib/logger";
|
|
import { getSevenDayStandingsChange, getSeasonPointProgression } from "~/models/standings";
|
|
import { isSeasonComplete, getSeasonCompletionPercentage } from "~/lib/season-helpers.server";
|
|
import { getRecentTeamScoreEvents } from "~/models/team-score-events";
|
|
import { PointProgressionChart } from "~/components/standings/PointProgressionChart";
|
|
import { findUsersByClerkIds, getUserDisplayName } from "~/models/user";
|
|
import { StandingsPreview } from "~/components/league/StandingsPreview";
|
|
import { buildTiedRankChecker, getDisplayRank } from "~/lib/standings-display";
|
|
import { RecentScoresCard } from "~/components/standings/RecentScoresCard";
|
|
import type { Route } from "./+types/$leagueId.standings.$seasonId";
|
|
|
|
export function meta({ data }: Route.MetaArgs): Route.MetaDescriptors {
|
|
return [{ title: `Standings — ${data?.league?.name ?? "League"} - Brackt` }];
|
|
}
|
|
|
|
export async function loader(args: Route.LoaderArgs) {
|
|
try {
|
|
const { userId } = await getAuth(args);
|
|
const { params } = args;
|
|
const { leagueId, seasonId } = params;
|
|
|
|
const db = database();
|
|
|
|
// Fetch league
|
|
const league = await db.query.leagues.findFirst({
|
|
where: eq(schema.leagues.id, leagueId),
|
|
});
|
|
|
|
if (!league) {
|
|
throw new Response("League not found", { status: 404 });
|
|
}
|
|
|
|
// Fetch season
|
|
const season = await db.query.seasons.findFirst({
|
|
where: eq(schema.seasons.id, seasonId),
|
|
});
|
|
|
|
if (!season || season.leagueId !== leagueId) {
|
|
throw new Response("Season not found", { status: 404 });
|
|
}
|
|
|
|
// Check access
|
|
if (!userId) {
|
|
throw new Response("You must be logged in to view standings", {
|
|
status: 401,
|
|
});
|
|
}
|
|
|
|
// Check if user is a commissioner
|
|
const isUserCommissioner = await db.query.commissioners.findFirst({
|
|
where: and(
|
|
eq(schema.commissioners.leagueId, leagueId),
|
|
eq(schema.commissioners.userId, userId)
|
|
),
|
|
});
|
|
|
|
// Check if user has a team in this season
|
|
const hasTeam = await db.query.teams.findFirst({
|
|
where: and(
|
|
eq(schema.teams.seasonId, seasonId),
|
|
eq(schema.teams.ownerId, userId)
|
|
),
|
|
});
|
|
|
|
if (!isUserCommissioner && !hasTeam) {
|
|
throw new Response("You do not have access to this league", {
|
|
status: 403,
|
|
});
|
|
}
|
|
|
|
// Fetch standings, teams (for owner lookup), and independent data in parallel
|
|
const [standingsWithComparison, teams, progressionData, seasonComplete, completionPercentage, recentScoreEvents] =
|
|
await Promise.all([
|
|
getSevenDayStandingsChange(seasonId, db),
|
|
db.query.teams.findMany({
|
|
where: eq(schema.teams.seasonId, seasonId),
|
|
columns: { id: true, ownerId: true },
|
|
}),
|
|
getSeasonPointProgression(seasonId, db),
|
|
isSeasonComplete(seasonId, db),
|
|
getSeasonCompletionPercentage(seasonId, db),
|
|
getRecentTeamScoreEvents(seasonId, 10, db),
|
|
]);
|
|
|
|
// Build teamId -> ownerName map
|
|
const ownerIds = [...new Set(teams.map((t) => t.ownerId).filter((id): id is string => id !== null))];
|
|
const userRows = await findUsersByClerkIds(ownerIds);
|
|
const userByClerkId = new Map(userRows.map((u) => [u.clerkId, u]));
|
|
const ownerNameByTeamId = new Map(
|
|
teams
|
|
.filter((t): t is typeof t & { ownerId: string } => t.ownerId !== null)
|
|
.map((t) => {
|
|
const user = userByClerkId.get(t.ownerId);
|
|
return [t.id, user ? getUserDisplayName(user) : null] as const;
|
|
})
|
|
);
|
|
|
|
// Map to format expected by component (use sevenDayRankChange instead of previousRank)
|
|
const formattedStandings = standingsWithComparison.map((standing) => ({
|
|
...standing,
|
|
rankChange: standing.sevenDayRankChange,
|
|
ownerName: ownerNameByTeamId.get(standing.teamId) ?? null,
|
|
}));
|
|
|
|
// Enrich recentScoreEvents with owner names
|
|
const enrichedScoreEvents = recentScoreEvents.map((event) => ({
|
|
...event,
|
|
ownerName: ownerNameByTeamId.get(event.teamId) ?? null,
|
|
}));
|
|
|
|
return {
|
|
league,
|
|
season,
|
|
standings: formattedStandings,
|
|
progressionData,
|
|
seasonComplete,
|
|
completionPercentage,
|
|
recentScoreEvents: enrichedScoreEvents,
|
|
};
|
|
} catch (error) {
|
|
logger.error("Error loading standings:", error);
|
|
logger.error("Error details:", {
|
|
message: error instanceof Error ? error.message : String(error),
|
|
stack: error instanceof Error ? error.stack : undefined,
|
|
});
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export default function LeagueStandings() {
|
|
const { league, season, standings, progressionData, seasonComplete, completionPercentage, recentScoreEvents } = useLoaderData<typeof loader>();
|
|
|
|
const isTied = buildTiedRankChecker(standings.map((s) => s.currentRank));
|
|
const previewEntries = standings.map((s) => ({
|
|
teamId: s.teamId,
|
|
teamName: s.teamName,
|
|
ownerName: s.ownerName,
|
|
displayRank: getDisplayRank(s, standings.length, isTied(s.currentRank)),
|
|
currentRank: s.currentRank,
|
|
points: s.totalPoints,
|
|
rankChange: s.rankChange,
|
|
pointChange: s.sevenDayPointChange,
|
|
href: `/leagues/${league.id}/standings/${season.id}/teams/${s.teamId}`,
|
|
}));
|
|
|
|
return (
|
|
<div className="container mx-auto py-8 px-4">
|
|
{/* Header */}
|
|
<div className="mb-8">
|
|
<Button variant="ghost" className="mb-4" asChild>
|
|
<Link to={`/leagues/${league.id}`}>
|
|
← Back to League
|
|
</Link>
|
|
</Button>
|
|
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h1 className="text-4xl font-bold mb-2">{league.name}</h1>
|
|
<p className="text-muted-foreground text-lg">
|
|
{season.year} Season Standings
|
|
</p>
|
|
</div>
|
|
<div className="text-right">
|
|
{seasonComplete ? (
|
|
<div className="inline-flex items-center px-3 py-1 rounded-full bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100 text-sm font-medium">
|
|
✓ Season Complete
|
|
</div>
|
|
) : (
|
|
<div className="text-sm text-muted-foreground">
|
|
{completionPercentage}% Complete
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Two-column layout */}
|
|
<div className="grid gap-6 md:grid-cols-3">
|
|
{/* Left: Standings + Point Progression (2/3 width) */}
|
|
<div className="md:col-span-2 space-y-6">
|
|
<StandingsPreview
|
|
entries={previewEntries}
|
|
description={seasonComplete ? "Final Standings" : "Current Standings"}
|
|
/>
|
|
|
|
{progressionData.chartData.length > 0 && (
|
|
<PointProgressionChart
|
|
chartData={progressionData.chartData}
|
|
teams={progressionData.teams}
|
|
/>
|
|
)}
|
|
</div>
|
|
|
|
{/* Right: Recent Scores (1/3 width) */}
|
|
<RecentScoresCard events={recentScoreEvents} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|