brackt/app/routes/home.tsx
Chris Parsons 9ed0282fd0
New design (#309)
* 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>
2026-04-23 13:14:55 -07:00

236 lines
8.7 KiB
TypeScript

import { useEffect } from "react";
import { useSearchParams } from "react-router";
import { toast } from "sonner";
import { getAuth } from "@clerk/react-router/server";
import { addDays, subDays } from "date-fns";
import type { Route } from "./+types/home";
import { LandingPage } from "~/components/marketing/LandingPage";
import { findLeaguesWithActiveSeasonsByUserId } from "~/models/league";
import { findSeasonById, findCurrentSeasonWithSports } from "~/models/season";
import { findTeamByOwnerAndSeason } from "~/models/team";
import { getDraftedParticipantsBySportsSeason } from "~/models/draft-pick";
import { getUpcomingEventsForDraftedParticipants } from "~/models/scoring-event";
import { getTeamStanding } from "~/models/standings";
import { getSeasonCompletionPercentage } from "~/lib/season-helpers.server";
import { findDraftSlotsBySeasonId } from "~/models/draft-slot";
import { getTeamForPick } from "~/lib/draft-order";
import type { CalendarPanelEvent } from "~/components/sport-season/UpcomingCalendarPanel";
import { UpcomingEventsCard } from "~/components/sport-season/UpcomingEventsCard";
import { MyLeaguesCard } from "~/components/league/MyLeaguesCard";
import { CreateLeagueCard } from "~/components/league/CreateLeagueCard";
import type { LeagueRowProps } from "~/components/league/LeagueRow";
import { toEventSortKey } from "~/lib/date-utils";
export function meta() {
return [
{ title: "Brackt - Fantasy All of the Sports!" },
{
name: "description",
content: "Play multi-sport fantasy leagues with your friends!",
},
];
}
export async function loader(args: Route.LoaderArgs) {
const { userId } = await getAuth(args);
if (!userId) {
return { leagues: [], isLoggedIn: false, upcomingCalendarEvents: [] };
}
const leagues = await findLeaguesWithActiveSeasonsByUserId(userId);
const today = new Date();
const dateFromStr = subDays(today, 1).toISOString().split("T")[0];
const dateToStr = addDays(today, 30).toISOString().split("T")[0];
const leaguesWithData = await Promise.all(
leagues.map(async (league) => {
const [season, seasonWithSports] = await Promise.all([
league.currentSeasonId ? findSeasonById(league.currentSeasonId) : null,
findCurrentSeasonWithSports(league.id),
]);
const numSports = seasonWithSports?.seasonSports?.length ?? 0;
const calendarEvents: CalendarPanelEvent[] = [];
let currentRank: number | undefined;
let totalPoints: number | undefined;
let previousRank: number | undefined;
let completionPercentage = 0;
let picksUntilMyTurn: number | undefined;
let draftPosition: number | undefined;
if (league.currentSeasonId && seasonWithSports?.seasonSports) {
const myTeam = await findTeamByOwnerAndSeason(userId, league.currentSeasonId);
if (myTeam) {
// Fetch standing, completion %, and calendar events in parallel
const [standing, pct, participantsBySportsSeason] = await Promise.all([
getTeamStanding(myTeam.id, league.currentSeasonId),
getSeasonCompletionPercentage(league.currentSeasonId),
getDraftedParticipantsBySportsSeason(myTeam.id, league.currentSeasonId),
]);
completionPercentage = pct;
// Draft slot info — needed for pre-draft position and in-progress picks-until-turn
if (season?.status === "draft" || season?.status === "pre_draft") {
const draftSlots = await findDraftSlotsBySeasonId(league.currentSeasonId);
const mySlot = draftSlots.find((s) => s.teamId === myTeam.id);
if (mySlot) {
draftPosition = mySlot.draftOrder;
}
if (season.status === "draft" && season.currentPickNumber) {
const currentPick = season.currentPickNumber;
let offset = 0;
// Snake draft: one full cycle is draftSlots.length * 2 picks
while (offset < draftSlots.length * 2) {
const slot = getTeamForPick(currentPick + offset, draftSlots);
if (slot?.teamId === myTeam.id) {
picksUntilMyTurn = offset;
break;
}
offset++;
}
}
}
if (standing) {
currentRank = standing.currentRank ?? undefined;
totalPoints = standing.totalPoints ?? undefined;
previousRank = standing.previousRank ?? undefined;
} else if (myTeam && season?.status === "active") {
// No standing row yet (no scoring events) — default to rank 1, 0 points
currentRank = 1;
totalPoints = 0;
}
const perSeasonEvents = await Promise.all(
seasonWithSports.seasonSports.map(async ({ sportsSeason: ss }) => {
const draftedParticipants = participantsBySportsSeason.get(ss.id) ?? [];
if (draftedParticipants.length === 0) return [];
const events = await getUpcomingEventsForDraftedParticipants(
ss.id,
ss.scoringPattern ?? "",
draftedParticipants,
dateFromStr,
dateToStr
);
return events.map((event) => ({
...event,
sportName: ss.sport.name,
sportSeasonName: ss.name,
leagueName: league.name,
leagueId: league.id,
sportsSeasonPageUrl: `/leagues/${league.id}/sports-seasons/${ss.id}`,
}));
})
);
calendarEvents.push(...perSeasonEvents.flat());
}
}
return {
...league,
currentSeason: season,
numSports,
currentRank,
totalPoints,
previousRank,
completionPercentage,
picksUntilMyTurn,
draftPosition,
draftDateTime: season?.draftDateTime?.toISOString() ?? null,
calendarEvents,
};
})
);
const upcomingCalendarEvents = leaguesWithData
.flatMap((l) => l.calendarEvents)
.toSorted((a, b) => toEventSortKey(a).localeCompare(toEventSortKey(b)));
return {
leagues: leaguesWithData,
isLoggedIn: true,
upcomingCalendarEvents,
};
}
const VALID_STATUSES = ["draft", "active", "pre_draft", "completed"] as const;
type ValidStatus = (typeof VALID_STATUSES)[number];
function isValidStatus(s: string): s is ValidStatus {
return VALID_STATUSES.includes(s as ValidStatus);
}
export default function Home({ loaderData }: Route.ComponentProps) {
const { leagues, isLoggedIn, upcomingCalendarEvents } = loaderData;
const [searchParams, setSearchParams] = useSearchParams();
useEffect(() => {
if (searchParams.get("deleted") === "true") {
toast.success("League deleted successfully");
setSearchParams({});
}
if (searchParams.get("left") === "true") {
toast.success("You have left the league. Your team is now available.");
setSearchParams({});
}
}, [searchParams, setSearchParams]);
if (!isLoggedIn) {
return <LandingPage />;
}
const leagueRows: LeagueRowProps[] = leagues.map((league) => {
const rawStatus = league.currentSeason?.status ?? "pre_draft";
return {
leagueId: league.id,
leagueName: league.name,
numSports: league.numSports,
status: isValidStatus(rawStatus) ? rawStatus : "pre_draft",
seasonId: league.currentSeasonId ?? undefined,
currentRank: league.currentRank,
totalPoints: league.totalPoints,
previousRank: league.previousRank,
completionPercentage: league.completionPercentage,
picksUntilMyTurn: league.picksUntilMyTurn,
draftPosition: league.draftPosition,
draftDateTime: league.draftDateTime,
};
});
return (
<div className="container mx-auto py-8 px-4">
{/*
lg+: 3-col grid, left column (My Leagues + Create) spans 2, right (Events) spans 1.
mobile/tablet: single column stacked in order: My Leagues, Upcoming Events, Create League.
*/}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
{/* My Leagues — order 1 on mobile, col-span-2 on desktop */}
<div className="order-1 lg:col-span-2">
<MyLeaguesCard leagues={leagueRows} />
</div>
{/* Upcoming Events — order 2 on mobile, right column on desktop spanning both rows */}
<div className="order-2 lg:col-span-1 lg:row-span-2">
<UpcomingEventsCard
events={upcomingCalendarEvents}
limit={8}
viewAllUrl="/upcoming-events"
showLeagueAvatar={leagueRows.length > 1}
/>
</div>
{/* Create a League — order 3 on mobile, below My Leagues on desktop */}
<div className="order-3 lg:col-span-2">
<CreateLeagueCard />
</div>
</div>
</div>
);
}