Remplacer un exercice en séance (lot 3b)
Lien « Machine prise ? » sur la carte, bibliothèque en mode choix (#/bibliotheque?remplacer=A.3), proches d'abord ; replaces dans SessionLogged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b385c4566b
commit
38e0283f3d
@@ -15,6 +15,8 @@ import { screenHeader } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { copyText } from "../files.js";
|
||||
import { toast } from "../feedback.js";
|
||||
import { doneCount, draftMatches, parseReplace, replaceExercise, replaceQuery } from "../session-draft.js";
|
||||
import { loadDraft, markReopen, saveDraft } from "../draft-storage.js";
|
||||
|
||||
/** @typedef {import("../../domain/library.js").LibraryCriteria} LibraryCriteria */
|
||||
|
||||
@@ -33,6 +35,24 @@ export function libraryScreen({ store, nav, query }) {
|
||||
/** @type {LibraryCriteria} */
|
||||
let criteria = parseCriteria(query);
|
||||
const total = Object.keys(EXERCISES).length;
|
||||
const pick = pickContext(store.getState(), query);
|
||||
// Le mode choix reste dans l'adresse quand les filtres changent (ADR 0009).
|
||||
const listHref = (/** @type {LibraryCriteria} */ c) =>
|
||||
href.library([pick ? replaceQuery(pick.sessionKey, pick.index) : "", formatCriteria(c)].filter(Boolean).join("&"));
|
||||
/** @param {string} ref */
|
||||
const choose = (ref) => {
|
||||
if (!pick) return;
|
||||
replaceExercise(pick.draft, pick.index, ref, pick.item, store.getState());
|
||||
saveDraft(pick.draft);
|
||||
markReopen(pick.index);
|
||||
nav.back(href.session(pick.sessionKey));
|
||||
};
|
||||
/** @param {string} ref @param {string} title @param {string} meta */
|
||||
const entry = (ref, title, meta) => pick
|
||||
? h("li", null, h("button", { type: "button", class: "row", on: { click: () => choose(ref) } },
|
||||
h("span", { class: "row__main" }, h("span", { class: "row__title" }, title), h("span", { class: "row__meta" }, meta)),
|
||||
h("span", { class: "mark" }, "Choisir")))
|
||||
: row(href.libraryItem(ref), title, meta);
|
||||
|
||||
const search = h("input", {
|
||||
class: "field__input", type: "search", id: "lib-q", placeholder: "squat, développé, pont…",
|
||||
@@ -44,7 +64,7 @@ export function libraryScreen({ store, nav, query }) {
|
||||
/** @param {LibraryCriteria} next */
|
||||
const update = (next) => {
|
||||
criteria = parseCriteria(formatCriteria(next)); // mêmes règles qu'à la lecture
|
||||
nav.set(href.library(formatCriteria(criteria)));
|
||||
nav.set(listHref(criteria));
|
||||
paint();
|
||||
};
|
||||
|
||||
@@ -90,9 +110,8 @@ export function libraryScreen({ store, nav, query }) {
|
||||
count === 0 && generic.length === 0 && h("p", { class: "coach-note coach-note--plain" }, "Aucun exercice ne répond à ces critères. Retire un filtre, ou décris l'exercice à ton IA : elle peut l'ajouter comme exercice générique."),
|
||||
groups.map((g) => [
|
||||
h("h2", { class: "tape" }, g.label, h("span", { class: "tape__hint" }, String(g.items.length))),
|
||||
h("ul", { class: "rows" }, g.items.map(({ ref, exercise }) => row(href.libraryItem(ref), exercise.name,
|
||||
`${EQUIPMENT_LABELS[exercise.equipment]} · ${exercise.primary.map((m) => MUSCLES[m].name).join(", ")}`)))]),
|
||||
generic.length > 0 && [
|
||||
h("ul", { class: "rows" }, g.items.map(({ ref, exercise }) => entry(ref, exercise.name, metaOf(exercise))))]),
|
||||
!pick && generic.length > 0 && [
|
||||
h("h2", { class: "tape" }, "Mes exercices", h("span", { class: "tape__hint" }, "hors bibliothèque")),
|
||||
h("ul", { class: "rows" }, generic.map((x) => row(href.libraryItem(x.id), x.name, "Exercice générique de ton programme")))]);
|
||||
};
|
||||
@@ -104,13 +123,26 @@ export function libraryScreen({ store, nav, query }) {
|
||||
});
|
||||
|
||||
paint();
|
||||
const near = pick ? [
|
||||
...(pick.planned.id !== pick.currentId && EXERCISES[pick.planned.id] ? [pick.planned.id] : []),
|
||||
// Pas un exercice déjà dans la séance : on ne remplace pas par un doublon.
|
||||
...similarExercises(pick.planned.id, 12).filter((r) => !pick.draft.exercises.some((x) => x.id === r)).slice(0, 8),
|
||||
] : [];
|
||||
const node = h("div", { class: "screen" },
|
||||
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "Exercices", title: "Bibliothèque",
|
||||
sub: "Le geste, les erreurs à éviter et un tutoriel pour chaque exercice." }),
|
||||
pick
|
||||
? screenHeader({ back: { label: `Séance ${pick.sessionKey}`, onClick: () => nav.back(href.session(pick.sessionKey)) },
|
||||
kicker: `Séance ${pick.sessionKey} · exercice ${pick.index + 1}`, title: "Remplacer",
|
||||
sub: `« ${pick.planned.name} » : choisis un exercice pour cette séance seulement. Séries, répétitions et repos restent ceux du programme.` })
|
||||
: screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "Exercices", title: "Bibliothèque",
|
||||
sub: "Le geste, les erreurs à éviter et un tutoriel pour chaque exercice." }),
|
||||
near.length > 0 && [
|
||||
h("h2", { class: "tape" }, "Proches", h("span", { class: "tape__hint" }, "mêmes muscles")),
|
||||
h("ul", { class: "rows" }, near.map((ref) => entry(ref, EXERCISES[ref].name + (ref === pick?.planned.id ? " (prévu)" : ""), metaOf(EXERCISES[ref]))))],
|
||||
pick && h("h2", { class: "tape" }, "Toute la bibliothèque"),
|
||||
h("div", { class: "field" }, h("label", { class: "field__label", for: "lib-q" }, "Rechercher"), search),
|
||||
filters,
|
||||
results);
|
||||
return { node, title: "Bibliothèque", destroy: () => clearTimeout(typing) };
|
||||
return { node, title: pick ? "Remplacer un exercice" : "Bibliothèque", destroy: () => clearTimeout(typing) };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,11 +203,34 @@ export function libraryItemScreen({ store, nav, today, id }) {
|
||||
h("h2", { class: "tape" }, "Exercices proches"),
|
||||
h("ul", { class: "rows" }, near.map((ref) => {
|
||||
const x = EXERCISES[ref];
|
||||
return row(href.libraryItem(ref), x.name, `${EQUIPMENT_LABELS[x.equipment]} · ${x.primary.map((m) => MUSCLES[m].name).join(", ")}`);
|
||||
return row(href.libraryItem(ref), x.name, metaOf(x));
|
||||
}))]);
|
||||
return { node, title: name };
|
||||
}
|
||||
|
||||
/**
|
||||
* Le mode choix (« remplacer=A.3 ») : valable seulement si le brouillon gardé
|
||||
* porte sur cette séance et que l'exercice n'a encore aucune série faite.
|
||||
* @param {import("../../domain/state.js").State} state
|
||||
* @param {string} query
|
||||
*/
|
||||
function pickContext(state, query) {
|
||||
const target = parseReplace(query);
|
||||
if (!target) return null;
|
||||
const session = state.program?.sessions.find((s) => s.key === target.sessionKey);
|
||||
const draft = /** @type {any} */ (loadDraft());
|
||||
if (!session || !Array.isArray(draft?.warmup) || !draftMatches(draft, session, draft.warmup.length)) return null;
|
||||
const ex = draft.exercises[target.index];
|
||||
if (!ex || doneCount(ex) > 0) return null;
|
||||
return {
|
||||
...target, draft, item: session.exercises[target.index], currentId: ex.id,
|
||||
planned: ex.replaces ?? { id: ex.id, name: ex.name },
|
||||
};
|
||||
}
|
||||
|
||||
/** Ligne d'une liste : matériel et muscles principaux. @param {import("../../domain/exercises.js").LibraryExercise} x */
|
||||
const metaOf = (x) => `${EQUIPMENT_LABELS[x.equipment]} · ${x.primary.map((m) => MUSCLES[m].name).join(", ")}`;
|
||||
|
||||
/** @param {string} link @param {string} title @param {string} meta */
|
||||
function row(link, title, meta) {
|
||||
return h("li", null, h("a", { class: "row", href: link },
|
||||
|
||||
Reference in New Issue
Block a user