diff --git a/app/routes/admin.sports-seasons.$id.simulate.tsx b/app/routes/admin.sports-seasons.$id.simulate.tsx index 5dace5c..49dce26 100644 --- a/app/routes/admin.sports-seasons.$id.simulate.tsx +++ b/app/routes/admin.sports-seasons.$id.simulate.tsx @@ -1,24 +1,13 @@ /** - * Admin: Run EV Simulation for a Sports Season + * Admin: Simulate action endpoint (stub) * - * Action-only route. POSTing here: - * 1. Delegates validation + execution to the shared simulator runner - * 6. Redirects back to the sports season admin page + * Simulation is now handled by intent="simulate" on the season admin page. + * This stub redirects any direct GET navigation to that page. */ import { redirect } from "react-router"; import type { Route } from "./+types/admin.sports-seasons.$id.simulate"; -import { runSportsSeasonSimulation } from "~/services/simulations/runner"; -export async function action({ params }: Route.ActionArgs) { - const sportsSeasonId = params.id; - try { - await runSportsSeasonSimulation(sportsSeasonId); - } catch (error) { - throw new Response(error instanceof Error ? error.message : "Simulation failed", { - status: error instanceof Error && error.message.includes("already running") ? 409 : 400, - }); - } - - return redirect(`/admin/sports-seasons/${sportsSeasonId}/expected-values`); +export async function loader({ params }: Route.LoaderArgs) { + return redirect(`/admin/sports-seasons/${params.id}`); } diff --git a/app/routes/admin.sports-seasons.$id.tsx b/app/routes/admin.sports-seasons.$id.tsx index fb84899..43aab95 100644 --- a/app/routes/admin.sports-seasons.$id.tsx +++ b/app/routes/admin.sports-seasons.$id.tsx @@ -11,6 +11,7 @@ import { database } from "~/database/context"; import { participantEvSnapshots, seasonSports } from "~/database/schema"; import { eq, desc } from "drizzle-orm"; import { getSimulatorInfo, type SimulatorType } from "~/services/simulations/registry"; +import { runSportsSeasonSimulation } from "~/services/simulations/runner"; import { syncStandings } from "~/services/standings-sync/index"; import { getPendingStandingsMappings, @@ -280,6 +281,17 @@ export async function action(args: Route.ActionArgs) { } } + if (intent === "simulate") { + try { + await runSportsSeasonSimulation(params.id); + return redirect(`/admin/sports-seasons/${params.id}/expected-values`); + } catch (error) { + return { + simulateError: error instanceof Error ? error.message : "Simulation failed", + }; + } + } + // Update const name = formData.get("name"); const year = formData.get("year"); @@ -669,7 +681,8 @@ export default function EditSportsSeason({ loaderData, actionData }: Route.Compo )} {simulatorInfo && ( -