Catalogue des WOD de référence (lot 4d)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-18 15:15:45 +01:00
co-authored by Claude Opus 5.5
parent 35a826ddf0
commit 79ce7b34ac
13 changed files with 325 additions and 5 deletions
+6
View File
@@ -32,6 +32,8 @@
* | {name: "connect-ai", query: string}
* | {name: "library", query: string}
* | {name: "library-item", id: string, query: string}
* | {name: "wods"}
* | {name: "wod", id: string}
* | {name: "reserved"}
* | {name: "not-found"}} Route
*/
@@ -63,6 +65,8 @@ export function parseRoute(hash) {
if (head === "connecter-ia" && parts.length === 1) return { name: "connect-ai", query };
if (head === "bibliotheque" && parts.length === 1) return { name: "library", query };
if (head === "bibliotheque" && parts.length === 2 && arg) return { name: "library-item", id: arg, query };
if (head === "wod" && parts.length === 1) return { name: "wods" };
if (head === "wod" && parts.length === 2 && arg) return { name: "wod", id: arg };
if (parts.length === 1 && WITH_QUERY[head]) return /** @type {Route} */ ({ name: WITH_QUERY[head], query });
if (parts.length === 1 && SIMPLE[head]) return /** @type {Route} */ ({ name: SIMPLE[head] });
return { name: "not-found" };
@@ -116,6 +120,8 @@ export const href = {
sync: () => "#/synchro",
pair: () => "#/relier",
library: (/** @type {string} */ query = "") => "#/bibliotheque" + (query ? "?" + query : ""),
wods: () => "#/wod",
wod: (/** @type {string} */ id) => "#/wod/" + enc(id),
libraryItem: (/** @type {string} */ id, /** @type {string} */ query = "") => "#/bibliotheque/" + enc(id) + (query ? "?" + query : ""),
};
+1
View File
@@ -192,6 +192,7 @@ function homeContent(store, nav, today, synced) {
tile(href.history(), "Historique", plural(state.sessions.length, "séance")),
tile(href.weight(), "Poids", state.weights.length ? `${String(state.weights[state.weights.length - 1].kg).replace(".", ",")} kg` : "première pesée"),
tile(href.library(), "Bibliothèque", "exercices, gestes"),
tile(href.wods(), "WOD", "références, records"),
tile(href.analysis(), "Analyses", "charges, assiduité"),
tile(href.progress(), "Succès", "niveau, records"),
tile(href.activities(), "Activités", plural(program.activities?.length ?? 0, "activité")),
+106
View File
@@ -0,0 +1,106 @@
// Le catalogue des WOD de référence (lot 4d) : la liste, et la fiche d'un WOD avec
// son record, « Faire aujourd'hui » (ajouté au programme comme WOD ponctuel) et
// « Demander à mon IA de l'adapter ». Données : domain/benchmarks.js.
import { h } from "../dom.js";
import { BENCHMARKS, BENCHMARK_FAMILIES, benchmark } from "../../domain/benchmarks.js";
import { formatHint, formatLabel, scoreLabel, wodKey } from "../../domain/wod.js";
import { wodRecords } from "../../domain/analysis.js";
import { pendingOneOffs, resolveExercise, withOneOff } from "../../domain/program.js";
import { buildEvolutionBrief } from "../../domain/ai-brief.js";
import { plural, shortDay } from "../format.js";
import { screenHeader } from "../layout.js";
import { href } from "../router.js";
import { copyText } from "../files.js";
import { toast } from "../feedback.js";
/** @typedef {import("../../domain/benchmarks.js").Benchmark} Benchmark */
/**
* @param {import("../../domain/state.js").State} state
* @param {Benchmark} b
*/
const recordOf = (state, b) => wodRecords(state).find((r) => r.key === wodKey(b.session.name, /** @type {any} */ (b.session.format))) ?? null;
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation}} ctx
* @returns {import("../router.js").Screen}
*/
export function wodCatalogScreen({ store, nav }) {
const state = store.getState();
const node = h("div", { class: "screen" },
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "WOD", title: "Références",
sub: "Les WOD que tout le monde connaît : fais-les, note ton score, et bats ton record la fois suivante." }),
Object.entries(BENCHMARK_FAMILIES).map(([family, label]) => {
const list = BENCHMARKS.filter((b) => b.family === family);
return [
h("h2", { class: "tape" }, label, h("span", { class: "tape__hint" }, String(list.length))),
h("ul", { class: "rows" }, list.map((b) => {
const record = recordOf(state, b);
return h("li", null, h("a", { class: "row", href: href.wod(b.id) },
h("span", { class: "row__main" },
h("span", { class: "row__title" }, `${b.session.name} · ${formatLabel(/** @type {any} */ (b.session.format))}`),
h("span", { class: "row__meta" }, record ? `Record ${scoreLabel(record.best.result)}` : b.summary)),
h("span", { class: "chevron", "aria-hidden": "true" })));
}))];
}));
return { node, title: "WOD de référence" };
}
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, id: string}} ctx
* @returns {import("../router.js").Screen}
*/
export function wodItemScreen({ store, nav, today, id }) {
const b = benchmark(id);
const back = { label: "Références", onClick: () => nav.back(href.wods()) };
if (!b) return { title: "WOD introuvable", node: h("div", { class: "screen" }, screenHeader({ back, title: "Introuvable", sub: "Ce WOD n'est pas dans le catalogue." })) };
const state = store.getState();
const format = /** @type {import("../../domain/wod.js").WodFormat} */ (b.session.format);
const record = recordOf(state, b);
// Déjà ajouté et pas encore fait : on le reprend plutôt que d'en ajouter un autre.
const pending = pendingOneOffs(state.program, state.sessions).find((s) => s.format && wodKey(s.name, s.format) === wodKey(b.session.name, format));
const doToday = () => {
if (pending) return nav.go(href.session(pending.key));
const program = store.getState().program;
if (!program) return;
const { program: next, key } = withOneOff(program, b.session, store.getState().sessions);
store.dispatch("ProgramAdopted", { program: next, source: "app", reason: `WOD de référence ajouté : ${b.session.name}.` });
nav.go(href.session(key));
};
const fallback = h("div", { class: "manual-copy", hidden: true });
const ask = async () => {
const text = buildEvolutionBrief(store.getState(), { today: today(), baseUrl: location.origin }) +
`\n## Ma demande\n\nJ'aimerais faire le WOD de référence « ${b.session.name} » (${formatLabel(format)}) :\n` +
b.session.exercises.map((x) => `- ${x.reps} ${resolveExercise(x).name}${x.note ? ` (${x.note})` : ""}`).join("\n") +
`\n\nAdapte-le à mon niveau, à mon matériel et à mes contraintes (charges, mouvements, volume), en gardant son nom exact pour que l'app suive mon record. Propose-le comme WOD ponctuel (outil propose_wod, ou séance oneOff dans le format ci-dessus).\n`;
if (await copyText(text, fallback, "Texte pour ton IA")) toast("Texte copié : colle-le dans ton IA.");
};
const node = h("div", { class: "screen" },
screenHeader({ back, kicker: BENCHMARK_FAMILIES[b.family], title: b.session.name, sub: b.summary }),
h("section", { class: "wod-format" },
h("p", { class: "kicker" }, "WOD"),
h("p", { class: "wod-format__label" }, formatLabel(format)),
h("p", { class: "muted" }, formatHint(format)),
record && h("p", { class: "wod-format__record" }, `Record : ${scoreLabel(record.best.result)}, le ${shortDay(record.best.date)} · ${plural(record.results.length, "fois")}`)),
h("ol", { class: "wod-moves" }, b.session.exercises.map((x) => {
const r = resolveExercise(x);
return h("li", { class: "wod-move" },
h("div", { class: "wod-move__main" }, h("span", { class: "wod-move__reps num" }, x.reps), h("a", { class: "wod-move__name", href: href.libraryItem(/** @type {string} */ (x.ref)) }, r.name)),
r.note && h("p", { class: "wod-move__note" }, r.note));
})),
h("p", { class: "coach-note" }, `Scaled : ${b.scaled}`),
state.program
? h("button", { type: "button", class: "btn btn--primary btn--block btn--lg", on: { click: doToday } }, pending ? "Reprendre ce WOD" : "Faire aujourd'hui")
: h("p", { class: "muted" }, "Crée d'abord ton programme : le WOD s'y ajoutera, hors rotation."),
h("button", { type: "button", class: "btn btn--block", on: { click: () => void ask() } }, "Demander à mon IA de l'adapter"),
fallback,
record && record.results.length > 0 && [
h("h2", { class: "tape" }, "Tes scores"),
h("ul", { class: "rows" }, [...record.results].reverse().slice(0, 10).map((x) => h("li", { class: "row" },
h("span", { class: "row__main" }, h("span", { class: "row__title" }, scoreLabel(x.result)), h("span", { class: "row__meta" }, shortDay(x.date))))))]);
return { node, title: b.session.name };
}