@composable-os/pack-programs 0.1.0-beta.11 → 0.1.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/authoring.d.ts +4 -1
  2. package/dist/authoring.js +65 -5
  3. package/dist/blocks/programs-builder/program-builder.d.ts +12 -3
  4. package/dist/blocks/programs-builder/program-builder.js +16 -3
  5. package/dist/blocks/programs-class-today/class-today.d.ts +1 -1
  6. package/dist/blocks/programs-coach-client/coach-client.d.ts +1 -1
  7. package/dist/blocks/programs-history/history.d.ts +11 -0
  8. package/dist/blocks/programs-history/history.js +84 -0
  9. package/dist/blocks/programs-native-class-today/class-today-screen.js +3 -2
  10. package/dist/blocks/programs-native-coach-client/coach-client-screen.js +2 -2
  11. package/dist/blocks/programs-native-history/history-screen.d.ts +11 -0
  12. package/dist/blocks/programs-native-history/history-screen.js +98 -0
  13. package/dist/blocks/programs-native-progress/progress-screen.js +4 -4
  14. package/dist/blocks/programs-native-session/session-screen.d.ts +6 -2
  15. package/dist/blocks/programs-native-session/session-screen.js +214 -88
  16. package/dist/blocks/programs-native-today/today-screen.d.ts +1 -1
  17. package/dist/blocks/programs-native-today/today-screen.js +22 -3
  18. package/dist/blocks/programs-session/session-view.d.ts +7 -3
  19. package/dist/blocks/programs-session/session-view.js +139 -81
  20. package/dist/blocks/programs-today/today.d.ts +1 -1
  21. package/dist/client/index.d.ts +367 -12
  22. package/dist/client/index.js +393 -12
  23. package/dist/client/logging.d.ts +289 -0
  24. package/dist/client/logging.js +558 -0
  25. package/dist/index.d.ts +152 -6
  26. package/dist/index.js +141 -6
  27. package/dist/layout.d.ts +3 -1
  28. package/dist/layout.js +10 -2
  29. package/dist/tools.d.ts +25 -2
  30. package/dist/tools.js +269 -37
  31. package/package.json +3 -3
@@ -1,65 +1,135 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // One session to do (stage 41): its plan with every target, last time's numbers at each exercise,
3
- // a row per set to log what was done and how hard it felt, a rest timer after each set, and
4
- // marking the session done. For a member (their own, or a class's: they choose the level they
5
- // take) and for a coach logging for a client (`personId`). Built on the web base layer.
2
+ // One session to do (stage 41): the workout logger, built on the web base layer. Its plan with
3
+ // every target and last time's numbers; a row per set with its numbers and a tick. One tap on a
4
+ // tick logs the set with the numbers shown (a suggestion, greyed, until the person types; a number
5
+ // still being typed counts); a tick of a done set takes it back, and typing over a done set's
6
+ // numbers changes it. Effort (RPE) is an optional tap. A tick starts the rest timer (the set's rest,
7
+ // else `defaultRest`); a timed set has a start/stop timer that fills its seconds and ticks it; an
8
+ // exercise folds away when its last set is ticked; the sets done show at the top; finishing says
9
+ // what was not ticked. For a member (their own, or a class's: they choose the level they take) and
10
+ // for a coach logging for a client (`personId`).
6
11
  //
7
- // It holds no rules: the targets, the last numbers and whose session it is come from the host
8
- // (`useSession`); a set is logged by the host, which takes its target from the plan and refuses a
9
- // session the caller may not log on; effort's bounds are the host's too.
10
- import { describeSet, describeSets, levelExercises, levelLabel, loggedFor, numberFrom, } from "@composable-os/pack-programs/client";
12
+ // It is the mobile session's logic (`useSessionLog`, the pack's one queue): every change shows at
13
+ // once and is saved in order, retried when it fails, and flushed when the page is hidden. It holds
14
+ // no rules: the targets, the last numbers and whose session it is come from the host; a set is
15
+ // logged by the host, which takes its target from the plan, refuses a session the caller may not
16
+ // log on and says why it refused a set; effort's bounds are the host's too.
17
+ import { describeSet, describeSets, EFFORTS, exerciseDone, exerciseKey, levelExercises, levelLabel, levelOf, notTickedText, progressOf, restAfter, secondsBetween, setKey, setRow, timed, unsaved, weighed, } from "@composable-os/pack-programs/client";
11
18
  import { useEffect, useState } from "react";
12
19
  import { Button } from "../ui-button/button.js";
13
20
  import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
14
21
  import { Input } from "../ui-input/input.js";
15
- export function SessionView({ programs, sessionId, personId, onRestDone, }) {
16
- const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
22
+ export function SessionView({ programs, sessionId, personId, onRestDone, defaultRest = 90, }) {
23
+ const { detail, log, state } = programs.useSessionLog({
24
+ sessionId,
25
+ ...(personId ? { personId } : {}),
26
+ });
17
27
  const mark = programs.useMarkSession();
18
- const [rest, setRest] = useState(null);
28
+ const [now, setNow] = useState(Date.now());
29
+ const [restUntil, setRestUntil] = useState(null);
30
+ const [clock, setClock] = useState(null);
31
+ const [finishing, setFinishing] = useState(null);
32
+ const [said, setSaid] = useState(null);
33
+ // Nothing waits when the page is hidden or the view closed: what is queued is sent now.
19
34
  useEffect(() => {
20
- if (rest === null)
35
+ const target = globalThis;
36
+ const send = () => void log.flush();
37
+ target.addEventListener?.("pagehide", send);
38
+ target.addEventListener?.("visibilitychange", send);
39
+ return () => {
40
+ target.removeEventListener?.("pagehide", send);
41
+ target.removeEventListener?.("visibilitychange", send);
42
+ send();
43
+ };
44
+ }, [log]);
45
+ const ticking = restUntil !== null || clock !== null;
46
+ useEffect(() => {
47
+ if (!ticking)
21
48
  return undefined;
22
- if (rest <= 0) {
23
- setRest(null);
49
+ const timer = setInterval(() => setNow(Date.now()), 250);
50
+ return () => clearInterval(timer);
51
+ }, [ticking]);
52
+ useEffect(() => {
53
+ if (restUntil !== null && now >= restUntil) {
54
+ setRestUntil(null);
24
55
  onRestDone?.();
25
- return undefined;
26
56
  }
27
- const timer = setTimeout(() => setRest((s) => (s === null ? null : s - 1)), 1000);
28
- return () => clearTimeout(timer);
29
- }, [rest, onRestDone]);
57
+ }, [now, restUntil, onRestDone]);
30
58
  if (detail.isPending)
31
59
  return _jsx("p", { "aria-busy": "true", children: "Loading the session\u2026" });
32
60
  if (detail.error || !detail.data)
33
61
  return _jsx("p", { role: "alert", children: "We could not load this session." });
34
- const { session, exercises, logged } = detail.data;
62
+ const { session, exercises } = detail.data;
35
63
  const plan = session.plan;
36
64
  const byId = new Map(exercises.map((e) => [e.id, e]));
37
- const refresh = () => detail.refetch?.();
65
+ const progress = progressOf(state);
66
+ const waiting = unsaved(state);
67
+ const restFor = restUntil === null ? null : secondsBetween(now, restUntil);
68
+ const shared = {
69
+ log,
70
+ state,
71
+ now,
72
+ clock,
73
+ onClock: (next) => {
74
+ setClock(next);
75
+ setNow(Date.now());
76
+ },
77
+ onTicked: (target) => {
78
+ setRestUntil(Date.now() + restAfter(target, defaultRest) * 1000);
79
+ setNow(Date.now());
80
+ },
81
+ };
82
+ const finish = async (anyway) => {
83
+ setSaid(null);
84
+ const missing = notTickedText(state, (id) => byId.get(id)?.name);
85
+ if (missing && !anyway) {
86
+ setFinishing(missing);
87
+ return;
88
+ }
89
+ setFinishing(null);
90
+ if (!(await log.flush())) {
91
+ setSaid("Some sets are not saved yet. They stay here and are sent when the connection is back: try finishing again then.");
92
+ return;
93
+ }
94
+ if (session.kind !== "personal") {
95
+ setSaid("All your sets are saved.");
96
+ return;
97
+ }
98
+ try {
99
+ await mark.mutateAsync({ sessionId, state: "done" });
100
+ detail.refetch?.();
101
+ }
102
+ catch (e) {
103
+ setSaid(e.message ?? "We could not mark the session done.");
104
+ }
105
+ };
38
106
  return (_jsxs(Card, { "data-testid": "session-view", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: session.name }), _jsx(CardDescription, { children: [session.programTitle, session.classTypeName, session.date, session.focus]
39
107
  .filter(Boolean)
40
- .join(" · ") })] }), _jsxs(CardContent, { className: "grid gap-5", children: [rest !== null ? (_jsxs("div", { role: "timer", "aria-live": "polite", className: "flex items-center gap-3 rounded-md bg-muted p-3", children: [_jsxs("strong", { className: "text-2xl tabular-nums", children: [rest, "s"] }), " rest", _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setRest(null), children: "Skip" })] })) : null, plan?.warmup?.text || plan?.warmup?.exercises?.length ? (_jsxs("section", { "aria-label": "Warm-up", className: "grid gap-1 text-sm", children: [_jsx("h3", { className: "font-semibold", children: "Warm-up" }), plan.warmup.text ? _jsx("p", { className: "whitespace-pre-wrap", children: plan.warmup.text }) : null, _jsx("ul", { children: (plan.warmup.exercises ?? []).map((p, i) => (_jsxs("li", { children: [byId.get(p.exercise)?.name ?? "Exercise", ": ", describeSets(p.sets)] }, i))) })] })) : null, (plan?.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), (plan?.blocks ?? []).map((block) => (_jsxs("section", { "aria-label": `Block ${block.label}`, className: "grid gap-3", children: [_jsxs("h3", { className: "font-semibold", children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), block.items.map((item) => (_jsx(ItemToDo, { programs: programs, sessionId: sessionId, personId: personId, item: item, exercises: byId, logged: logged, onLogged: (target) => {
41
- refresh();
42
- if (target?.rest)
43
- setRest(target.rest);
44
- } }, item.label)))] }, block.label))), session.kind === "personal" ? (_jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { disabled: mark.isPending || session.state === "done", onClick: async () => {
45
- await mark.mutateAsync({ sessionId, state: "done" });
46
- refresh();
47
- }, children: session.state === "done" ? "Done" : "Mark done" }), session.state !== "done" ? (_jsx(Button, { variant: "ghost", disabled: mark.isPending, onClick: async () => {
108
+ .join(" · ") })] }), _jsxs(CardContent, { className: "grid gap-5", children: [_jsxs("div", { className: "grid gap-1", "data-testid": "progress", children: [_jsxs("span", { className: "text-sm font-medium", children: [progress.done, " of ", progress.planned, " sets"] }), _jsx("progress", { className: "h-1.5 w-full", max: progress.planned || 1, value: progress.done })] }), waiting && state.failure ? (_jsxs("div", { role: "alert", className: "flex items-center gap-3 rounded-md border border-destructive p-3 text-sm", children: [_jsxs("span", { children: [waiting === 1 ? "1 set is" : `${waiting} sets are`, " not saved yet. ", state.failure] }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void log.flush(), children: "Try now" })] })) : null, restFor !== null ? (_jsxs("div", { role: "timer", "aria-live": "polite", className: "flex items-center gap-3 rounded-md bg-muted p-3", children: [_jsxs("strong", { className: "text-2xl tabular-nums", children: [restFor, "s"] }), " rest", _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setRestUntil((t) => (t ?? Date.now()) + 30_000), children: "+30 s" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setRestUntil(null), children: "Skip" })] })) : null, plan?.warmup?.text || plan?.warmup?.exercises?.length ? (_jsxs("section", { "aria-label": "Warm-up", className: "grid gap-1 text-sm", children: [_jsx("h3", { className: "font-semibold", children: "Warm-up" }), plan.warmup.text ? _jsx("p", { className: "whitespace-pre-wrap", children: plan.warmup.text }) : null, _jsx("ul", { children: (plan.warmup.exercises ?? []).map((p, i) => (_jsxs("li", { children: [byId.get(p.exercise)?.name ?? "Exercise", ": ", describeSets(p.sets)] }, i))) })] })) : null, (plan?.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), (plan?.blocks ?? []).map((block) => (_jsxs("section", { "aria-label": `Block ${block.label}`, className: "grid gap-3", children: [_jsxs("h3", { className: "font-semibold", children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), block.items.map((item) => (_jsx(ItemToDo, { item: item, exercises: byId, shared: shared }, item.label)))] }, block.label))), finishing ? (_jsxs("div", { role: "alert", className: "grid gap-2 rounded-md border p-3 text-sm", children: [_jsxs("p", { children: ["Not ticked: ", finishing, "."] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { size: "sm", onClick: () => void finish(true), children: "Finish anyway" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setFinishing(null), children: "Keep going" })] })] })) : null, said ? _jsx("p", { "aria-live": "polite", children: said }) : null, _jsxs("div", { className: "flex gap-2", children: [session.state === "done" ? (_jsx(Button, { disabled: true, children: "Done" })) : (_jsx(Button, { disabled: mark.isPending, onClick: () => void finish(false), children: "Finish session" })), session.kind === "personal" && session.state !== "done" ? (_jsx(Button, { variant: "ghost", disabled: mark.isPending, onClick: async () => {
48
109
  await mark.mutateAsync({ sessionId, state: "skipped" });
49
- refresh();
50
- }, children: "Skip this session" })) : null] })) : null] })] }));
110
+ detail.refetch?.();
111
+ }, children: "Skip this session" })) : null] })] })] }));
51
112
  }
52
- function ItemToDo({ programs, sessionId, personId, item, exercises, logged, onLogged, }) {
53
- const taken = logged.find((l) => l.item === item.label)?.level ?? null;
54
- const [chosen, setChosen] = useState(taken);
113
+ function ItemToDo({ item, exercises, shared, }) {
55
114
  const levels = item.kind === "levels" ? item.levels : [];
56
- const level = levels.find((l) => l.level === chosen) ?? (levels.length === 1 ? levels[0] : undefined);
57
- const prescriptions = item.kind === "all" ? item.exercises : level ? levelExercises(level) : [];
58
- return (_jsxs("div", { className: "grid gap-2 rounded-md border p-3", "data-testid": "item-to-do", "data-item": item.label, children: [_jsx("div", { className: "font-medium", children: item.label }), (item.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), levels.length > 1 ? (_jsx("fieldset", { className: "flex flex-wrap gap-1", "aria-label": "The level you take", children: levels.map((l) => (_jsx(Button, { size: "sm", variant: l.level === level?.level ? "default" : "outline", "aria-pressed": l.level === level?.level, onClick: () => setChosen(l.level), children: levelLabel(l) }, l.level))) })) : null, level?.mode === "alternatives" ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Do one of these." })) : null, prescriptions.map((p) => (_jsx(ExerciseToDo, { programs: programs, sessionId: sessionId, personId: personId, itemLabel: item.label, level: item.kind === "levels" ? level?.level : undefined, prescription: p, exercise: exercises.get(p.exercise), logged: logged, onLogged: onLogged }, p.exercise))), item.kind === "levels" && !level ? (_jsx("p", { className: "text-sm", children: "Choose the level you take to log it." })) : null] }));
115
+ const chosen = levelOf(shared.state, item.label);
116
+ const level = levels.find((l) => l.level === chosen);
117
+ // Everyone's exercises (beside the levels, if any), then the level's.
118
+ const prescriptions = item.kind === "all"
119
+ ? item.exercises
120
+ : [...(item.exercises ?? []), ...(level ? levelExercises(level) : [])];
121
+ return (_jsxs("div", { className: "grid gap-2 rounded-md border p-3", "data-testid": "item-to-do", "data-item": item.label, children: [_jsx("div", { className: "font-medium", children: item.label }), (item.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), levels.length > 1 ? (_jsx("fieldset", { className: "flex flex-wrap gap-1", "aria-label": "The level you take", children: levels.map((l) => (_jsx(Button, { size: "sm", variant: l.level === level?.level ? "default" : "outline", "aria-pressed": l.level === level?.level, onClick: () => shared.log.dispatch({ type: "level", item: item.label, level: l.level }), children: levelLabel(l) }, l.level))) })) : null, level?.mode === "alternatives" ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Do one of these." })) : null, prescriptions.map((p) => (_jsx(ExerciseToDo, { itemLabel: item.label, prescription: p, exercise: exercises.get(p.exercise), shared: shared }, p.exercise))), item.kind === "levels" && !level ? (_jsx("p", { className: "text-sm", children: "Choose the level you take to log it." })) : null] }));
59
122
  }
60
- function ExerciseToDo({ programs, sessionId, personId, itemLabel, level, prescription, exercise, logged, onLogged, }) {
123
+ function ExerciseToDo({ itemLabel, prescription, exercise, shared, }) {
124
+ const [open, setOpen] = useState(false);
125
+ const folded = exerciseDone(shared.state, itemLabel, prescription.exercise);
61
126
  const last = exercise?.last ?? [];
62
- return (_jsxs("div", { className: "grid gap-2", "data-testid": "exercise-to-do", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-2", children: [_jsx("strong", { children: exercise?.name ?? "Exercise" }), _jsx("span", { className: "text-sm text-muted-foreground", children: describeSets(prescription.sets) }), exercise?.video ? (_jsx("a", { href: exercise.video, target: "_blank", rel: "noreferrer", className: "text-sm underline", children: "Demo" })) : null] }), prescription.note ? _jsx("p", { className: "text-sm", children: prescription.note }) : null, exercise?.cues ? _jsx("p", { className: "text-xs text-muted-foreground", children: exercise.cues }) : null, last.length ? (_jsxs("p", { className: "text-xs text-muted-foreground", "data-testid": "last-time", children: ["Last time (", last[0]?.date, "):", " ", last
127
+ const name = exercise?.name ?? "Exercise";
128
+ const withLoad = weighed(shared.state.exercises[exerciseKey(itemLabel, prescription.exercise)], exercise?.measure ?? null);
129
+ if (folded && !open) {
130
+ return (_jsxs("button", { type: "button", className: "flex items-baseline justify-between text-left text-sm", "data-testid": "exercise-folded", onClick: () => setOpen(true), children: [_jsxs("strong", { children: ["\u2713 ", name] }), _jsxs("span", { className: "text-muted-foreground", children: [prescription.sets.length, " sets done"] })] }));
131
+ }
132
+ return (_jsxs("div", { className: "grid gap-2", "data-testid": "exercise-to-do", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-2", children: [_jsx("strong", { children: name }), _jsx("span", { className: "text-sm text-muted-foreground", children: describeSets(prescription.sets) }), exercise?.video ? (_jsx("a", { href: exercise.video, target: "_blank", rel: "noreferrer", className: "text-sm underline", children: "Demo" })) : null, folded ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => setOpen(false), children: "Fold" })) : null] }), prescription.note ? _jsx("p", { className: "text-sm", children: prescription.note }) : null, exercise?.cues ? _jsx("p", { className: "text-xs text-muted-foreground", children: exercise.cues }) : null, last.length ? (_jsxs("p", { className: "text-xs text-muted-foreground", "data-testid": "last-time", children: ["Last time (", last[0]?.date, "):", " ", last
63
133
  .map((s) => [
64
134
  s.reps !== null ? `${s.reps} reps` : null,
65
135
  s.seconds !== null ? `${s.seconds} s` : null,
@@ -69,48 +139,36 @@ function ExerciseToDo({ programs, sessionId, personId, itemLabel, level, prescri
69
139
  .join(" "))
70
140
  .join(", ")] })) : null, _jsx("ol", { className: "grid gap-1", children: prescription.sets.map((set, i) => (_jsx(SetRow
71
141
  // biome-ignore lint/suspicious/noArrayIndexKey: sets are positions.
72
- , { programs: programs, sessionId: sessionId, personId: personId, itemLabel: itemLabel, level: level, exerciseId: prescription.exercise, setNumber: i + 1, target: set, done: loggedFor(logged, itemLabel, prescription.exercise, i + 1), onLogged: onLogged }, i))) })] }));
142
+ , { itemLabel: itemLabel, exerciseId: prescription.exercise, setNumber: i + 1, target: set, withLoad: withLoad, shared: shared }, i))) })] }));
73
143
  }
74
- function SetRow({ programs, sessionId, personId, itemLabel, level, exerciseId, setNumber, target, done, onLogged, }) {
75
- const add = programs.useLogSet();
76
- const update = programs.useUpdateSet();
77
- const timed = target.kind !== "reps";
78
- const [count, setCount] = useState(String((timed ? done?.actual.seconds : done?.actual.reps) ?? (timed ? target.seconds : target.reps)));
79
- const [load, setLoad] = useState(String(done?.actual.load ?? target.load ?? ""));
80
- const [effort, setEffort] = useState(String(done?.rpe ?? ""));
81
- const [error, setError] = useState(null);
82
- const busy = add.isPending || update.isPending;
83
- const actual = {
84
- ...(timed ? { seconds: numberFrom(count) } : { reps: numberFrom(count) }),
85
- ...(numberFrom(load) !== undefined ? { load: numberFrom(load) } : {}),
86
- };
87
- const rpe = numberFrom(effort);
88
- return (_jsxs("li", { className: "flex flex-wrap items-center gap-2 text-sm", "data-testid": "set-row", "data-done": Boolean(done), children: [_jsxs("span", { className: "w-12", children: ["Set ", setNumber] }), _jsx("span", { className: "w-40 text-muted-foreground", children: describeSet(target) }), _jsx(Input, { "aria-label": `Set ${setNumber} ${timed ? "seconds" : "reps"} done`, className: "h-8 w-16", inputMode: "numeric", value: count, onChange: (e) => setCount(e.target.value) }), _jsx(Input, { "aria-label": `Set ${setNumber} load`, placeholder: "kg", className: "h-8 w-16", inputMode: "decimal", value: load, onChange: (e) => setLoad(e.target.value) }), _jsx(Input, { "aria-label": `Set ${setNumber} effort`, placeholder: "RPE", className: "h-8 w-16", inputMode: "decimal", value: effort, onChange: (e) => setEffort(e.target.value) }), _jsx(Button, { size: "sm", variant: done ? "secondary" : "default", disabled: busy, onClick: async () => {
89
- setError(null);
90
- try {
91
- if (done) {
92
- await update.mutateAsync({
93
- logId: done.id,
94
- actual,
95
- ...(rpe !== undefined ? { rpe } : {}),
96
- });
97
- }
98
- else {
99
- await add.mutateAsync({
100
- sessionId,
101
- item: itemLabel,
102
- exerciseId,
103
- ...(level !== undefined ? { level } : {}),
104
- setNumber,
105
- actual,
106
- ...(rpe !== undefined ? { rpe } : {}),
107
- ...(personId ? { personId } : {}),
108
- });
109
- }
110
- onLogged(target);
111
- }
112
- catch (e) {
113
- setError(e.message ?? "Not logged");
114
- }
115
- }, children: done ? "Update" : "Log set" }), done ? _jsx("span", { title: "Logged", children: "\u2713" }) : null, error ? (_jsx("span", { role: "alert", className: "text-destructive", children: error })) : null] }));
144
+ function SetRow({ itemLabel, exerciseId, setNumber, target, withLoad, shared, }) {
145
+ const { log, state, now, clock, onClock, onTicked } = shared;
146
+ const at = { item: itemLabel, exercise: exerciseId, setNumber };
147
+ const row = setRow(state, itemLabel, exerciseId, setNumber);
148
+ const [effortOpen, setEffortOpen] = useState(false);
149
+ const count = timed(target) ? "seconds" : "reps";
150
+ const key = setKey(itemLabel, exerciseId, setNumber);
151
+ const running = clock?.key === key;
152
+ const field = (name, label, mode) => (_jsx(Input, { "aria-label": `Set ${setNumber} ${name === "load" ? "load" : `${name} done`}`, className: `h-9 w-16 text-center ${row.suggested ? "placeholder:text-muted-foreground" : ""}`, inputMode: mode,
153
+ // A suggestion is greyed (the placeholder); what the person typed or ticked is the value.
154
+ placeholder: row.suggested ? (row.values[name] ?? label) : label, value: row.suggested ? "" : (row.values[name] ?? ""), onChange: (e) => log.dispatch({ type: "edit", ...at, field: name, text: e.target.value }) }));
155
+ return (_jsxs("li", { className: "grid gap-1 text-sm", "data-testid": "set-row", "data-done": row.done, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "w-6 font-medium text-muted-foreground", children: setNumber }), field(count, count === "reps" ? "reps" : "s", "numeric"), withLoad ? field("load", "kg", "decimal") : null, _jsx(Button, { size: "sm", variant: "ghost", "aria-label": `Set ${setNumber} effort`, "aria-expanded": effortOpen, onClick: () => setEffortOpen((o) => !o), children: row.rpe !== null ? `@${row.rpe}` : "RPE" }), timed(target) && !row.done ? (_jsx(Button, { size: "sm", variant: running ? "default" : "outline", onClick: () => {
156
+ if (!running) {
157
+ onClock({ key, from: Date.now() });
158
+ return;
159
+ }
160
+ onClock(null);
161
+ const seconds = String(secondsBetween(clock?.from ?? Date.now(), Date.now()));
162
+ log.dispatch({ type: "tick", ...at, values: { seconds } });
163
+ onTicked(target);
164
+ }, children: running ? `Stop ${secondsBetween(clock?.from ?? now, now)} s` : "Start" })) : null, _jsx("button", { type: "button", "aria-pressed": row.done, "aria-label": `Set ${setNumber} done`, className: `flex h-9 w-9 items-center justify-center rounded-md border-2 ${row.done ? "border-primary bg-primary text-primary-foreground" : "text-muted-foreground"}`,
165
+ // Before the field loses focus: the tick takes the number as typed.
166
+ onPointerDown: (e) => e.preventDefault(), onClick: () => {
167
+ if (!row.done)
168
+ onTicked(target);
169
+ log.dispatch({ type: "toggle", ...at });
170
+ }, children: "\u2713" }), _jsx("span", { className: "text-muted-foreground", children: describeSet(target) })] }), effortOpen ? (_jsx("fieldset", { className: "flex flex-wrap gap-1", "aria-label": `Set ${setNumber} effort`, children: EFFORTS.map((e) => (_jsx(Button, { size: "sm", variant: row.rpe === e ? "default" : "outline", "aria-pressed": row.rpe === e, onClick: () => {
171
+ log.dispatch({ type: "rpe", ...at, rpe: row.rpe === e ? null : e });
172
+ setEffortOpen(false);
173
+ }, children: e }, e))) })) : null, row.error ? (_jsx("span", { role: "alert", className: "text-destructive", children: row.error })) : null] }));
116
174
  }
@@ -1,6 +1,6 @@
1
1
  import type { ProgramsHooks } from "@composable-os/pack-programs/client";
2
2
  export declare function Today({ programs, date, onRestDone, }: {
3
- programs: Pick<ProgramsHooks, "useLogSet" | "useMarkSession" | "useSession" | "useToday" | "useUpdateSet">;
3
+ programs: Pick<ProgramsHooks, "useMarkSession" | "useSessionLog" | "useToday">;
4
4
  /** The member's local date (YYYY-MM-DD); the host's UTC today when left out. */
5
5
  date?: string;
6
6
  onRestDone?: () => void;