WOD du jour composé par l'app, hors ligne (5c)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
442b3f0a56
commit
7194530b38
+4
-3
@@ -32,7 +32,7 @@
|
||||
* | {name: "connect-ai", query: string}
|
||||
* | {name: "library", query: string}
|
||||
* | {name: "library-item", id: string, query: string}
|
||||
* | {name: "wods"}
|
||||
* | {name: "wods", query: string}
|
||||
* | {name: "wod", id: string}
|
||||
* | {name: "reserved"}
|
||||
* | {name: "not-found"}} Route
|
||||
@@ -65,7 +65,7 @@ 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 === 1) return { name: "wods", query };
|
||||
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] });
|
||||
@@ -120,7 +120,8 @@ export const href = {
|
||||
sync: () => "#/synchro",
|
||||
pair: () => "#/relier",
|
||||
library: (/** @type {string} */ query = "") => "#/bibliotheque" + (query ? "?" + query : ""),
|
||||
wods: () => "#/wod",
|
||||
/** Le catalogue, et le tirage du WOD du jour (1 omis). */
|
||||
wods: (/** @type {number} */ draw = 1) => withParams("#/wod", { tirage: draw > 1 ? draw : null }),
|
||||
wod: (/** @type {string} */ id) => "#/wod/" + enc(id),
|
||||
libraryItem: (/** @type {string} */ id, /** @type {string} */ query = "") => "#/bibliotheque/" + enc(id) + (query ? "?" + query : ""),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Le catalogue des WOD de référence (lot 4d) : la liste, et la fiche d'un WOD avec
|
||||
// Le catalogue des WOD de référence (lot 4d), précédé du WOD du jour généré hors
|
||||
// ligne (lot 5c, domain/wod-generator.js) : 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 { h, replace } from "../dom.js";
|
||||
import { generateWod } from "../../domain/wod-generator.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";
|
||||
@@ -23,14 +25,67 @@ import { toast } from "../feedback.js";
|
||||
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
|
||||
* Le tirage du WOD du jour, lu dans l'adresse (#/wod?tirage=2) ; 1 par défaut.
|
||||
* @param {string} query
|
||||
*/
|
||||
export function readDraw(query) {
|
||||
const n = Number(new URLSearchParams(query).get("tirage"));
|
||||
return Number.isInteger(n) && n >= 1 && n <= 99 ? n : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Le WOD du jour : généré par les règles de l'app, avec le matériel du profil.
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
|
||||
*/
|
||||
function dailyWod({ store, nav, today, query }) {
|
||||
let draw = readDraw(query);
|
||||
const box = h("section", { class: "block wod-daily", "aria-labelledby": "wod-daily" });
|
||||
const paint = () => {
|
||||
const state = store.getState();
|
||||
const session = generateWod({ today: today(), draw, kit: state.profile.kit, sessions: state.sessions });
|
||||
const format = /** @type {import("../../domain/wod.js").WodFormat} */ (session.format);
|
||||
const pending = pendingOneOffs(state.program, state.sessions).find((s) => s.format && wodKey(s.name, s.format) === wodKey(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, session, store.getState().sessions);
|
||||
store.dispatch("ProgramAdopted", { program: next, source: "app", reason: `WOD du jour ajouté : ${formatLabel(format)}.` });
|
||||
nav.go(href.session(key));
|
||||
};
|
||||
replace(box,
|
||||
h("p", { class: "kicker" }, "Composé par l'app, hors ligne"),
|
||||
h("h2", { class: "block__title", id: "wod-daily" }, "WOD du jour"),
|
||||
h("p", { class: "wod-format__label" }, formatLabel(format)),
|
||||
h("p", { class: "muted" }, formatHint(format)),
|
||||
h("ol", { class: "wod-moves" }, 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)),
|
||||
x.note && h("p", { class: "wod-move__note" }, x.note));
|
||||
})),
|
||||
!state.profile.kit && h("p", { class: "coach-note coach-note--plain" }, "Sans matériel coché dans ton profil, le WOD reste au poids du corps et à la course. ",
|
||||
h("a", { href: href.profile() }, "Cocher mon matériel")),
|
||||
h("div", { class: "btn-stack" },
|
||||
state.program
|
||||
? h("button", { type: "button", class: "btn btn--primary btn--block", 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."),
|
||||
!pending && h("button", { type: "button", class: "btn btn--ghost btn--block", on: { click: () => { draw = draw >= 99 ? 1 : draw + 1; nav.set(href.wods(draw)); paint(); } } }, "Un autre")));
|
||||
};
|
||||
paint();
|
||||
return box;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function wodCatalogScreen({ store, nav }) {
|
||||
export function wodCatalogScreen({ store, nav, today, query }) {
|
||||
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." }),
|
||||
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "Cross-training", title: "WOD",
|
||||
sub: "Le WOD du jour, composé par l'app, et les WOD que tout le monde connaît : fais-les, note ton score, bats ton record." }),
|
||||
dailyWod({ store, nav, today, query }),
|
||||
Object.entries(BENCHMARK_FAMILIES).map(([family, label]) => {
|
||||
const list = BENCHMARKS.filter((b) => b.family === family);
|
||||
return [
|
||||
@@ -44,7 +99,7 @@ export function wodCatalogScreen({ store, nav }) {
|
||||
h("span", { class: "chevron", "aria-hidden": "true" })));
|
||||
}))];
|
||||
}));
|
||||
return { node, title: "WOD de référence" };
|
||||
return { node, title: "WOD" };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +108,7 @@ export function wodCatalogScreen({ store, nav }) {
|
||||
*/
|
||||
export function wodItemScreen({ store, nav, today, id }) {
|
||||
const b = benchmark(id);
|
||||
const back = { label: "Références", onClick: () => nav.back(href.wods()) };
|
||||
const back = { label: "WOD", 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);
|
||||
|
||||
Reference in New Issue
Block a user