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:
co-authored by
Claude Opus 5.5
parent
30a1a3b56d
commit
4844c7b8e7
+47
-7
@@ -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))));
|
||||
|
||||
Reference in New Issue
Block a user