## Summary - **Group stage match list**: Removed MD 1/2/3 headings; matches now listed chronologically under date separators (e.g. "Jun 14"). Kick-off time appears below the team names instead of between them. - **Sort order**: \`findMatchesByGroupIds\` / \`findMatchesByEventId\` now order by \`scheduledAt ASC NULLS LAST\` so unscheduled matches always trail scheduled ones. - **Groups/Bracket toggle**: When both group stage and knockout bracket exist, a toggle appears (mirroring the NBA/AFL standings toggle). Sports with both regular-season standings and a group stage get all views available. - **Upcoming events**: \`getUpcomingEventsForDraftedParticipants\` now also queries \`groupStageMatches\`, so World Cup group fixtures appear on the home page calendar sorted by kick-off time with a label like "Group A — France vs Germany". - **\`isAllCompete\` fix**: \`UpcomingEventsCard\` and \`UpcomingCalendarPanel\` now treat \`group_stage_match\` as a bracket-style event, showing team badges instead of "N of your picks". Fixes #53 ## Test plan - [ ] Navigate to a World Cup sports season page — groups should be listed chronologically under date headers with no MD labels; kick-off time should appear below each match row - [ ] Once the knockout bracket has matches, confirm the Groups/Bracket toggle appears and both views render correctly - [ ] On the home page, a user with drafted World Cup participants should see upcoming group fixtures in the calendar panel with individual team badges (not a participant count) - [ ] NBA/AFL/NHL pages unaffected — their standings/playoffs/finished toggle still works normally - [ ] \`npm run typecheck\` and \`npm run test:run\` pass Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: #55
228 lines
8.3 KiB
TypeScript
228 lines
8.3 KiB
TypeScript
import { Link } from "react-router";
|
|
import { useState } from "react";
|
|
import type { Route } from "./+types/$leagueId.sports-seasons.$sportsSeasonId";
|
|
|
|
import { loader } from "./$leagueId.sports-seasons.$sportsSeasonId.server";
|
|
import { SportSeasonDisplay } from "~/components/scoring/SportSeasonDisplay";
|
|
import { EventSchedule } from "~/components/sport-season/EventSchedule";
|
|
import { RegularSeasonStandings } from "~/components/sport-season/RegularSeasonStandings";
|
|
import { GroupStageStandings } from "~/components/sport-season/GroupStageStandings";
|
|
import { Button } from "~/components/ui/button";
|
|
import { cn } from "~/lib/utils";
|
|
import { ArrowLeft } from "lucide-react";
|
|
|
|
export function meta({ data }: Route.MetaArgs): Route.MetaDescriptors {
|
|
return [{ title: `${data?.sportsSeason?.name ?? "Sport Season"} — ${data?.league?.name ?? "League"} - Brackt` }];
|
|
}
|
|
|
|
export { loader };
|
|
|
|
type BracketView = "standings" | "playoffs" | "finished" | "groups";
|
|
|
|
export default function SportSeasonDetail({
|
|
loaderData,
|
|
}: Route.ComponentProps) {
|
|
const {
|
|
league,
|
|
season,
|
|
sportsSeason,
|
|
scoringPattern,
|
|
playoffMatches,
|
|
playoffRounds,
|
|
preEliminatedParticipants,
|
|
participantPoints,
|
|
partialScoreParticipantIds,
|
|
seasonStandings,
|
|
qpStandings,
|
|
teamOwnerships,
|
|
userParticipantIds,
|
|
upcomingEvents,
|
|
recentEvents,
|
|
seasonIsFinalized,
|
|
regularSeasonStandings,
|
|
|
|
groupStandings,
|
|
bracketTemplateId,
|
|
} = loaderData;
|
|
|
|
const hasBracket = playoffMatches && playoffMatches.length > 0;
|
|
const hasStandings = regularSeasonStandings && regularSeasonStandings.length > 0;
|
|
const showOtLosses = hasStandings && regularSeasonStandings.some((s) => s.otLosses !== null);
|
|
|
|
const simulatorType = sportsSeason.sport?.simulatorType;
|
|
const standingsDisplayMode =
|
|
simulatorType === "nhl_bracket" ? "nhl-divisions" :
|
|
simulatorType === "mlb_bracket" ? "mlb-divisions" :
|
|
"flat";
|
|
const playoffSpots =
|
|
simulatorType === "nba_bracket" || simulatorType === "afl_bracket" ? 10 :
|
|
simulatorType === "mls_bracket" ? 9 :
|
|
8;
|
|
|
|
const ownershipMap = Object.fromEntries(
|
|
teamOwnerships.map((o) => [
|
|
o.participantId,
|
|
{ teamName: o.teamName, ownerName: o.ownerName ?? "", teamId: o.teamId },
|
|
])
|
|
);
|
|
|
|
// Show the 3-way toggle for bracket sports with regular season standings (NBA/AFL/etc.)
|
|
const showToggle = hasStandings && scoringPattern === "playoff_bracket";
|
|
// Show Groups/Bracket toggle for tournaments with a group stage AND a knockout bracket.
|
|
// Independent of showToggle — a sport can have both standings and group stage.
|
|
const hasGroupStage = groupStandings.length > 0;
|
|
const showGroupStageToggle = hasGroupStage && hasBracket;
|
|
const showAnyToggle = showToggle || showGroupStageToggle;
|
|
|
|
const [view, setView] = useState<BracketView>(() => {
|
|
if (showGroupStageToggle) {
|
|
return sportsSeason.status === "completed" ? "finished" : "playoffs";
|
|
}
|
|
if (!hasBracket) return "standings";
|
|
if (sportsSeason.status === "completed") return "finished";
|
|
return "playoffs";
|
|
});
|
|
|
|
const TOGGLE_VIEWS: { value: BracketView; label: string }[] = showGroupStageToggle
|
|
? [
|
|
{ value: "groups", label: "Groups" },
|
|
...(showToggle ? [{ value: "standings" as BracketView, label: "Standings" }] : []),
|
|
{ value: "playoffs", label: "Bracket" },
|
|
...(sportsSeason.status === "completed" ? [{ value: "finished" as BracketView, label: "Final" }] : []),
|
|
]
|
|
: [
|
|
{ value: "standings", label: "Standings" },
|
|
{ value: "playoffs", label: "Playoffs" },
|
|
{ value: "finished", label: "Finished" },
|
|
];
|
|
|
|
const bracketDisplay = (bracketMode: "bracket" | "rankings") => (
|
|
<SportSeasonDisplay
|
|
scoringPattern={scoringPattern as "playoff_bracket" | "season_standings" | "qualifying_points"}
|
|
sportSeasonName={sportsSeason.name}
|
|
sportName={sportsSeason.sport.name}
|
|
bracketMode={bracketMode}
|
|
playoffMatches={playoffMatches}
|
|
playoffRounds={playoffRounds}
|
|
bracketTemplateId={bracketTemplateId}
|
|
preEliminatedParticipants={preEliminatedParticipants}
|
|
participantPoints={participantPoints}
|
|
partialScoreParticipantIds={partialScoreParticipantIds}
|
|
seasonStandings={seasonStandings}
|
|
seasonIsFinalized={seasonIsFinalized}
|
|
qpStandings={qpStandings}
|
|
qpIsFinalized={sportsSeason.qualifyingPointsFinalized || false}
|
|
totalMajors={sportsSeason.totalMajors}
|
|
majorsCompleted={sportsSeason.majorsCompleted || 0}
|
|
canFinalize={
|
|
(sportsSeason.majorsCompleted || 0) >=
|
|
(sportsSeason.totalMajors || 0) &&
|
|
!sportsSeason.qualifyingPointsFinalized
|
|
}
|
|
teamOwnerships={teamOwnerships}
|
|
userParticipantIds={userParticipantIds}
|
|
scoringRules={season}
|
|
showOwnership={true}
|
|
/>
|
|
);
|
|
|
|
const standingsDisplay = (
|
|
<RegularSeasonStandings
|
|
standings={regularSeasonStandings}
|
|
teamOwnerships={ownershipMap}
|
|
userParticipantIds={userParticipantIds}
|
|
showOtLosses={showOtLosses}
|
|
showSoccerTable={simulatorType === "epl_standings" || simulatorType === "mls_bracket"}
|
|
displayMode={standingsDisplayMode as "flat" | "nhl-divisions" | "mlb-divisions"}
|
|
playoffSpots={playoffSpots}
|
|
/>
|
|
);
|
|
|
|
return (
|
|
<div className="container mx-auto py-8 px-4">
|
|
<div className="mb-6">
|
|
<Button variant="ghost" size="sm" asChild className="mb-4">
|
|
<Link to={`/leagues/${league.id}`}>
|
|
<ArrowLeft className="mr-2 h-4 w-4" />
|
|
Back to League
|
|
</Link>
|
|
</Button>
|
|
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between mb-4">
|
|
<div>
|
|
<h1 className="text-3xl font-bold mb-1">
|
|
{sportsSeason.sport.name}
|
|
</h1>
|
|
<p className="text-muted-foreground">
|
|
{sportsSeason.name} • {league.name} • {season.year} Season
|
|
</p>
|
|
</div>
|
|
|
|
{showAnyToggle && (
|
|
<div className="flex gap-1 rounded-lg bg-muted p-1 sm:shrink-0">
|
|
{TOGGLE_VIEWS.map(({ value, label }) => (
|
|
<button
|
|
key={value}
|
|
type="button"
|
|
onClick={() => setView(value)}
|
|
className={cn(
|
|
"flex-1 sm:flex-none px-3 py-1.5 text-sm font-medium rounded-md transition-colors",
|
|
view === value
|
|
? "bg-background shadow-sm text-foreground"
|
|
: "text-muted-foreground hover:text-foreground"
|
|
)}
|
|
>
|
|
{label}
|
|
</button>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{showAnyToggle ? (
|
|
<div>
|
|
{view === "groups" && (
|
|
<GroupStageStandings groups={groupStandings} ownershipMap={ownershipMap} showEmpty={true} />
|
|
)}
|
|
{view === "standings" && standingsDisplay}
|
|
{view === "playoffs" && bracketDisplay("bracket")}
|
|
{view === "finished" && bracketDisplay("rankings")}
|
|
</div>
|
|
) : (
|
|
<>
|
|
{/* Regular season standings above bracket when no bracket exists yet */}
|
|
{hasStandings && !hasBracket && (
|
|
<div className="mb-6">{standingsDisplay}</div>
|
|
)}
|
|
|
|
{/* Event schedule — hidden for bracket sports */}
|
|
{scoringPattern !== "playoff_bracket" &&
|
|
(upcomingEvents.length > 0 || recentEvents.length > 0) && (
|
|
<div className="mb-6">
|
|
<EventSchedule
|
|
upcomingEvents={upcomingEvents}
|
|
recentEvents={recentEvents}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
{/* Group stage standings */}
|
|
{groupStandings.length > 0 && (
|
|
<div className="mb-6">
|
|
<GroupStageStandings groups={groupStandings} ownershipMap={ownershipMap} showEmpty={false} />
|
|
</div>
|
|
)}
|
|
|
|
{/* Bracket — hidden when standings exist but bracket is empty */}
|
|
{!(scoringPattern === "playoff_bracket" && hasStandings && !hasBracket) && bracketDisplay("bracket")}
|
|
|
|
{/* Regular season standings below bracket once bracket exists */}
|
|
{hasStandings && hasBracket && (
|
|
<div className="mt-8">{standingsDisplay}</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|