Extracts 9 domain components from new.tsx and $leagueId.settings.tsx into app/components/league/ (each with a Storybook story), consolidates wizard form-building into wizard-state.ts, and updates the settings page to use the shared components instead of hand-rolled duplicates. new.tsx shrinks from ~2000 → ~1280 lines. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import type { ScoringRules } from "~/lib/scoring-types";
|
|
|
|
export const WIZARD_SS_KEY = "brackt_new_league_wizard";
|
|
|
|
export type WizardSnapshot = {
|
|
leagueName: string;
|
|
teamCount: number;
|
|
joinAsPlayer: boolean;
|
|
selectedTemplate: string;
|
|
selectedSports: string[];
|
|
draftRounds: number;
|
|
draftDate: string;
|
|
draftTime: string;
|
|
timerMode: "chess_clock" | "standard";
|
|
draftSpeed: string;
|
|
overnightMode: "none" | "league" | "per_user";
|
|
overnightStart: string;
|
|
overnightEnd: string;
|
|
overnightTimezone: string;
|
|
scoringPreset: "brackt" | "omnifantasy" | "custom";
|
|
scoringRules: ScoringRules;
|
|
userTimezone: string;
|
|
};
|
|
|
|
type SS = { getItem(k: string): string | null; setItem(k: string, v: string): void; removeItem(k: string): void };
|
|
|
|
function ss(): SS | null {
|
|
const g = globalThis as Record<string, unknown>;
|
|
return (typeof g["sessionStorage"] !== "undefined" ? g["sessionStorage"] : null) as SS | null;
|
|
}
|
|
|
|
export function saveWizardState(snapshot: WizardSnapshot) {
|
|
try { ss()?.setItem(WIZARD_SS_KEY, JSON.stringify(snapshot)); } catch {}
|
|
}
|
|
|
|
export function loadWizardState(): WizardSnapshot | null {
|
|
try {
|
|
const raw = ss()?.getItem(WIZARD_SS_KEY);
|
|
return raw ? (JSON.parse(raw) as WizardSnapshot) : null;
|
|
} catch { return null; }
|
|
}
|
|
|
|
export function clearWizardState() {
|
|
try { ss()?.removeItem(WIZARD_SS_KEY); } catch {}
|
|
}
|
|
|
|
export function buildFormDataFromSnapshot(s: WizardSnapshot): FormData {
|
|
const fd = new FormData();
|
|
fd.append("name", s.leagueName);
|
|
fd.append("teamCount", s.teamCount.toString());
|
|
fd.append("templateId", s.selectedTemplate);
|
|
fd.append("draftRounds", s.draftRounds.toString());
|
|
if (s.draftDate && s.draftTime) {
|
|
fd.append("draftDateTime", new Date(`${s.draftDate}T${s.draftTime}`).toISOString());
|
|
}
|
|
fd.append("draftTimerMode", s.timerMode);
|
|
fd.append("draftSpeed", s.draftSpeed);
|
|
fd.append("overnightPauseMode", s.overnightMode);
|
|
if (s.overnightMode !== "none") {
|
|
fd.append("overnightPauseStart", s.overnightStart);
|
|
fd.append("overnightPauseEnd", s.overnightEnd);
|
|
fd.append("overnightPauseTimezone", s.overnightTimezone);
|
|
}
|
|
(["pointsFor1st", "pointsFor2nd", "pointsFor3rd", "pointsFor4th",
|
|
"pointsFor5th", "pointsFor6th", "pointsFor7th", "pointsFor8th"] as const
|
|
).forEach((k) => fd.append(k, s.scoringRules[k].toString()));
|
|
for (const id of s.selectedSports) fd.append("sportsSeasons", id);
|
|
if (s.joinAsPlayer) fd.append("joinAsPlayer", "on");
|
|
if (s.userTimezone) fd.append("userTimezone", s.userTimezone);
|
|
return fd;
|
|
}
|