É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,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;
|
||||
}
|
||||
Reference in New Issue
Block a user