Écrans branchés : planning du jour, semaine, activités, poids, données, profil, analyses, propositions avec aperçu, gamification
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
077f2dc58d
commit
41d5e44daa
+197
-67
@@ -1,112 +1,242 @@
|
||||
// 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.
|
||||
// n'y a pas encore de programme, sinon le HUD (niveau, série), la carte du
|
||||
// jour tirée du planning, les séances, le cardio, les repères et la grille des
|
||||
// autres écrans.
|
||||
|
||||
import { h, setAccent } from "../dom.js";
|
||||
import { h, paintWhenIdle, 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 { longDay, plural, shortDay } from "../format.js";
|
||||
import { dayName, lastDoneByKey, loggedForSlot, nextByRotation, slotLabel, todayModel } from "../home-model.js";
|
||||
import { actionBar, note } from "../layout.js";
|
||||
import { href } from "../router.js";
|
||||
import { onboarding } from "../onboarding.js";
|
||||
import { proposalCard } from "../proposal-card.js";
|
||||
import { estimatedMinutes } from "../../domain/progression.js";
|
||||
import { hud } from "../game.js";
|
||||
import { toast } from "../feedback.js";
|
||||
|
||||
/** @typedef {import("../../domain/state.js").State} State */
|
||||
/** @typedef {import("../../domain/planning.js").Slot} Slot */
|
||||
/** @typedef {import("../store.js").Store} Store */
|
||||
|
||||
/**
|
||||
* 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
|
||||
* (ADR 0008) : tant qu'aucun ProgramAdopted n'est au journal, l'accueil montre
|
||||
* l'onboarding.
|
||||
* @param {State} state
|
||||
*/
|
||||
export const hasProgram = (state) => !!state.program && state.programVersions.length > 0;
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store}} ctx
|
||||
* @param {{store: Store, nav: import("../router.js").Navigation, today: () => string}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function homeScreen({ store }) {
|
||||
export function homeScreen({ store, nav, today }) {
|
||||
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));
|
||||
const paint = () => node.replaceChildren(homeContent(store, nav, today()));
|
||||
paint();
|
||||
return { node, title: "", destroy: store.subscribe(paint) };
|
||||
return { node, title: "", destroy: store.subscribe(paintWhenIdle(node, paint)) };
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../store.js").Store} store
|
||||
* Plaque d'une séance : sa lettre sur sa couleur.
|
||||
* @param {string} key
|
||||
* @param {string|undefined} color
|
||||
* @param {string} [cls]
|
||||
*/
|
||||
export function plaque(key, color, cls = "plaque") {
|
||||
const el = h("span", { class: cls, "aria-hidden": "true" }, key);
|
||||
const c = sessionColor(color);
|
||||
setAccent(el, c, inkOn(c));
|
||||
return el;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Store} store
|
||||
* @param {import("../router.js").Navigation} nav
|
||||
* @param {string} today
|
||||
* @returns {Node}
|
||||
*/
|
||||
function homeContent(store) {
|
||||
function homeContent(store, nav, today) {
|
||||
const state = store.getState();
|
||||
// Une proposition en attente passe avant tout le reste.
|
||||
if (state.proposals.length) {
|
||||
const [first, ...others] = state.proposals;
|
||||
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 })));
|
||||
proposalCard({ proposal: first, store }),
|
||||
others.length > 0 && h("p", { class: "muted" }, `Et ${plural(others.length, "autre proposition")} ensuite.`));
|
||||
}
|
||||
if (!hasProgram(state)) return onboarding({ store });
|
||||
|
||||
const program = /** @type {import("../../domain/program.js").Program} */ (state.program);
|
||||
const model = todayModel(state, today);
|
||||
const last = lastDoneByKey(state);
|
||||
const today = localDay();
|
||||
/** @type {Node|null} */
|
||||
let primary = null;
|
||||
|
||||
// À 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);
|
||||
/** @param {Slot} slot @param {string} date */
|
||||
const markDone = (slot, date) => {
|
||||
const data = loggedForSlot(slot, program, date);
|
||||
if (state.skippedDays.includes(date)) store.dispatch("DayUnskipped", { date });
|
||||
store.dispatch("SessionLogged", data);
|
||||
toast(`${data.name} : fait.`);
|
||||
};
|
||||
|
||||
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."));
|
||||
// ---- carte du jour -----------------------------------------------------------
|
||||
const kicker = h("p", { class: "kicker" }, "Aujourd'hui · ", longDay(today));
|
||||
/** @type {import("../dom.js").Child[]} */
|
||||
let body = [];
|
||||
if (!model.planned) {
|
||||
const next = nextByRotation(state);
|
||||
if (next) {
|
||||
body = [
|
||||
h("div", { class: "block__head" }, plaque(next.key, next.color),
|
||||
h("div", null, h("h2", { class: "block__title" }, next.name),
|
||||
h("p", { class: "block__meta" }, `${plural(next.exercises.length, "exercice")} · ${estimatedMinutes(next)} min · ${last[next.key] ? "faite le " + shortDay(last[next.key]) : "jamais faite"}`))),
|
||||
h("p", { class: "muted" }, "Pas de planning : la séance faite le moins récemment. "),
|
||||
h("a", { class: "btn btn--block", href: href.week() }, "Planifier ma semaine"),
|
||||
];
|
||||
primary = h("a", { class: "btn btn--primary btn--block btn--lg", href: href.session(next.key) }, `Commencer · séance ${next.key}`);
|
||||
}
|
||||
} else if (model.status === "rest") {
|
||||
body = [h("h2", { class: "block__title" }, "Repos"), h("p", { class: "block__meta" }, nextText(model.next, program))];
|
||||
} else if (model.status === "done") {
|
||||
body = [h("h2", { class: "block__title" }, "C'est fait."), h("p", { class: "block__meta" }, nextText(model.next, program))];
|
||||
} else if (model.status === "skipped") {
|
||||
body = [
|
||||
h("h2", { class: "block__title" }, "Passée"),
|
||||
h("p", { class: "block__meta" }, `Marquée non faite. ${nextText(model.next, program)}`),
|
||||
h("button", { type: "button", class: "btn btn--block", on: { click: () => store.dispatch("DayUnskipped", { date: today }) } }, "Annuler, je la fais"),
|
||||
];
|
||||
} else if (model.slot) {
|
||||
const slot = model.slot;
|
||||
const label = slotLabel(slot, program);
|
||||
const session = slot.kind === "strength" ? program.sessions.find((s) => s.key === slot.sessionKey) : null;
|
||||
body = [
|
||||
h("div", { class: "block__head" },
|
||||
session ? plaque(session.key, session.color) : h("span", { class: "plaque plaque--empty", "aria-hidden": "true" }, slot.kind === "cardio" ? "C" : "A"),
|
||||
h("div", null,
|
||||
h("h2", { class: "block__title" }, session ? session.name : label.title),
|
||||
h("p", { class: "block__meta" }, session
|
||||
? `Séance ${session.key} · ${plural(session.exercises.length, "exercice")} · ${estimatedMinutes(session)} min`
|
||||
: label.detail))),
|
||||
session?.subtitle && h("p", null, session.subtitle),
|
||||
slot.kind === "cardio" && program.cardio?.[slot.cardioIndex ?? -1]?.text && h("p", { class: "muted" }, program.cardio[slot.cardioIndex ?? -1].text),
|
||||
h("button", { type: "button", class: "btn btn--ghost btn--block", on: { click: () => store.dispatch("DaySkipped", { date: today }) } }, "Pas aujourd'hui"),
|
||||
];
|
||||
primary = session
|
||||
? h("a", { class: "btn btn--primary btn--block btn--lg", href: href.session(session.key) }, "Commencer")
|
||||
: h("button", { type: "button", class: "btn btn--primary btn--block btn--lg", on: { click: () => markDone(slot, today) } }, "Marquer comme fait");
|
||||
}
|
||||
|
||||
const late = model.late.length > 0 && h("div", { class: "block__sep" },
|
||||
h("p", { class: "mark" }, "En retard cette semaine"),
|
||||
h("ul", { class: "rows" }, model.late.map((slot) => {
|
||||
const label = slotLabel(slot, program);
|
||||
return h("li", { class: "row" },
|
||||
h("span", { class: "row__main" },
|
||||
h("span", { class: "row__title" }, label.title + (label.detail ? ` · ${label.detail}` : "")),
|
||||
h("span", { class: "row__meta" }, `Prévue ${dayName(slot.date)}`)),
|
||||
slot.kind === "strength"
|
||||
? h("a", { class: "btn btn--sm", href: href.session(/** @type {string} */ (slot.sessionKey)) }, "Faire")
|
||||
: h("button", { type: "button", class: "btn btn--sm", on: { click: () => markDone(slot, slot.date) } }, "Marquer faite"));
|
||||
})));
|
||||
|
||||
const progress = model.planned && h("div", { class: "block__sep" },
|
||||
h("p", { class: "mark" }, `Semaine · ${model.done}/${model.cells.length} fait`,
|
||||
model.skipped ? ` · ${model.skipped} manqué${model.skipped > 1 ? "s" : ""}` : "",
|
||||
model.extra ? ` · ${model.extra} en plus` : ""),
|
||||
h("span", { class: "cells", "aria-hidden": "true" }, model.cells.map((c) => h("i", { data: { state: c.state } }))));
|
||||
|
||||
const doneToday = model.doneToday.length > 0 && h("p", { class: "muted" },
|
||||
"Déjà fait aujourd'hui : ", model.doneToday.map((s) => s.name).join(", "), ".");
|
||||
|
||||
const todayBlock = h("section", { class: "block block--today", "aria-label": "Aujourd'hui" },
|
||||
kicker, ...body, otherActivity(store, today), doneToday, late, progress);
|
||||
|
||||
return h("div", null,
|
||||
screenHeader({ kicker: "IA-Fit", title: program.name, sub: program.subtitle }),
|
||||
todayCard,
|
||||
hud(state, today),
|
||||
h("header", { class: "visually-hidden" }, h("h1", null, program.name)),
|
||||
todayBlock,
|
||||
|
||||
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"),
|
||||
])))),
|
||||
h("h2", { class: "tape" }, "Séances"),
|
||||
h("ul", { class: "rows" }, program.sessions.map((s) =>
|
||||
h("li", null, h("a", { class: "row", href: href.session(s.key) },
|
||||
plaque(s.key, s.color),
|
||||
h("span", { class: "row__main" },
|
||||
h("span", { class: "row__title" }, s.name),
|
||||
h("span", { class: "row__meta" }, `${plural(s.exercises.length, "exercice")} · ${estimatedMinutes(s)} min · ${last[s.key] ? "faite le " + shortDay(last[s.key]) : "jamais faite"}`)),
|
||||
h("span", { class: "chevron", "aria-hidden": "true" }))))),
|
||||
|
||||
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,
|
||||
program.cardio?.length ? [h("h2", { class: "tape" }, "Cardio"), program.cardio.map((c) => note(c.name, c.text))] : null,
|
||||
program.rules?.length ? [h("h2", { class: "tape" }, "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("h2", { class: "tape" }, "Tout le reste"),
|
||||
h("nav", { class: "grid-nav", "aria-label": "Autres écrans" },
|
||||
tile(href.week(), "Semaine", "jours, planning, agenda"),
|
||||
tile(href.history(), "Historique", plural(state.sessions.length, "séance")),
|
||||
tile(href.weight(), "Poids", state.weights.length ? `${String(state.weights[state.weights.length - 1].kg).replace(".", ",")} kg` : "première pesée"),
|
||||
tile(href.analysis(), "Analyses", "charges, assiduité"),
|
||||
tile(href.progress(), "Succès", "niveau, records"),
|
||||
tile(href.activities(), "Activités", plural(program.activities?.length ?? 0, "activité")),
|
||||
tile(href.profile(), "Profil", "objectif, mode"),
|
||||
tile(href.data(), "Données", "sauvegarde, IA")),
|
||||
|
||||
h("footer", { class: "foot" }, "Tes données restent sur cet appareil."),
|
||||
h("p", { class: "foot" }, `${program.name} · tes données restent sur cet appareil.`),
|
||||
primary && actionBar(primary));
|
||||
}
|
||||
|
||||
next && actionBar(h("a", { class: "btn btn--primary btn--block btn--lg", href: href.session(next.key) },
|
||||
`Commencer la séance ${next.key}`)));
|
||||
/** @param {string} link @param {string} name @param {string} meta */
|
||||
function tile(link, name, meta) {
|
||||
return h("a", { class: "tile", href: link }, h("span", { class: "tile__name" }, name), h("span", { class: "tile__meta" }, meta));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param {Slot|null} next
|
||||
* @param {import("../../domain/program.js").Program} program
|
||||
*/
|
||||
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;
|
||||
function nextText(next, program) {
|
||||
if (!next) return "Plus rien de prévu cette semaine.";
|
||||
const l = slotLabel(next, program);
|
||||
return `Ensuite : ${dayName(next.date)}, ${l.title.toLowerCase()}${l.detail ? " · " + l.detail : ""}.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* « Autre activité » : enregistrer n'importe quelle séance, cardio ou activité,
|
||||
* à une date choisie avant.
|
||||
* @param {Store} store
|
||||
* @param {string} today
|
||||
*/
|
||||
function otherActivity(store, today) {
|
||||
const program = /** @type {import("../../domain/program.js").Program} */ (store.getState().program);
|
||||
const panel = h("div", { class: "other", hidden: true });
|
||||
const toggle = h("button", { type: "button", class: "btn btn--ghost btn--block", "aria-expanded": "false" }, "Autre activité");
|
||||
toggle.addEventListener("click", () => {
|
||||
panel.hidden = !panel.hidden;
|
||||
toggle.setAttribute("aria-expanded", String(!panel.hidden));
|
||||
});
|
||||
const date = h("input", { id: "other-date", class: "field__input", type: "date", max: today, value: today });
|
||||
const day = () => (/^\d{4}-\d{2}-\d{2}$/.test(date.value) && date.value <= today ? date.value : today);
|
||||
/** @param {"cardio"|"activity"} kind @param {string} ref @param {string} name */
|
||||
const log = (kind, ref, name) => {
|
||||
const d = day();
|
||||
if (store.getState().sessions.some((s) => s.kind === kind && s.ref === ref && s.date === d)) {
|
||||
toast(`${name} est déjà enregistré à cette date.`);
|
||||
return;
|
||||
}
|
||||
if (store.getState().skippedDays.includes(d)) store.dispatch("DayUnskipped", { date: d });
|
||||
store.dispatch("SessionLogged", { date: d, kind, ref, name, warmup: null, exercises: [] });
|
||||
toast(`${name} : enregistré le ${shortDay(d)}.`);
|
||||
};
|
||||
const session = (/** @type {string} */ key) => {
|
||||
location.hash = href.session(key, day() === today ? null : day());
|
||||
};
|
||||
panel.append(
|
||||
h("div", { class: "field field--inline" }, h("label", { class: "field__label", for: "other-date" }, "Le"), date),
|
||||
h("div", { class: "choice-list" },
|
||||
program.sessions.map((s) => h("button", { type: "button", class: "choice", on: { click: () => session(s.key) } }, `Séance ${s.key} · ${s.name}`)),
|
||||
(program.cardio ?? []).map((c) => h("button", { type: "button", class: "choice", on: { click: () => log("cardio", c.name, c.name) } }, `Cardio · ${c.name}`)),
|
||||
(program.activities ?? []).map((a) => h("button", { type: "button", class: "choice", on: { click: () => log("activity", a.id, a.name) } }, a.name))));
|
||||
return h("div", null, toggle, panel);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user