107 lines
6.4 KiB
JavaScript
107 lines
6.4 KiB
JavaScript
// 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 };
|
|
}
|