100 lines
4.8 KiB
JavaScript
100 lines
4.8 KiB
JavaScript
// Premier lancement : pas de programme, pas de proposition en attente.
|
|
// But : un programme dans l'app en moins de deux minutes, construit avec l'IA
|
|
// de l'utilisateur (ADR 0005, point 7 : le circuit par lien).
|
|
|
|
import { h } from "./dom.js";
|
|
import { actionBar } from "./layout.js";
|
|
import { toast } from "./feedback.js";
|
|
import { exampleProgram, onboardingBrief } from "./pending.js";
|
|
|
|
/** Consigne courte pour une IA qui sait lire une page web. */
|
|
export const AI_GUIDE_URL = "https://ia-fit.sans.pub/ia.md";
|
|
|
|
/**
|
|
* @param {{store: import("./store.js").Store}} o
|
|
*/
|
|
export function onboarding({ store }) {
|
|
const status = h("p", { class: "status status--ok", role: "status", "aria-live": "polite" });
|
|
const manual = h("div", { class: "manual-copy", hidden: true });
|
|
|
|
const copyBrief = async () => {
|
|
const text = await onboardingBrief(location.origin);
|
|
if (!text) {
|
|
// À brancher : ai-brief.buildOnboardingBrief({baseUrl}) (autre sous-agent).
|
|
status.textContent = "Le texte à donner à ton IA arrive bientôt. En attendant, dis-lui de lire " + AI_GUIDE_URL + ".";
|
|
return;
|
|
}
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
status.textContent = "Copié. Colle-le maintenant dans ton IA.";
|
|
toast("Texte copié.");
|
|
} catch {
|
|
// Presse-papiers refusé (http, navigateur ancien) : copie à la main.
|
|
const area = h("textarea", { class: "field__input field__input--area", readonly: true, "aria-label": "Texte à copier dans ton IA" });
|
|
area.value = text;
|
|
manual.replaceChildren(h("p", { class: "muted" }, "Copie ce texte à la main :"), area);
|
|
manual.hidden = false;
|
|
area.select();
|
|
status.textContent = "";
|
|
}
|
|
};
|
|
|
|
const startFromExample = async () => {
|
|
const program = await exampleProgram();
|
|
if (!program) {
|
|
// À brancher : example-program.EXAMPLE_PROGRAM (autre sous-agent).
|
|
toast("Le programme d'exemple arrive bientôt.");
|
|
return;
|
|
}
|
|
try {
|
|
store.dispatch("ProgramProposed", {
|
|
program,
|
|
source: /** @type {any} */ ("example"),
|
|
reason: "Programme d'exemple : trois séances à domicile avec barre, haltères, banc et élastiques. Ton IA pourra l'adapter ensuite.",
|
|
});
|
|
} catch (e) {
|
|
toast("Le programme d'exemple n'a pas pu être proposé : " + (e instanceof Error ? e.message : String(e)));
|
|
}
|
|
};
|
|
|
|
const copyGuide = async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(`Lis ${AI_GUIDE_URL}`);
|
|
toast("Phrase copiée.");
|
|
} catch {
|
|
toast("Copie impossible : recopie l'adresse à la main.");
|
|
}
|
|
};
|
|
|
|
return h("div", { class: "onboarding" },
|
|
h("header", { class: "screen-head hero" },
|
|
h("p", { class: "kicker" }, "IA-Fit"),
|
|
h("h1", { class: "title title--hero" }, "Ton programme, construit avec ton IA"),
|
|
h("p", { class: "lede" }, "Puis suivi séance par séance : séries, charges, repos. Tes données restent sur ton appareil, sans compte.")),
|
|
|
|
h("section", { class: "card card--today", "aria-labelledby": "onb-how" },
|
|
h("h2", { class: "card__title", id: "onb-how" }, "En trois gestes"),
|
|
h("ol", { class: "how" },
|
|
h("li", { class: "how__step" }, h("strong", null, "Copie le texte"), h("span", null, " et colle-le dans ton IA : Claude, ChatGPT, Le Chat…")),
|
|
h("li", { class: "how__step" }, h("strong", null, "Réponds à ses questions"), h("span", null, ", ou montre-lui ton programme actuel : export d'une autre app, texte, captures d'écran.")),
|
|
h("li", { class: "how__step" }, h("strong", null, "Touche le lien qu'elle te renvoie"), h("span", null, " : ton programme s'affiche ici, et tu le valides."))),
|
|
status,
|
|
manual,
|
|
h("p", { class: "card__hint" },
|
|
"Ou dis simplement à ton IA : ",
|
|
h("code", { class: "inline-code" }, `lis ${AI_GUIDE_URL}`),
|
|
" ",
|
|
h("button", { type: "button", class: "link-btn", on: { click: copyGuide } }, "Copier")),
|
|
h("p", { class: "card__hint" }, "Connecteur MCP pour ton IA : bientôt.")),
|
|
|
|
h("section", { class: "alt", "aria-label": "Autres façons de commencer" },
|
|
h("button", { type: "button", class: "btn btn--block", on: { click: startFromExample } }, "Partir d'un programme d'exemple"),
|
|
// À brancher : import d'un instantané (snapshot.js, autre sous-agent).
|
|
h("button", { type: "button", class: "btn btn--block btn--ghost", disabled: true, "aria-describedby": "onb-restore" }, "Restaurer une sauvegarde"),
|
|
h("p", { class: "muted", id: "onb-restore" }, "Restaurer une sauvegarde : bientôt.")),
|
|
|
|
h("footer", { class: "foot" }, "Rien ne part sur un serveur : ce que tu colles dans ton IA, c'est toi qui le choisis."),
|
|
|
|
actionBar(h("button", { type: "button", class: "btn btn--primary btn--block btn--lg", on: { click: copyBrief } }, "Créer mon programme avec mon IA")));
|
|
}
|