Semaine, poids, activités et date de séance dans l'adresse (lot 3c)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-18 14:53:45 +01:00
co-authored by Claude Opus 5.5
parent 30a1a3b56d
commit 4844c7b8e7
13 changed files with 317 additions and 37 deletions
+23 -2
View File
@@ -43,10 +43,22 @@ export function withActivity(program, { id, activity }) {
}
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string}} ctx
* L'activité en cours de modification, lue dans la requête de l'adresse
* (modifier=<id>, ADR 0009). Un id inconnu est ignoré.
* @param {string} query partie après « ? »
* @param {Activity[]} activities
* @returns {Activity|null}
*/
export function readEditedActivity(query, activities) {
const id = new URLSearchParams(query).get("modifier");
return activities.find((a) => a.id === id) ?? null;
}
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
* @returns {import("../router.js").Screen}
*/
export function activitiesScreen({ store, nav, today }) {
export function activitiesScreen({ store, nav, today, query }) {
const list = h("div");
const back = { label: "Accueil", onClick: () => nav.back(href.home()) };
if (!store.getState().program) {
@@ -80,8 +92,11 @@ export function activitiesScreen({ store, nav, today }) {
intBtns.forEach((b) => b.addEventListener("click", () => { intensity = /** @type {string} */ (b.dataset.intensity); paintChoices(); }));
const cancel = h("button", { type: "button", class: "btn btn--ghost btn--block", hidden: true }, "Annuler la modification");
// L'activité modifiée est dans l'adresse (ADR 0009) : l'ouvrir empile une
// entrée, la refermer la remplace. Les champs restent un brouillon hors adresse.
const reset = () => {
editing = null;
nav.set(href.activities());
zones.clear();
zones.add("cardio");
intensity = "moderate";
@@ -95,6 +110,7 @@ export function activitiesScreen({ store, nav, today }) {
/** @param {Activity} a */
const load = (a) => {
nav.set(href.activities(a.id), { push: editing === null });
editing = a.id;
zones.clear();
a.zones.forEach((z) => zones.add(z));
@@ -169,6 +185,11 @@ export function activitiesScreen({ store, nav, today }) {
};
paint();
paintChoices();
const edited = readEditedActivity(query, store.getState().program?.activities ?? []);
if (edited) {
editing = edited.id; // déjà dans l'adresse : rien à empiler
load(edited);
}
const node = h("div", { class: "screen" },
screenHeader({ back, kicker: "Hors programme", title: "Activités", sub: "Foot, escalade, vélo… Le planning en tient compte : une activité cardio remplace une sortie, une activité intense éloigne la séance qui travaille les mêmes zones." }),
+2
View File
@@ -71,6 +71,8 @@ export function sessionScreen({ store, key, date, nav, timer }) {
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;
// L'adresse suit la date (ADR 0009) ; le brouillon reste la source.
nav.set(href.session(key, draft.date === today ? null : draft.date));
paintDate();
onChange();
});
+47 -7
View File
@@ -4,7 +4,7 @@
// (PlanSettingsChanged) et les faits (SessionLogged, DaySkipped…) sont au journal.
import { h, paintWhenIdle, replace } from "../dom.js";
import { addDays, mondayOf } from "../../domain/dates.js";
import { addDays, isoWeek, mondayOf, mondayOfIsoWeek } from "../../domain/dates.js";
import { settingsForWeek } from "../../domain/planning.js";
import { buildIcs } from "../../domain/ics.js";
import { DAY_LETTERS, DAY_NAMES, DAY_SHORT, dayName, lockOptions, loggedForSlot, sessionForSlot, slotLabel, weekRows, withDays, withLock } from "../home-model.js";
@@ -18,13 +18,47 @@ import { plaque } from "./home.js";
/** @typedef {import("../home-model.js").WeekRow} WeekRow */
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string}} ctx
* Lit l'état de l'écran dans la requête de l'adresse (ADR 0009) : la semaine
* affichée (semaine=AAAA-Www, la suivante ou, par défaut, celle en cours) et le
* jour déplié (jour=1 pour lundi … 7). Une valeur invalide est ignorée ; une
* semaine qui n'est ni l'une ni l'autre revient à la semaine en cours.
* @param {string} query partie après « ? »
* @param {string} today
* @returns {{tab: 0|1, day: number|null}} day : 0 (lundi) à 6
*/
export function readWeekQuery(query, today) {
const p = new URLSearchParams(query);
const monday = mondayOfIsoWeek(p.get("semaine") ?? "");
const tab = monday === addDays(mondayOf(today), 7) ? 1 : 0;
const day = Number(p.get("jour"));
return { tab, day: Number.isInteger(day) && day >= 1 && day <= 7 ? day - 1 : null };
}
/**
* L'adresse de l'écran pour cet état : la semaine en cours et aucun jour déplié
* sont omis.
* @param {0|1} tab @param {number|null} day 0 (lundi) à 6 @param {string} today
*/
export function weekHref(tab, day, today) {
return href.week({ week: tab === 1 ? isoWeek(addDays(today, 7)) : null, day: day === null ? null : day + 1 });
}
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
* @returns {import("../router.js").Screen}
*/
export function weekScreen({ store, nav, today }) {
let tab = 0;
export function weekScreen({ store, nav, today, query }) {
const initial = readWeekQuery(query, today());
/** @type {0|1} */
let tab = initial.tab;
/** @type {number|null} */
let lockOpen = null;
let lockOpen = initial.day;
/**
* Garde l'adresse à jour : l'onglet la remplace (un filtre), le jour qu'on
* déplie l'empile (un élément ouvert, que le retour referme).
* @param {{push?: boolean}} [options]
*/
const syncAddress = (options) => nav.set(weekHref(tab, lockOpen, today()), options);
const zone = h("div", { class: "week" });
const status = h("p", { class: "status status--ok", role: "status", "aria-live": "polite" });
@@ -49,7 +83,7 @@ export function weekScreen({ store, nav, today }) {
const tabs = h("div", { class: "segmented", role: "group", "aria-label": "Semaine affichée" },
["Cette semaine", "Semaine suivante"].map((label, i) => h("button", {
type: "button", class: "segmented__opt", "aria-pressed": String(tab === i),
on: { click: () => { tab = i; lockOpen = null; status.textContent = ""; paint(); } },
on: { click: () => { tab = /** @type {0|1} */ (i); lockOpen = null; status.textContent = ""; syncAddress(); paint(); } },
}, label)));
const days = h("div", { class: "segmented segmented--days", role: "group", "aria-label": "Jours où je peux m'entraîner" },
@@ -84,7 +118,12 @@ export function weekScreen({ store, nav, today }) {
const head = h("button", {
type: "button", class: "week__day", "aria-expanded": String(lockOpen === r.day),
"aria-label": `${DAY_NAMES[r.day]} ${shortDay(r.date)} : ${title}${detail ? ", " + detail : ""}${state ? ", " + state : ""}. Choisir ce que porte ce jour.`,
on: { click: () => { lockOpen = lockOpen === r.day ? null : r.day; paint(); } },
on: { click: () => {
const wasClosed = lockOpen === null;
lockOpen = lockOpen === r.day ? null : r.day;
syncAddress({ push: wasClosed && lockOpen !== null });
paint();
} },
},
h("span", { class: "row__day" }, h("span", { class: "mark" }, DAY_SHORT[r.day]), h("span", { class: "num" }, r.date.slice(8))),
mark,
@@ -99,6 +138,7 @@ export function weekScreen({ store, nav, today }) {
save(withLock(settings, r.day, o.value));
status.textContent = `${DAY_NAMES[r.day]} : ${o.label.toLowerCase()}.`;
lockOpen = null;
syncAddress();
paint();
} },
}, o.label))));
+16 -6
View File
@@ -10,15 +10,25 @@ import { href } from "../router.js";
import { lineChart } from "../chart.js";
import { toast } from "../feedback.js";
/** Périodes de la courbe, en jours (Infinity : tout). */
const PERIODS = [{ days: 90, label: "3 mois" }, { days: 365, label: "1 an" }, { days: Infinity, label: "Tout" }];
/** Périodes de la courbe, en jours (Infinity : tout), et leur nom dans l'adresse. La première est celle par défaut. */
const PERIODS = [{ days: 90, label: "3 mois", param: "3mois" }, { days: 365, label: "1 an", param: "1an" }, { days: Infinity, label: "Tout", param: "tout" }];
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string}} ctx
* La période de la courbe lue dans la requête de l'adresse (periode=3mois|1an|tout,
* ADR 0009), en jours. Absente ou inconnue : 3 mois.
* @param {string} query partie après « ? »
*/
export function readPeriod(query) {
const param = new URLSearchParams(query).get("periode");
return (PERIODS.find((p) => p.param === param) ?? PERIODS[0]).days;
}
/**
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
* @returns {import("../router.js").Screen}
*/
export function weightScreen({ store, nav, today }) {
let period = 90;
export function weightScreen({ store, nav, today, query }) {
let period = readPeriod(query);
const summary = h("div");
const chartZone = h("div");
const milestones = h("div");
@@ -79,7 +89,7 @@ export function weightScreen({ store, nav, today }) {
const pts = inPeriod.length > 1 ? inPeriod : weights;
replace(chartZone,
h("div", { class: "segmented", role: "group", "aria-label": "Période de la courbe" }, PERIODS.map((p) =>
h("button", { type: "button", class: "segmented__opt", "aria-pressed": String(p.days === period), on: { click: () => { period = p.days; paint(); } } }, p.label))),
h("button", { type: "button", class: "segmented__opt", "aria-pressed": String(p.days === period), on: { click: () => { period = p.days; nav.set(href.weight(p.param)); paint(); } } }, p.label))),
pts.length > 1
? h("figure", { class: "chart" },
lineChart({