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:
Pierre MARTIN
2026-11-23 02:12:25 +01:00
co-authored by Claude Opus 5.5
parent 938d6cf198
commit 72adffb613
15 changed files with 281 additions and 20 deletions
+29 -3
View File
@@ -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),