Matériel coché dans le profil, bibliothèque « ce que mon matériel permet » (5a)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
938d6cf198
commit
72adffb613
@@ -2,6 +2,7 @@
|
||||
// filtres dans l'adresse (ADR 0009), et la fiche d'un exercice. Calculs du
|
||||
// domaine : domain/library.js.
|
||||
|
||||
import { KIT, canDo, missingKit, requiredKit } from "../../domain/kit.js";
|
||||
import { h, replace } from "../dom.js";
|
||||
import { EXERCISES, FAMILIES, MUSCLES } from "../../domain/exercises.js";
|
||||
import { resolveExercise } from "../../domain/program.js";
|
||||
@@ -84,7 +85,13 @@ export function libraryScreen({ store, nav, query }) {
|
||||
const c = criteria;
|
||||
const muscles = c.zone ? Object.entries(MUSCLES).filter(([, m]) => m.zone === c.zone) : [];
|
||||
const more = !!(c.family || c.equipment);
|
||||
const kit = store.getState().profile.kit;
|
||||
replace(filters,
|
||||
// Le matériel coché du profil (lot 5a) : un seul geste pour ne voir que le faisable.
|
||||
kit && h("button", {
|
||||
type: "button", class: "choice lib-possible", "aria-pressed": String(!!c.possible),
|
||||
on: { click: () => update({ ...c, possible: !c.possible || undefined }) },
|
||||
}, "Seulement ce que mon matériel permet"),
|
||||
h("p", { class: "mini-label" }, "Zone"),
|
||||
segmented("Zone", ZONES.map((z) => [z, ZONE_LABELS[z]]), c.zone, (zone) => update({ ...c, zone: /** @type {any} */ (zone), muscle: undefined })),
|
||||
muscles.length > 1 && [
|
||||
@@ -97,13 +104,13 @@ export function libraryScreen({ store, nav, query }) {
|
||||
h("p", { class: "mini-label" }, "Matériel"),
|
||||
segmented("Matériel", Object.entries(EQUIPMENT_GROUPS).map(([k, v]) => [k, v.label]), c.equipment, (equipment) => update({ ...c, equipment: /** @type {any} */ (equipment) }))));
|
||||
|
||||
const groups = filterLibrary(c);
|
||||
const groups = filterLibrary(c, kit);
|
||||
const count = groups.reduce((n, g) => n + g.items.length, 0);
|
||||
// Les exercices génériques n'ont pas de muscles : ils ne suivent que la recherche.
|
||||
const words = c.q ? fold(c.q).split(/\s+/).filter(Boolean) : [];
|
||||
const generic = c.zone || c.muscle || c.family || c.equipment ? []
|
||||
const generic = c.zone || c.muscle || c.family || c.equipment || c.possible ? []
|
||||
: genericExercises(store.getState()).filter((x) => words.every((w) => fold(x.name).includes(w)));
|
||||
const filtered = !!(c.q || c.zone || c.muscle || c.family || c.equipment);
|
||||
const filtered = !!(c.q || c.zone || c.muscle || c.family || c.equipment || c.possible);
|
||||
replace(results,
|
||||
h("p", { class: "lib-count" }, filtered ? `${plural(count, "exercice")} sur ${total}` : `${total} exercices`,
|
||||
filtered && h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => { search.value = ""; update({}); } } }, "Tout effacer")),
|
||||
@@ -125,8 +132,9 @@ 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),
|
||||
// Ni un exercice déjà dans la séance (un doublon), ni un que le matériel coché ne permet pas.
|
||||
...similarExercises(pick.planned.id, 16)
|
||||
.filter((r) => !pick.draft.exercises.some((x) => x.id === r) && canDo(r, store.getState().profile.kit)).slice(0, 8),
|
||||
] : [];
|
||||
const node = h("div", { class: "screen" },
|
||||
pick
|
||||
@@ -181,6 +189,7 @@ export function libraryItemScreen({ store, nav, today, id }) {
|
||||
library && h("ul", { class: "chips", "aria-label": "Muscles" },
|
||||
library.primary.map((m) => h("li", { class: "chip" }, MUSCLES[m].name)),
|
||||
library.secondary.map((m) => h("li", { class: "chip chip--secondary" }, MUSCLES[m].name))),
|
||||
library && kitLine(id, state.profile.kit),
|
||||
|
||||
h("h2", { class: "tape" }, "Dans ton programme"),
|
||||
use.sessions.length
|
||||
@@ -229,6 +238,18 @@ function pickContext(state, query) {
|
||||
}
|
||||
|
||||
/** Ligne d'une liste : matériel et muscles principaux. @param {import("../../domain/exercises.js").LibraryExercise} x */
|
||||
/**
|
||||
* Le matériel que demande l'exercice, et ce qui manque au profil (lot 5a).
|
||||
* @param {string} ref @param {readonly string[]|undefined} kit
|
||||
*/
|
||||
function kitLine(ref, kit) {
|
||||
const needs = requiredKit(ref);
|
||||
if (!needs.length) return null;
|
||||
const missing = missingKit(ref, kit);
|
||||
return h("p", { class: "lib-kit" }, `Matériel : ${needs.map((k) => KIT[k]).join(", ")}.`,
|
||||
missing.length > 0 && h("strong", null, ` Il te manque : ${missing.map((k) => KIT[k].toLowerCase()).join(", ")}.`));
|
||||
}
|
||||
|
||||
const metaOf = (x) => `${EQUIPMENT_LABELS[x.equipment]} · ${x.primary.map((m) => MUSCLES[m].name).join(", ")}`;
|
||||
|
||||
/** @param {string} link @param {string} title @param {string} meta */
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { h } from "../dom.js";
|
||||
import { MODES } from "../../domain/vocabulary.js";
|
||||
import { validateProfile } from "../../domain/profile.js";
|
||||
import { KIT } from "../../domain/kit.js";
|
||||
import { screenHeader } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { toast } from "../feedback.js";
|
||||
@@ -21,7 +22,8 @@ export const MODE_LABELS = {
|
||||
|
||||
/**
|
||||
* Lit le formulaire. Les listes s'écrivent une ligne par élément.
|
||||
* @param {{goal: string, context: string, equipment: string, constraints: string, heightCm: string, sessionMinutes: string}} form
|
||||
* @param {{goal: string, context: string, equipment: string, constraints: string, heightCm: string, sessionMinutes: string, kit?: string[]}} form
|
||||
* kit : le matériel coché, omis s'il n'a jamais été renseigné
|
||||
* @returns {{profile: import("../../domain/profile.js").Profile, errors: string[]}}
|
||||
*/
|
||||
export function profileFromForm(form) {
|
||||
@@ -33,6 +35,7 @@ export function profileFromForm(form) {
|
||||
context: form.context.trim(),
|
||||
equipment: lines(form.equipment),
|
||||
constraints: lines(form.constraints),
|
||||
...(form.kit ? { kit: /** @type {import("../../domain/kit.js").Kit[]} */ (Object.keys(KIT).filter((k) => form.kit?.includes(k))) } : {}),
|
||||
heightCm: height,
|
||||
sessionMinutes: Math.round(Number(form.sessionMinutes.replace(",", "."))),
|
||||
};
|
||||
@@ -63,10 +66,26 @@ export function profileScreen({ store, nav }) {
|
||||
const minutes = h("input", { id: "p-minutes", class: "field__input", type: "text", inputmode: "numeric", value: String(p.sessionMinutes) });
|
||||
const status = h("p", { class: "status", role: "status", "aria-live": "polite" });
|
||||
|
||||
// Matériel coché (lot 5a) : absent tant qu'on n'a rien touché, pour ne rien filtrer à tort.
|
||||
/** @type {Set<string>|null} */
|
||||
let kit = p.kit ? new Set(p.kit) : null;
|
||||
const kitBtns = Object.entries(KIT).map(([k, label]) => h("button", {
|
||||
type: "button", class: "segmented__opt", data: { kit: k },
|
||||
on: { click: () => { kit ??= new Set(); if (kit.has(k)) kit.delete(k); else kit.add(k); paintKit(); } },
|
||||
}, label));
|
||||
const kitNote = h("p", { class: "field__hint" });
|
||||
const paintKit = () => {
|
||||
kitBtns.forEach((b) => b.setAttribute("aria-pressed", String(!!kit?.has(/** @type {string} */ (b.dataset.kit)))));
|
||||
kitNote.textContent = kit === null ? "Pas encore renseigné : la bibliothèque montre tout."
|
||||
: kit.size === 0 ? "Rien de coché : poids du corps seulement." : `${kit.size} coché${kit.size > 1 ? "s" : ""}.`;
|
||||
};
|
||||
const setKit = (/** @type {string[]} */ keys) => { kit = new Set(keys); paintKit(); };
|
||||
paintKit();
|
||||
|
||||
const save = () => {
|
||||
const { profile, errors } = profileFromForm({
|
||||
goal: goal.value, context: context.value, equipment: equipment.value, constraints: constraints.value,
|
||||
heightCm: height.value, sessionMinutes: minutes.value,
|
||||
heightCm: height.value, sessionMinutes: minutes.value, kit: kit ? [...kit] : undefined,
|
||||
});
|
||||
if (errors.length) {
|
||||
status.className = "status status--err";
|
||||
@@ -109,7 +128,14 @@ export function profileScreen({ store, nav }) {
|
||||
h("h2", { class: "tape" }, "Toi"),
|
||||
field("p-goal", "Objectif", goal, "En une phrase."),
|
||||
field("p-context", "Contexte", context, "Pratique passée, lieu d'entraînement."),
|
||||
field("p-equipment", "Matériel", equipment, "Un élément par ligne."),
|
||||
h("div", { class: "field" },
|
||||
h("p", { class: "field__label", id: "p-kit" }, "Matériel"),
|
||||
h("div", { class: "segmented segmented--wrap", role: "group", "aria-labelledby": "p-kit" }, kitBtns),
|
||||
kitNote,
|
||||
h("div", { class: "btn-row" },
|
||||
h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => setKit(Object.keys(KIT)) } }, "Salle complète"),
|
||||
h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => setKit([]) } }, "Poids du corps seulement"))),
|
||||
field("p-equipment", "Autre matériel", equipment, "Ce que les cases ne disent pas (charges des haltères, hauteur du plafond…). Un élément par ligne."),
|
||||
field("p-constraints", "Contraintes", constraints, "Sécurité, blessures, organisation. Une par ligne."),
|
||||
h("div", { class: "field-pair" },
|
||||
field("p-height", "Taille (cm)", height),
|
||||
|
||||
Reference in New Issue
Block a user