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
+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({