brackt/app/components/sport-season/RegularSeasonStandings.tsx

506 lines
18 KiB
TypeScript
Raw Normal View History

Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
import { useId, useState } from "react";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "~/components/ui/card";
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
import { Switch } from "~/components/ui/switch";
import { BarChart3 } from "lucide-react";
import { TeamOwnerBadge } from "~/components/ui/team-owner-badge";
interface StandingRow {
id: string;
participantId: string;
wins: number;
losses: number;
otLosses: number | null;
ties?: number | null;
tablePoints?: number | null;
goalsFor?: number | null;
goalsAgainst?: number | null;
goalDifference?: number | null;
winPct: string | null;
gamesPlayed: number;
gamesBack: string | null;
conference: string | null;
division: string | null;
conferenceRank: number | null;
divisionRank: number | null;
leagueRank: number | null;
streak: string | null;
lastTen: string | null;
homeRecord: string | null;
awayRecord: string | null;
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
syncedAt: Date | string | null;
participant: { id: string; name: string; shortName?: string | null };
}
interface TeamOwnership {
teamName: string;
ownerName: string;
teamId: string;
}
interface Props {
standings: StandingRow[];
teamOwnerships: Record<string, TeamOwnership>;
userParticipantIds: string[];
showOtLosses?: boolean;
showSoccerTable?: boolean;
/** How many teams per conference qualify for playoffs (flat mode only). 0 = no line. */
playoffSpots?: number;
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
/** "flat" = single ranked list per conference (NBA). "nhl-divisions" = div top-3 + wild card. "mlb-divisions" = same structure with 3 WC spots, uses "League" label. */
displayMode?: "flat" | "nhl-divisions" | "mlb-divisions";
}
type RankMode = "conference" | "division" | "index";
interface TableSection {
heading?: string;
rows: StandingRow[];
rankMode: RankMode;
playoffSpots: number;
showDivisionLabel?: boolean;
}
// ─── Formatting ───────────────────────────────────────────────────────────────
function formatWinPct(winPct: string | null, wins: number, gamesPlayed: number): string {
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
if (winPct !== null) {
const pct = parseFloat(winPct);
if (!isNaN(pct)) return pct.toFixed(3);
}
if (gamesPlayed > 0) return (wins / gamesPlayed).toFixed(3);
return "—";
}
function formatGB(gamesBack: string | null): string {
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
if (gamesBack === null) return "—";
const gb = parseFloat(gamesBack);
if (isNaN(gb) || gb === 0) return "—";
return gb % 1 === 0 ? gb.toString() : gb.toFixed(1);
}
function getRank(row: StandingRow, idx: number, mode: RankMode): number {
if (mode === "division") return row.divisionRank ?? idx + 1;
if (mode === "index") return idx + 1;
return row.conferenceRank ?? idx + 1;
}
// ─── Grouping ─────────────────────────────────────────────────────────────────
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
type ConferenceGroup = { conference: string; conferenceLabel: string; sections: TableSection[] };
function buildFlatSections(
standings: StandingRow[],
playoffSpots: number
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
): ConferenceGroup[] {
const hasConferences = standings.some((s) => s.conference);
if (!hasConferences) {
return [
{
conference: "",
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
conferenceLabel: "Conference",
sections: [
{
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
rows: [...standings].toSorted(
(a, b) => (a.leagueRank ?? 99) - (b.leagueRank ?? 99)
),
rankMode: "conference",
playoffSpots,
},
],
},
];
}
const confMap = new Map<string, StandingRow[]>();
for (const row of standings) {
const conf = row.conference ?? "Other";
if (!confMap.has(conf)) confMap.set(conf, []);
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
confMap.get(conf)?.push(row);
}
return Array.from(confMap.entries()).map(([conference, rows]) => ({
conference,
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
conferenceLabel: "Conference",
sections: [
{
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
rows: [...rows].toSorted(
(a, b) =>
(a.conferenceRank ?? a.leagueRank ?? 99) -
(b.conferenceRank ?? b.leagueRank ?? 99)
),
rankMode: "conference" as RankMode,
playoffSpots,
showDivisionLabel: true,
},
],
}));
}
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
/**
* Shared builder for division-based display modes (NHL and MLB).
* `divisionSpots`: how many teams per division qualify directly (3 for NHL, 1 for MLB).
* `wcSpots`: how many wildcard slots exist per conference (2 for NHL, 3 for MLB).
* `conferenceLabel`: the word shown after the conference name in the heading.
*/
function buildDivisionSections(
standings: StandingRow[],
divisionSpots: number,
wcSpots: number,
conferenceLabel: string
): ConferenceGroup[] {
const confMap = new Map<string, StandingRow[]>();
for (const row of standings) {
const conf = row.conference ?? "Other";
if (!confMap.has(conf)) confMap.set(conf, []);
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
confMap.get(conf)?.push(row);
}
return Array.from(confMap.entries()).map(([conference, rows]) => {
const divMap = new Map<string, StandingRow[]>();
for (const row of rows) {
const div = row.division ?? "";
if (!divMap.has(div)) divMap.set(div, []);
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
divMap.get(div)?.push(row);
}
const divisions = Array.from(divMap.entries())
.map(([name, divRows]) => ({
name,
qualifiers: divRows
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
.filter((r) => (r.divisionRank ?? 99) <= divisionSpots)
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
.toSorted((a, b) => (a.divisionRank ?? 99) - (b.divisionRank ?? 99)),
}))
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
.toSorted(
(a, b) =>
(a.qualifiers[0]?.conferenceRank ?? 99) -
(b.qualifiers[0]?.conferenceRank ?? 99)
);
const wildCard = rows
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
.filter((r) => (r.divisionRank ?? 99) > divisionSpots)
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
.toSorted(
(a, b) =>
(a.conferenceRank ?? a.leagueRank ?? 99) -
(b.conferenceRank ?? b.leagueRank ?? 99)
);
const sections: TableSection[] = [
...divisions.map((div) => ({
heading: `${div.name} Division`,
rows: div.qualifiers,
rankMode: "division" as RankMode,
playoffSpots: 0,
showDivisionLabel: false,
})),
...(wildCard.length > 0
? [
{
heading: "Wild Card",
rows: wildCard,
rankMode: "index" as RankMode,
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
playoffSpots: wcSpots,
showDivisionLabel: true,
},
]
: []),
];
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
return { conference, conferenceLabel, sections };
});
}
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
function buildNhlSections(standings: StandingRow[]): ConferenceGroup[] {
return buildDivisionSections(standings, 3, 2, "Conference");
}
function buildMlbSections(standings: StandingRow[]): ConferenceGroup[] {
return buildDivisionSections(standings, 1, 3, "League");
}
// ─── Single table that renders all sections ───────────────────────────────────
function StandingsTable({
sections,
teamOwnerships,
userParticipantIds,
showOtLosses,
showSoccerTable = false,
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
showStats,
}: {
sections: TableSection[];
teamOwnerships: Record<string, TeamOwnership>;
userParticipantIds: string[];
showOtLosses: boolean;
showSoccerTable?: boolean;
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
showStats: boolean;
}) {
Fix MLB streak doubling bug, hide empty standings columns, improve mobile layout (#413) * Fix MLB streak doubling bug, hide empty standings columns, improve mobile layout - mlb.ts: use streakCode alone (the API already returns the full string like "W3"); appending streakNumber was doubling the digit, causing "L33" display - Update mlb.test.ts mocks to match real API format (streakCode "W3" not "W") - RegularSeasonStandings: conditionally hide GB/L10/STK columns when no rows have data, so pre-season or stats-free sports don't show blank columns - Mobile two-row layout: GP/PCT/GB/L10 move to a secondary sub-row (sm:hidden) so all data stays visible without horizontal scroll on small screens; STK and W/L remain on the primary row; reduce min-w from 740px to 360px https://claude.ai/code/session_01RADi3LhYMPbRDm5no1ZpdF * Address code review: cleanup mlb streak type, fix soccer GP on mobile, hoist showSubRow - mlb.ts: drop redundant `?? undefined` after optional chain; document that streakCode is the full string (e.g. "W3") and streakNumber is unused - RegularSeasonStandings: hoist hasSecondaryStats → showSubRow to component level (it only depends on a prop, not on individual row data) - Remove non-functional `truncate`/`min-w-0` from team name cell — truncation requires table-layout:fixed which we don't use; team names size naturally - Soccer GP was hidden on mobile with no sub-row to surface it; GP now shows inline for soccer on all viewports, hidden only for non-soccer (which has the secondary sub-row) - Add comment explaining totalCols counts hidden-on-mobile columns for colSpan - Add missing test for GB column hiding when no rows have gamesBack data https://claude.ai/code/session_01RADi3LhYMPbRDm5no1ZpdF --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-05-12 08:14:34 -07:00
const allRows = sections.flatMap((s) => s.rows);
const hasStreak = allRows.some((r) => r.streak !== null);
const hasLastTen = allRows.some((r) => r.lastTen !== null);
const hasGB = allRows.some((r) => r.gamesBack !== null);
Fix MLB streak doubling bug, hide empty standings columns, improve mobile layout (#413) * Fix MLB streak doubling bug, hide empty standings columns, improve mobile layout - mlb.ts: use streakCode alone (the API already returns the full string like "W3"); appending streakNumber was doubling the digit, causing "L33" display - Update mlb.test.ts mocks to match real API format (streakCode "W3" not "W") - RegularSeasonStandings: conditionally hide GB/L10/STK columns when no rows have data, so pre-season or stats-free sports don't show blank columns - Mobile two-row layout: GP/PCT/GB/L10 move to a secondary sub-row (sm:hidden) so all data stays visible without horizontal scroll on small screens; STK and W/L remain on the primary row; reduce min-w from 740px to 360px https://claude.ai/code/session_01RADi3LhYMPbRDm5no1ZpdF * Address code review: cleanup mlb streak type, fix soccer GP on mobile, hoist showSubRow - mlb.ts: drop redundant `?? undefined` after optional chain; document that streakCode is the full string (e.g. "W3") and streakNumber is unused - RegularSeasonStandings: hoist hasSecondaryStats → showSubRow to component level (it only depends on a prop, not on individual row data) - Remove non-functional `truncate`/`min-w-0` from team name cell — truncation requires table-layout:fixed which we don't use; team names size naturally - Soccer GP was hidden on mobile with no sub-row to surface it; GP now shows inline for soccer on all viewports, hidden only for non-soccer (which has the secondary sub-row) - Add comment explaining totalCols counts hidden-on-mobile columns for colSpan - Add missing test for GB column hiding when no rows have gamesBack data https://claude.ai/code/session_01RADi3LhYMPbRDm5no1ZpdF --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-05-12 08:14:34 -07:00
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
// # Team [GP] W [D] L [GF GA GD PTS] [OTL PTS] [PCT] [GB] [L10] [STK] Mgr
// Stats columns (GP, PCT, GB, L10, STK) are toggled by showStats.
return (
<div className="overflow-x-auto -mx-6 px-6">
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
<table className="w-full text-sm">
<thead>
<tr className="text-xs text-muted-foreground uppercase tracking-wide border-b">
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
<th className="text-left py-1.5 pl-2 pr-2 w-8">#</th>
<th className="text-left py-1.5">Team</th>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats) && <th className="text-right py-1.5 px-2 w-10">GP</th>}
<th className="text-right py-1.5 px-2 w-8">W</th>
{showSoccerTable && <th className="text-right py-1.5 px-2 w-8">D</th>}
<th className="text-right py-1.5 px-2 w-8">L</th>
{showSoccerTable && <th className="text-right py-1.5 px-2 w-10">GF</th>}
{showSoccerTable && <th className="text-right py-1.5 px-2 w-10">GA</th>}
{showSoccerTable && <th className="text-right py-1.5 px-2 w-10">GD</th>}
{showSoccerTable && <th className="text-right py-1.5 px-2 w-10">PTS</th>}
{showOtLosses && <th className="text-right py-1.5 px-2 w-10">OTL</th>}
{showOtLosses && <th className="text-right py-1.5 px-2 w-10">PTS</th>}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats) && <th className="text-right py-1.5 px-2 w-12">PCT</th>}
{(!showSoccerTable && showStats && hasGB) && <th className="text-right py-1.5 px-2 w-10">GB</th>}
{(!showSoccerTable && showStats && hasLastTen) && <th className="text-right py-1.5 px-2 w-12">L10</th>}
{(!showSoccerTable && showStats && hasStreak) && <th className="text-right py-1.5 px-2 w-12">STK</th>}
<th className="hidden sm:table-cell text-right py-1.5 pl-4 w-40">Mgr</th>
</tr>
</thead>
<tbody>
{sections.flatMap((section, sIdx) => {
const sectionRows: React.ReactNode[] = [];
let playoffLineShown = false;
if (section.heading) {
sectionRows.push(
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
<tr key={`h-${section.heading}`}>
<td
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
colSpan={100}
className={`text-xs font-medium text-muted-foreground/60 uppercase tracking-wider pb-1 ${
sIdx > 0 ? "pt-5" : "pt-2"
}`}
>
{section.heading}
</td>
</tr>
);
}
section.rows.forEach((row, i) => {
const rank = getRank(row, i, section.rankMode);
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
const nextRow = section.rows[i + 1];
const nextRank = nextRow ? getRank(nextRow, i + 1, section.rankMode) : null;
const isLastBeforePlayoffLine =
section.playoffSpots > 0 &&
rank <= section.playoffSpots &&
nextRank !== null &&
nextRank > section.playoffSpots;
if (!playoffLineShown && section.playoffSpots > 0 && rank > section.playoffSpots) {
playoffLineShown = true;
sectionRows.push(
<tr key={`pl-${sIdx}`}>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
<td colSpan={100} className="py-0.5">
<div className="flex w-full items-center gap-2">
<div className="flex-1 border-t border-dashed border-amber-500/40" />
<span className="text-[10px] text-amber-600/70 dark:text-amber-500/70 uppercase tracking-wide whitespace-nowrap font-medium px-1">
Playoff Line
</span>
<div className="flex-1 border-t border-dashed border-amber-500/40" />
</div>
</td>
</tr>
);
}
const isUserTeam = userParticipantIds.includes(row.participantId);
const ownership = teamOwnerships[row.participantId];
sectionRows.push(
<tr
key={row.id}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
className={`${isLastBeforePlayoffLine ? "" : "border-b border-border/50 last:border-0"} ${
isUserTeam ? "bg-primary/5" : "hover:bg-muted/30"
}`}
>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
<td className="py-2 pl-2 pr-2 text-muted-foreground tabular-nums">{rank}</td>
<td className="py-2">
<span className={`font-medium ${isUserTeam ? "text-primary" : ""}`}>
{row.participant.shortName ?? row.participant.name}
</span>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{ownership && (
<div className="sm:hidden mt-0.5">
<TeamOwnerBadge
teamName={ownership.teamName}
ownerName={ownership.ownerName || undefined}
/>
</div>
)}
</td>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats) && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">
{row.gamesPlayed}
</td>
)}
<td className="py-2 px-2 text-right tabular-nums font-medium">{row.wins}</td>
{showSoccerTable && (
<td className="py-2 px-2 text-right tabular-nums">{row.ties ?? 0}</td>
)}
<td className="py-2 px-2 text-right tabular-nums">{row.losses}</td>
{showSoccerTable && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">{row.goalsFor ?? "—"}</td>
)}
{showSoccerTable && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">{row.goalsAgainst ?? "—"}</td>
)}
{showSoccerTable && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">{row.goalDifference ?? "—"}</td>
)}
{showSoccerTable && (
<td className="py-2 px-2 text-right tabular-nums font-medium">{row.tablePoints ?? row.wins * 3 + (row.ties ?? 0)}</td>
)}
{showOtLosses && (
<td className="py-2 px-2 text-right tabular-nums">{row.otLosses ?? 0}</td>
)}
{showOtLosses && (
<td className="py-2 px-2 text-right tabular-nums font-medium">
{row.wins * 2 + (row.otLosses ?? 0)}
</td>
)}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats) && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">
{formatWinPct(row.winPct, row.wins, row.gamesPlayed)}
</td>
)}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats && hasGB) && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">
{formatGB(row.gamesBack)}
</td>
)}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats && hasLastTen) && (
<td className="py-2 px-2 text-right tabular-nums text-muted-foreground">
{row.lastTen ?? "—"}
</td>
)}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{(!showSoccerTable && showStats && hasStreak) && (
<td className="py-2 px-2 text-right tabular-nums">
{row.streak ? (
<span
className={
row.streak.startsWith("W")
? "text-emerald-500"
: "text-destructive/80"
}
>
{row.streak}
</span>
) : (
<span className="text-muted-foreground"></span>
)}
</td>
)}
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
<td className="hidden sm:table-cell py-2 pl-4 text-right">
{ownership ? (
<div className="flex justify-end">
<TeamOwnerBadge
teamName={ownership.teamName}
ownerName={ownership.ownerName || undefined}
align="right"
/>
</div>
) : (
<span className="text-xs text-muted-foreground"></span>
)}
</td>
</tr>
);
});
return sectionRows;
})}
</tbody>
</table>
</div>
);
}
// ─── Main export ──────────────────────────────────────────────────────────────
export function RegularSeasonStandings({
standings,
teamOwnerships,
userParticipantIds,
showOtLosses = false,
showSoccerTable = false,
playoffSpots = 8,
displayMode = "flat",
}: Props) {
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
const switchId = useId();
const [showStats, setShowStats] = useState(false);
if (standings.length === 0) return null;
const lastSyncedAt = standings
.map((s) => s.syncedAt)
.filter(Boolean)
Add oxlint linting setup with zero errors (#194) * Add oxlint and fix all lint errors - Install oxlint, add .oxlintrc.json with rules for TypeScript/React - Add npm run lint / lint:fix scripts - Add Claude PostToolUse hook to run oxlint on every edited file - Fix 101 errors: unused vars/imports, eqeqeq, prefer-const, no-new-array - Fix no-array-index-key (use stable keys or suppress positional cases) - Fix exhaustive-deps missing dependency in useEffect - Promote exhaustive-deps and no-array-index-key to errors - Fix Map.get() !== null bug in $leagueId.server.ts (should be !== undefined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix no-explicit-any warnings and upgrade tsconfig to ES2023 - Replace all `any` types with proper types or `unknown` across ~20 files - Add typed socket payload interfaces in draft route and useDraftSocket - Use any[] with eslint-disable for socket.io callbacks (legitimate escape hatch) - Bump all tsconfigs from ES2022 → ES2023 to support toSorted/toReversed - Fix cascading type errors uncovered by removing any: Map.get narrowing, participant relation types, ChartDataPoint, Partial<NewSeason> indexing - Add ParticipantResultWithParticipant type to participant-result model - Fix test fixtures to match updated interfaces (DraftCell, ParticipantResult) - Fix duplicate getQPStandings import in sportsSeasonId.server.ts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Promote no-explicit-any to error Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 09:44:05 -07:00
.toSorted()
.at(-1);
const groups =
displayMode === "nhl-divisions"
? buildNhlSections(standings)
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
: displayMode === "mlb-divisions"
? buildMlbSections(standings)
: buildFlatSections(standings, playoffSpots);
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
const tableProps = { teamOwnerships, userParticipantIds, showOtLosses, showSoccerTable, showStats };
return (
<Card>
<CardHeader>
<div className="flex items-center justify-between gap-2">
<CardTitle className="flex items-center gap-2">
<BarChart3 className="h-5 w-5" />
Regular Season Standings
</CardTitle>
{lastSyncedAt && (
<CardDescription className="text-xs tabular-nums">
Updated {new Date(lastSyncedAt).toLocaleDateString()}
</CardDescription>
)}
</div>
</CardHeader>
<CardContent>
Fix standings table bugs and polish across all three scoring patterns (#415) * Fix standings table bugs and polish across all three scoring patterns - Fix isLastBeforePointsLine/PlayoffLine: was incorrectly suppressing the bottom border on the last row of a section when no divider followed (nextStanding === undefined case). Now correctly requires nextStanding to exist and exceed the cutoff rank. - Fix totalCols colSpan overcounting: hidden sm:table-cell columns (Drafted By / Mgr) don't occupy column slots on mobile, so counting them caused the divider rows to span one too many. Replaced with colSpan={100} (browser caps to actual column count). - Move pointsLinePushed mutation out of render in SeasonStandings and QualifyingPointsStandings: replaced let+mutation+array-push pattern with pre-computed firstOver8Idx and React.Fragment per row. - Replace array-returning .map() with keyed React.Fragment in both files. - Remove unused description prop from SeasonStandingsProps. - Use useId() for Switch id props in all three components to prevent id collisions when mounted multiple times. - Fix formatQP NaN fallback from "0" to "—". - Add comment noting canFinalize guards the admin-only finalize UI. - Drop dead description prop pass-through in SportSeasonDisplay. Fixes #408 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix RegularSeasonStandings tests broken by showStats toggle - STK/streak tests: click the Details switch before asserting on stats columns, which are now hidden behind the toggle by default - Ownership badge test: use getAllByText since the badge renders in both the mobile inline slot and the hidden-sm desktop Mgr cell - Division label test: remove expectation for inline per-row division labels, which were intentionally removed to fix mobile scroll Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:39:25 -07:00
{!showSoccerTable && (
<div className="flex items-center justify-end gap-2 mb-2">
<label className="text-xs text-muted-foreground cursor-pointer" htmlFor={switchId}>
Details
</label>
<Switch
id={switchId}
checked={showStats}
onCheckedChange={setShowStats}
/>
</div>
)}
{groups.map((group) => (
<div key={group.conference} className="mb-6 last:mb-0">
{group.conference && (
<h3 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide mb-3">
Add MLB playoff simulator with AL/NL division standings, fixes #121 (#225) * Add MLB playoff simulator with AL/NL division standings, fixes #121 - New `mlb-simulator.ts`: 50k Monte Carlo sim drawing division winners (weighted by p_div) and 3 WC teams per league, then simulating WC best-of-3 → DS best-of-5 → LCS best-of-7 → World Series. Elo parity factor 350; blends Vegas odds 30/70 when sourceOdds available. - New `standings-sync/mlb.ts`: adapter for free statsapi.mlb.com API, mapping AL/NL conferences, division ranks, streaks, home/away/L10 splits. - New `mlb-divisions` display mode in RegularSeasonStandings: shows 1 division winner per division section + Wild Card section with 3-spot playoff line, headings read "AL/NL League" instead of "Conference". - Refactored buildNhlSections/buildMlbSections into shared buildDivisionSections (divisionSpots + wcSpots params); conferenceLabel now flows through group objects rather than being derived from displayMode in the render. - DB migration 0062 adds `mlb_bracket` to simulator_type enum. - 37 new tests across simulator, adapter, and component. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix flaky tennis simulator test: increase trials and lower threshold 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 08:47:02 -07:00
{group.conference} {group.conferenceLabel}
</h3>
)}
<StandingsTable sections={group.sections} {...tableProps} />
</div>
))}
</CardContent>
</Card>
);
}