Écrans : onboarding, accueil, séance guidée, minuteur, historique
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ba08daaa89
commit
af92c021e2
@@ -0,0 +1,149 @@
|
||||
// Historique : la liste des séances faites, et la correction ou la suppression
|
||||
// d'une séance passée (SessionCorrected, SessionDeleted).
|
||||
|
||||
import { h, replace } from "../dom.js";
|
||||
import { kg, localDay, longDay, mediumDay, parseAmount } from "../format.js";
|
||||
import { actionBar, screenHeader, sectionLabel } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { sessionDataOf, sessionSummary, usesLoad, usesTime } from "../session-draft.js";
|
||||
import { confirmDialog, toast } from "../feedback.js";
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function historyScreen({ store, nav }) {
|
||||
const list = h("div", { class: "history" });
|
||||
const paint = () => {
|
||||
const sessions = [...store.getState().sessions].reverse();
|
||||
if (!sessions.length) {
|
||||
replace(list, h("p", { class: "empty" }, "Aucune séance enregistrée pour l'instant. Termine ta première séance : elle apparaîtra ici."));
|
||||
return;
|
||||
}
|
||||
replace(list, h("ul", { class: "history__list" }, sessions.map((s) =>
|
||||
h("li", null, h("a", { class: "history__item", href: href.historyEdit(s.id) },
|
||||
h("span", { class: "history__date" }, mediumDay(s.date)),
|
||||
h("span", { class: "history__name" }, s.name),
|
||||
h("span", { class: "history__meta" }, sessionSummary(s) || kindLabel(s.kind)),
|
||||
h("span", { class: "chevron", "aria-hidden": "true" }))))));
|
||||
};
|
||||
paint();
|
||||
const unsubscribe = store.subscribe(paint);
|
||||
const node = h("div", { class: "screen" },
|
||||
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "Ton parcours", title: "Historique", sub: "Touche une séance pour la corriger ou la retirer." }),
|
||||
list);
|
||||
return { node, title: "Historique", destroy: unsubscribe };
|
||||
}
|
||||
|
||||
/** @param {string} kind */
|
||||
const kindLabel = (kind) => (kind === "cardio" ? "Cardio" : kind === "activity" ? "Activité" : "Séance");
|
||||
|
||||
/**
|
||||
* Correction d'une séance passée. Le formulaire travaille sur une copie ; rien
|
||||
* n'est enregistré avant « Enregistrer les modifications ».
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, id: string}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function historyEditScreen({ store, nav, id }) {
|
||||
const back = { label: "Historique", onClick: () => nav.back(href.history()) };
|
||||
const logged = store.getState().sessions.find((s) => s.id === id);
|
||||
if (!logged) {
|
||||
return {
|
||||
title: "Séance introuvable",
|
||||
node: h("div", { class: "screen" }, screenHeader({ back, title: "Séance introuvable", sub: "Elle a peut-être été retirée de l'historique." })),
|
||||
};
|
||||
}
|
||||
const data = sessionDataOf(logged);
|
||||
const today = localDay();
|
||||
const status = h("p", { class: "status", role: "alert" });
|
||||
|
||||
const dateInput = h("input", { id: "edit-date", class: "field__input field__input--date", type: "date", max: today, value: data.date });
|
||||
dateInput.addEventListener("change", () => {
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(dateInput.value) && dateInput.value <= today) data.date = dateInput.value;
|
||||
else dateInput.value = data.date;
|
||||
});
|
||||
|
||||
/** @type {Set<HTMLInputElement>} */
|
||||
const invalid = new Set();
|
||||
/**
|
||||
* Champ numérique qui écrit dans la copie à chaque frappe (aucune
|
||||
* reconstruction : le focus reste).
|
||||
* @param {string} label
|
||||
* @param {number|null} value
|
||||
* @param {(v: number|null) => void} write
|
||||
* @param {string} unit
|
||||
*/
|
||||
const numberField = (label, value, write, unit) => {
|
||||
const input = h("input", { class: "field__input", type: "text", inputmode: "decimal", autocomplete: "off", placeholder: "—", "aria-label": label, value: value === null ? "" : kg(value) });
|
||||
input.addEventListener("input", () => {
|
||||
const v = parseAmount(input.value);
|
||||
input.setAttribute("aria-invalid", String(v === undefined));
|
||||
if (v === undefined) invalid.add(input);
|
||||
else { invalid.delete(input); write(v); }
|
||||
});
|
||||
return h("span", { class: "field field--amount field--compact" }, input, h("span", { class: "field__unit" }, unit));
|
||||
};
|
||||
|
||||
const exercises = data.exercises.map((x) => {
|
||||
const sets = h("div", { class: "edit-sets" });
|
||||
const drawSets = () => {
|
||||
replace(sets,
|
||||
x.sets.map((s, i) => h("div", { class: "edit-set" },
|
||||
h("span", { class: "edit-set__n" }, `Série ${i + 1}`),
|
||||
numberField(`Répétitions de la série ${i + 1}, ${x.name}`, s.reps, (v) => { s.reps = v === null ? null : Math.round(v); }, "rép."))),
|
||||
h("div", { class: "edit-sets__btns" },
|
||||
h("button", { type: "button", class: "btn btn--sm", on: { click: () => {
|
||||
const prev = x.sets[x.sets.length - 1];
|
||||
x.sets.push({ reps: prev?.reps ?? null, effort: null });
|
||||
drawSets();
|
||||
} } }, "+ Série"),
|
||||
x.sets.length > 0 && h("button", { type: "button", class: "btn btn--sm btn--ghost", on: { click: () => { x.sets.pop(); drawSets(); } } }, "− Série")));
|
||||
};
|
||||
drawSets();
|
||||
return h("li", { class: "edit-ex" },
|
||||
h("div", { class: "edit-ex__head" },
|
||||
h("strong", null, x.name),
|
||||
h("span", { class: "muted" }, x.target)),
|
||||
h("div", { class: "work__fields" },
|
||||
usesLoad(x.tracking) && numberField(`Charge, ${x.name}`, x.loadKg, (v) => { x.loadKg = v; }, "kg"),
|
||||
usesTime(x.tracking) && numberField(`Durée, ${x.name}`, x.seconds, (v) => { x.seconds = v; }, "s")),
|
||||
sets);
|
||||
});
|
||||
|
||||
const save = () => {
|
||||
if (invalid.size) {
|
||||
status.textContent = "Un nombre est illisible : corrige le champ signalé.";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
store.dispatch("SessionCorrected", { sessionId: id, session: data });
|
||||
} catch (e) {
|
||||
status.textContent = "La correction n'a pas pu être enregistrée : " + (e instanceof Error ? e.message : String(e));
|
||||
return;
|
||||
}
|
||||
toast("Séance corrigée.");
|
||||
nav.back(href.history());
|
||||
};
|
||||
|
||||
const remove = async () => {
|
||||
const ok = await confirmDialog({
|
||||
title: "Retirer cette séance ?",
|
||||
lines: [`${data.name}, ${longDay(data.date)}.`, "Elle disparaît de l'historique et des calculs de progression."],
|
||||
confirm: "Retirer la séance", cancel: "Garder", danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
store.dispatch("SessionDeleted", { sessionId: id });
|
||||
toast("Séance retirée de l'historique.");
|
||||
nav.back(href.history());
|
||||
};
|
||||
|
||||
const node = h("div", { class: "screen" },
|
||||
screenHeader({ back, kicker: mediumDay(logged.date), title: "Corriger", sub: logged.name }),
|
||||
h("div", { class: "field field--inline" }, h("label", { class: "field__label", for: "edit-date" }, "Date"), dateInput),
|
||||
data.exercises.length > 0 && [sectionLabel("Exercices", "séries faites et charge"), h("ul", { class: "edit-list" }, exercises)],
|
||||
sectionLabel("Retirer"),
|
||||
h("button", { type: "button", class: "btn btn--danger btn--block", on: { click: remove } }, "Retirer cette séance de l'historique"),
|
||||
status,
|
||||
actionBar(h("button", { type: "button", class: "btn btn--primary btn--block btn--lg", on: { click: save } }, "Enregistrer les modifications")));
|
||||
return { node, title: "Corriger une séance" };
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Accueil. Par priorité : une proposition en attente, sinon l'onboarding s'il
|
||||
// n'y a pas encore de programme, sinon la carte du jour, les séances, le
|
||||
// cardio et les repères.
|
||||
|
||||
import { h, setAccent } from "../dom.js";
|
||||
import { inkOn, sessionColor } from "../color.js";
|
||||
import { longDay, localDay, shortDay, plural } from "../format.js";
|
||||
import { estimateMinutes, lastDoneByKey, nextByRotation } from "../home-model.js";
|
||||
import { actionBar, note, screenHeader, sectionLabel } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { onboarding } from "../onboarding.js";
|
||||
import { proposalCard } from "../proposal-card.js";
|
||||
|
||||
/**
|
||||
* Un programme a-t-il été adopté ? Il n'y a pas de programme par défaut
|
||||
* (décision du porteur du projet, 2026-11-18) : tant qu'aucun ProgramAdopted
|
||||
* n'est au journal, l'accueil montre l'onboarding.
|
||||
* @param {import("../../domain/state.js").State} state
|
||||
*/
|
||||
export const hasProgram = (state) => !!state.program && state.programVersions.length > 0;
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function homeScreen({ store }) {
|
||||
const node = h("div", { class: "screen screen--home" });
|
||||
// L'accueil n'a aucun champ de saisie : le reconstruire à chaque changement est sans risque.
|
||||
const paint = () => node.replaceChildren(homeContent(store));
|
||||
paint();
|
||||
return { node, title: "", destroy: store.subscribe(paint) };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../store.js").Store} store
|
||||
* @returns {Node}
|
||||
*/
|
||||
function homeContent(store) {
|
||||
const state = store.getState();
|
||||
// Une proposition en attente passe avant tout le reste.
|
||||
if (state.proposals.length) {
|
||||
return h("div", null,
|
||||
h("header", { class: "screen-head" }, h("p", { class: "kicker" }, "IA-Fit"), h("h1", { class: "title" }, "Un programme t'attend")),
|
||||
state.proposals.map((proposal) => proposalCard({ proposal, store })));
|
||||
}
|
||||
if (!hasProgram(state)) return onboarding({ store });
|
||||
|
||||
const program = /** @type {import("../../domain/program.js").Program} */ (state.program);
|
||||
const last = lastDoneByKey(state);
|
||||
const today = localDay();
|
||||
|
||||
// À brancher : planning.weekPlan(state, monday) donnera le créneau du jour
|
||||
// (séance, cardio, activité, repos), les créneaux en retard et l'avancement de
|
||||
// la semaine. En attendant : rotation simple, annoncée comme telle.
|
||||
const next = nextByRotation(state);
|
||||
|
||||
const todayCard = next
|
||||
? sessionLink(next, "card card--today", [
|
||||
h("p", { class: "kicker" }, "Aujourd'hui · ", longDay(today)),
|
||||
h("p", { class: "card__eyebrow" }, h("span", { class: "swatch", "aria-hidden": "true" }), `Séance ${next.key}`),
|
||||
h("h2", { class: "card__title" }, next.name),
|
||||
h("p", { class: "card__meta" },
|
||||
`${plural(next.exercises.length, "exercice")} · environ ${estimateMinutes(next)} min`,
|
||||
last[next.key] ? ` · faite le ${shortDay(last[next.key])}` : " · jamais faite"),
|
||||
next.subtitle && h("p", { class: "card__text" }, next.subtitle),
|
||||
h("p", { class: "card__hint" },
|
||||
"Proposée par rotation : la séance faite le moins récemment. Le planning de la semaine arrive bientôt."),
|
||||
])
|
||||
: h("div", { class: "card card--today" }, h("p", { class: "card__text" }, "Le programme ne contient aucune séance."));
|
||||
|
||||
return h("div", null,
|
||||
screenHeader({ kicker: "IA-Fit", title: program.name, sub: program.subtitle }),
|
||||
todayCard,
|
||||
|
||||
sectionLabel("Séances"),
|
||||
h("ul", { class: "plates" }, program.sessions.map((s) =>
|
||||
h("li", null, sessionLink(s, "plate", [
|
||||
h("span", { class: "plate__bar", "aria-hidden": "true" }),
|
||||
h("span", { class: "plate__body" },
|
||||
h("span", { class: "plate__id" }, `Séance ${s.key}${s.tag ? " · " + s.tag : ""}`),
|
||||
h("span", { class: "plate__name" }, s.name),
|
||||
h("span", { class: "plate__meta" }, `${plural(s.exercises.length, "exercice")} · environ ${estimateMinutes(s)} min`)),
|
||||
h("span", { class: "plate__last" }, last[s.key] ? `Faite le ${shortDay(last[s.key])}` : "Jamais faite"),
|
||||
])))),
|
||||
|
||||
program.cardio?.length ? [sectionLabel("Cardio"), program.cardio.map((c) => note(c.name, c.text))] : null,
|
||||
program.rules?.length ? [sectionLabel("Repères"), program.rules.map((r) => note(r.name, r.text))] : null,
|
||||
|
||||
sectionLabel("Aller plus loin"),
|
||||
h("nav", { class: "links", "aria-label": "Autres écrans" },
|
||||
h("a", { class: "btn btn--block btn--ghost", href: href.history() }, "Historique des séances"),
|
||||
// À brancher (sous-lot 1d) : semaine, activités, poids, données, profil.
|
||||
h("p", { class: "muted" }, "Semaine, activités, poids et sauvegarde : bientôt.")),
|
||||
|
||||
h("footer", { class: "foot" }, "Tes données restent sur cet appareil."),
|
||||
|
||||
next && actionBar(h("a", { class: "btn btn--primary btn--block btn--lg", href: href.session(next.key) },
|
||||
`Commencer la séance ${next.key}`)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lien vers une séance, coloré par sa couleur.
|
||||
* @param {import("../../domain/program.js").ProgramSession} s
|
||||
* @param {string} cls
|
||||
* @param {import("../dom.js").Child[]} children
|
||||
*/
|
||||
function sessionLink(s, cls, children) {
|
||||
const a = h("a", { class: cls, href: href.session(s.key) }, ...children);
|
||||
const color = sessionColor(s.color);
|
||||
setAccent(a, color, inkOn(color));
|
||||
return a;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// La séance guidée : échauffement, blocs et supersets, séries, minuteur.
|
||||
// Le brouillon est local ; « Terminer » crée un seul SessionLogged.
|
||||
|
||||
import { h, setAccent } from "../dom.js";
|
||||
import { groupBlocks, resolveExercise } from "../../domain/program.js";
|
||||
import { inkOn, sessionColor } from "../color.js";
|
||||
import { localDay, longDay, plural } from "../format.js";
|
||||
import { estimateMinutes } from "../home-model.js";
|
||||
import { actionBar, screenHeader } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { buildSessionData, completion, createDraft, doneCount, draftMatches } from "../session-draft.js";
|
||||
import { clearDraft, loadDraft, saveDraft } from "../draft-storage.js";
|
||||
import { exerciseCard } from "../exercise-card.js";
|
||||
import { WARMUP_STEPS, warmupCard } from "../warmup-card.js";
|
||||
import { confirmDialog, toast } from "../feedback.js";
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store, key: string, nav: import("../router.js").Navigation, timer: import("../timer.js").Timer}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function sessionScreen({ store, key, nav, timer }) {
|
||||
const state = store.getState();
|
||||
const session = state.program?.sessions.find((s) => s.key === key);
|
||||
const back = { label: "Accueil", onClick: () => nav.back(href.home()) };
|
||||
if (!session) {
|
||||
return {
|
||||
title: "Séance introuvable",
|
||||
node: h("div", { class: "screen" },
|
||||
screenHeader({ back, title: "Séance introuvable", sub: `Le programme n'a pas de séance « ${key} ».` })),
|
||||
};
|
||||
}
|
||||
|
||||
const today = localDay();
|
||||
const stored = loadDraft();
|
||||
const draft = draftMatches(stored, session, WARMUP_STEPS.length)
|
||||
? stored
|
||||
: createDraft(session, state, today, WARMUP_STEPS.length);
|
||||
const resumed = draft === stored;
|
||||
|
||||
const progress = h("span", { class: "action-bar__meta", "aria-live": "polite" });
|
||||
const status = h("p", { class: "status", role: "alert" });
|
||||
const totalSets = draft.exercises.reduce((n, ex) => n + ex.sets, 0);
|
||||
const paintProgress = () => {
|
||||
const done = draft.exercises.reduce((n, ex) => n + doneCount(ex), 0);
|
||||
progress.textContent = `${done}/${totalSets} séries`;
|
||||
};
|
||||
// Le brouillon n'est gardé qu'au premier changement : ouvrir une séance pour
|
||||
// la regarder n'écrase pas celle qu'on a commencée.
|
||||
const onChange = () => {
|
||||
saveDraft(draft);
|
||||
paintProgress();
|
||||
status.textContent = "";
|
||||
};
|
||||
|
||||
// ---- date de la séance (saisie a posteriori possible) ------------------------
|
||||
const dateNotice = h("p", { class: "coach-note", hidden: draft.date === today });
|
||||
const paintDate = () => {
|
||||
dateNotice.hidden = draft.date === today;
|
||||
dateNotice.textContent = `Cette séance sera enregistrée au ${longDay(draft.date)}.`;
|
||||
};
|
||||
const dateInput = h("input", { id: "session-date", class: "field__input field__input--date", type: "date", max: today, value: draft.date });
|
||||
dateInput.addEventListener("change", () => {
|
||||
const value = dateInput.value;
|
||||
draft.date = /^\d{4}-\d{2}-\d{2}$/.test(value) && value <= today ? value : today;
|
||||
if (draft.date !== value) dateInput.value = draft.date;
|
||||
paintDate();
|
||||
onChange();
|
||||
});
|
||||
paintDate();
|
||||
|
||||
// ---- blocs ---------------------------------------------------------------------
|
||||
const color = sessionColor(session.color);
|
||||
const firstOpen = draft.exercises.findIndex((ex) => doneCount(ex) < ex.sets);
|
||||
let index = 0;
|
||||
const blocks = groupBlocks(session.exercises).map((block) => {
|
||||
const cards = block.items.map((item, k) => {
|
||||
const i = index++;
|
||||
return exerciseCard({
|
||||
ex: draft.exercises[i], item, sessionKey: session.key, number: String(i + 1),
|
||||
letter: block.items.length > 1 ? String.fromCharCode(65 + k) : null,
|
||||
open: resumed && i === firstOpen, store, timer, onChange,
|
||||
});
|
||||
});
|
||||
if (block.items.length === 1) return cards[0];
|
||||
const names = block.items.map((item) => resolveExercise(item).name).join(" + ");
|
||||
const rounds = Math.max(...block.items.map((item) => item.sets));
|
||||
return h("section", { class: "superset", "aria-label": `Superset : ${names}` },
|
||||
h("div", { class: "superset__head" },
|
||||
h("span", { class: "tag tag--superset" }, "Superset"),
|
||||
h("p", { class: "superset__text" }, `${rounds} tours : enchaîne les exercices, le vrai repos vient après le dernier.`)),
|
||||
cards);
|
||||
});
|
||||
|
||||
const finish = async () => {
|
||||
const c = completion(draft);
|
||||
if (c.doneSets === 0) {
|
||||
status.textContent = "Aucune série validée : rien à enregistrer.";
|
||||
return;
|
||||
}
|
||||
if (!c.complete) {
|
||||
const lines = [];
|
||||
if (c.missing.length)
|
||||
lines.push(`${plural(c.missing.length, "exercice")} pas commencé${c.missing.length > 1 ? "s" : ""} : ${c.missing.slice(0, 3).join(", ")}${c.missing.length > 3 ? "…" : ""}.`);
|
||||
if (c.partial.length) lines.push(`${plural(c.partial.length, "exercice")} incomplet${c.partial.length > 1 ? "s" : ""}.`);
|
||||
lines.push("Tu pourras la corriger ensuite depuis l'historique.");
|
||||
const ok = await confirmDialog({ title: "La séance n'est pas finie", lines, confirm: "Enregistrer quand même", cancel: "Continuer la séance" });
|
||||
if (!ok) return;
|
||||
}
|
||||
try {
|
||||
store.dispatch("SessionLogged", buildSessionData(draft));
|
||||
} catch (e) {
|
||||
status.textContent = "La séance n'a pas pu être enregistrée : " + (e instanceof Error ? e.message : String(e));
|
||||
return;
|
||||
}
|
||||
clearDraft();
|
||||
timer.stop();
|
||||
toast(draft.date === today ? "Séance enregistrée." : `Séance enregistrée au ${longDay(draft.date)}.`);
|
||||
nav.go(href.home(), { replace: true });
|
||||
};
|
||||
|
||||
const node = h("div", { class: "screen screen--session" },
|
||||
screenHeader({
|
||||
back,
|
||||
kicker: `Séance ${session.key}${session.tag ? " · " + session.tag : ""} · environ ${estimateMinutes(session)} min`,
|
||||
title: session.name,
|
||||
sub: session.subtitle,
|
||||
}),
|
||||
resumed && h("p", { class: "coach-note" }, "Séance reprise là où tu l'avais laissée."),
|
||||
h("div", { class: "field field--inline" },
|
||||
h("label", { class: "field__label", for: "session-date" }, "Date de la séance"),
|
||||
dateInput),
|
||||
dateNotice,
|
||||
h("div", { class: "exercises" },
|
||||
warmupCard({ done: draft.warmup, timer, onChange, open: !resumed }),
|
||||
blocks),
|
||||
status,
|
||||
h("p", { class: "foot" }, "Touche une série pour noter tes répétitions et ton ressenti : le repos démarre tout seul."),
|
||||
actionBar(progress, h("button", { type: "button", class: "btn btn--primary btn--lg", on: { click: finish } }, "Terminer la séance")));
|
||||
setAccent(node, color, inkOn(color));
|
||||
paintProgress();
|
||||
|
||||
return { node, title: session.name, destroy: () => timer.stop() };
|
||||
}
|
||||
Reference in New Issue
Block a user