@composable-os/pack-programs 0.1.0-beta.10 → 0.1.0-beta.13

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,108 +1,169 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- // One session to do, for the mobile app (stage 41): targets, last time's numbers, a row per set
3
- // to log what was done and how hard it felt, a rest timer, and marking it done. A member's own
2
+ // One session to do, for the mobile app (stage 41): the workout logger. Each set is a row with its
3
+ // numbers and a tick; one tap logs it with the numbers shown (a suggestion, greyed, until the
4
+ // person types), even with the keyboard open and a number half typed. A tick of a done set takes
5
+ // it back; typing over a done set's numbers changes it. Effort (RPE) is an optional tap. Ticking
6
+ // a set starts the rest timer (the set's rest time, else `defaultRest`); a timed set has a
7
+ // start/stop timer that fills its seconds and ticks it; an exercise folds away when its last set
8
+ // is ticked; the sets done show at the top; finishing says what was not ticked. A member's own
4
9
  // session, a class's (choose the level you take), or a coach logging for a client (`personId`).
5
- // The app gives the buzz at the end of a rest (`onRestDone`, for example `expo-haptics`), so this
6
- // block needs no device package. It holds no rules: targets, whose session it is and what may be
7
- // logged are the host's.
8
- import { describeSet, describeSets, levelExercises, levelLabel, loggedFor, numberFrom, } from "@composable-os/pack-programs/client";
10
+ //
11
+ // Every change shows at once and goes to the host through the pack's one queue
12
+ // (`useSessionLog`): in order, retried when it fails, flushed when the app goes to the background
13
+ // and when the screen is left, and it says when something could not be saved. The app gives the
14
+ // buzz at the end of a rest (`onRestDone`, for example `expo-haptics`), so this block needs no
15
+ // device package. It holds no rules: targets, whose session it is and what may be logged are the
16
+ // host's, and a set it refuses is shown with its reason.
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";
9
18
  import { useEffect, useState } from "react";
10
- import { StyleSheet, Text, View } from "react-native";
19
+ import { AppState, Pressable, StyleSheet, TextInput, View } from "react-native";
11
20
  import { Button } from "../native-base/button.js";
12
- import { Field } from "../native-base/field.js";
13
21
  import { Screen } from "../native-base/screen.js";
22
+ import { Text } from "../native-base/text.js";
14
23
  import { theme } from "../native-base/theme.js";
15
- export function SessionScreen({ programs, sessionId, personId, onRestDone, }) {
16
- const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
24
+ export function SessionScreen({ programs, sessionId, personId, onRestDone, defaultRest = 90, }) {
25
+ const { detail, log, state } = programs.useSessionLog({
26
+ sessionId,
27
+ ...(personId ? { personId } : {}),
28
+ });
17
29
  const mark = programs.useMarkSession();
18
- const [rest, setRest] = useState(null);
30
+ const [now, setNow] = useState(Date.now());
31
+ const [restUntil, setRestUntil] = useState(null);
32
+ const [clock, setClock] = useState(null);
33
+ const [finishing, setFinishing] = useState(null);
34
+ const [said, setSaid] = useState(null);
35
+ // Nothing waits when the app goes to the background or the screen is left: what is queued is
36
+ // sent now (and, if it cannot be, it stays queued and the screen says so when it is back).
19
37
  useEffect(() => {
20
- if (rest === null)
38
+ const sub = AppState.addEventListener("change", (next) => {
39
+ if (next !== "active")
40
+ void log.flush();
41
+ });
42
+ return () => {
43
+ sub.remove();
44
+ void log.flush();
45
+ };
46
+ }, [log]);
47
+ // One clock for the rest and a timed set, from timestamps, so a pause in the background
48
+ // does not drift.
49
+ const ticking = restUntil !== null || clock !== null;
50
+ useEffect(() => {
51
+ if (!ticking)
21
52
  return undefined;
22
- if (rest <= 0) {
23
- setRest(null);
53
+ const timer = setInterval(() => setNow(Date.now()), 250);
54
+ return () => clearInterval(timer);
55
+ }, [ticking]);
56
+ const restFor = restUntil === null ? null : secondsBetween(now, restUntil);
57
+ useEffect(() => {
58
+ if (restUntil !== null && now >= restUntil) {
59
+ setRestUntil(null);
24
60
  onRestDone?.();
25
- return undefined;
26
61
  }
27
- const timer = setTimeout(() => setRest((s) => (s === null ? null : s - 1)), 1000);
28
- return () => clearTimeout(timer);
29
- }, [rest, onRestDone]);
62
+ }, [now, restUntil, onRestDone]);
30
63
  if (detail.isPending)
31
- return (_jsx(Screen, { title: "Session", children: _jsx(Text, { children: "Loading\u2026" }) }));
64
+ return (_jsx(Screen, { title: "Session", children: _jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" }) }));
32
65
  if (!detail.data)
33
- return (_jsx(Screen, { title: "Session", children: _jsx(Text, { children: "We could not load this session." }) }));
34
- const { session, exercises, logged } = detail.data;
66
+ return (_jsx(Screen, { title: "Session", children: _jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load this session. Check the connection and try again." }) }));
67
+ const { session, exercises } = detail.data;
35
68
  const plan = session.plan;
36
69
  const names = new Map(exercises.map((e) => [e.id, e]));
37
- return (_jsxs(Screen, { title: session.name ?? "Session", children: [_jsx(Text, { style: styles.muted, children: [session.programTitle, session.classTypeName, session.date].filter(Boolean).join(" · ") }), rest !== null ? (_jsxs(View, { style: styles.timer, accessibilityRole: "timer", accessibilityLiveRegion: "polite", children: [_jsxs(Text, { style: styles.timerText, children: [rest, "s rest"] }), _jsx(Button, { quiet: true, label: "Skip", onPress: () => setRest(null) })] })) : null, plan?.warmup?.text ? _jsx(Text, { children: plan.warmup.text }) : null, (plan?.blocks ?? []).map((block) => (_jsxs(View, { style: styles.block, children: [_jsxs(Text, { style: styles.heading, children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), block.items.map((item) => (_jsx(NativeItem, { programs: programs, sessionId: sessionId, personId: personId, item: item, names: names, logged: logged, onLogged: (t) => {
38
- detail.refetch?.();
39
- if (t?.rest)
40
- setRest(t.rest);
41
- } }, item.label)))] }, block.label))), session.kind === "personal" ? (_jsx(Button, { label: session.state === "done" ? "Done" : "Mark done", busy: mark.isPending, disabled: session.state === "done", onPress: async () => {
42
- await mark.mutateAsync({ sessionId, state: "done" });
43
- detail.refetch?.();
44
- } })) : null] }));
70
+ const progress = progressOf(state);
71
+ const waiting = unsaved(state);
72
+ const startRest = (target) => {
73
+ setRestUntil(Date.now() + restAfter(target, defaultRest) * 1000);
74
+ setNow(Date.now());
75
+ };
76
+ const finish = async (anyway) => {
77
+ setSaid(null);
78
+ const missing = notTickedText(state, (id) => names.get(id)?.name);
79
+ if (missing && !anyway) {
80
+ setFinishing(missing);
81
+ return;
82
+ }
83
+ setFinishing(null);
84
+ if (!(await log.flush())) {
85
+ setSaid("Some sets are not saved yet. They stay on this phone and are sent when the connection is back: try finishing again then.");
86
+ return;
87
+ }
88
+ if (session.kind !== "personal") {
89
+ setSaid("All your sets are saved.");
90
+ return;
91
+ }
92
+ try {
93
+ await mark.mutateAsync({ sessionId, state: "done" });
94
+ detail.refetch?.();
95
+ }
96
+ catch (e) {
97
+ setSaid(e.message ?? "We could not mark the session done.");
98
+ }
99
+ };
100
+ return (_jsxs(Screen, { title: session.name ?? "Session", children: [_jsx(Text, { style: styles.muted, children: [session.programTitle, session.classTypeName, session.date].filter(Boolean).join(" · ") }), _jsxs(View, { accessibilityRole: "progressbar", style: styles.progress, children: [_jsxs(Text, { style: styles.heading, children: [progress.done, " of ", progress.planned, " sets"] }), _jsx(View, { style: styles.track, children: _jsx(View, { style: [
101
+ styles.fill,
102
+ {
103
+ width: `${progress.planned ? Math.round((progress.done / progress.planned) * 100) : 0}%`,
104
+ },
105
+ ] }) })] }), waiting && state.failure ? (_jsxs(View, { style: styles.warning, accessibilityLiveRegion: "polite", children: [_jsxs(Text, { style: styles.warningText, children: [waiting === 1 ? "1 set is" : `${waiting} sets are`, " not saved yet. ", state.failure] }), _jsx(Button, { quiet: true, label: "Try now", onPress: () => void log.flush() })] })) : null, restFor !== null ? (_jsxs(View, { style: styles.timer, accessibilityRole: "timer", accessibilityLiveRegion: "polite", children: [_jsxs(Text, { style: styles.timerText, children: [restFor, "s rest"] }), _jsx(Button, { quiet: true, label: "+30s", onPress: () => setRestUntil((t) => (t ?? Date.now()) + 30_000) }), _jsx(Button, { quiet: true, label: "Skip", onPress: () => setRestUntil(null) })] })) : null, plan?.warmup?.text ? _jsx(Text, { children: plan.warmup.text }) : null, (plan?.blocks ?? []).map((block) => (_jsxs(View, { style: styles.block, children: [_jsxs(Text, { style: styles.heading, children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), block.items.map((item) => (_jsx(NativeItem, { item: item, names: names, log: log, state: state, now: now, clock: clock, onClock: (next) => {
106
+ setClock(next);
107
+ setNow(Date.now());
108
+ }, onTicked: startRest }, item.label)))] }, block.label))), finishing ? (_jsxs(View, { style: styles.warning, children: [_jsxs(Text, { style: styles.warningText, children: ["Not ticked: ", finishing, "."] }), _jsxs(View, { style: styles.row, children: [_jsx(Button, { label: "Finish anyway", onPress: () => void finish(true) }), _jsx(Button, { quiet: true, label: "Keep going", onPress: () => setFinishing(null) })] })] })) : null, said ? _jsx(Text, { accessibilityLiveRegion: "polite", children: said }) : null, session.state === "done" ? (_jsx(Text, { style: styles.heading, children: "Done" })) : (_jsx(Button, { label: "Finish session", busy: mark.isPending, onPress: () => void finish(false) }))] }));
45
109
  }
46
- function NativeItem({ programs, sessionId, personId, item, names, logged, onLogged, }) {
47
- const taken = logged.find((l) => l.item === item.label)?.level ?? null;
48
- const [chosen, setChosen] = useState(taken);
110
+ function NativeItem({ item, names, log, state, now, clock, onClock, onTicked, }) {
49
111
  const levels = item.kind === "levels" ? item.levels : [];
50
- const level = levels.find((l) => l.level === chosen) ?? (levels.length === 1 ? levels[0] : undefined);
51
- const list = item.kind === "all" ? item.exercises : level ? levelExercises(level) : [];
52
- return (_jsxs(View, { style: styles.item, children: [_jsx(Text, { style: styles.heading, children: item.label }), (item.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), levels.length > 1 ? (_jsx(View, { style: styles.row, children: levels.map((l) => (_jsx(Button, { quiet: l.level !== level?.level, label: levelLabel(l), onPress: () => setChosen(l.level) }, l.level))) })) : null, list.map((p) => {
53
- const e = names.get(p.exercise);
54
- return (_jsxs(View, { style: styles.exercise, children: [_jsx(Text, { style: styles.name, children: e?.name ?? "Exercise" }), _jsx(Text, { style: styles.muted, children: describeSets(p.sets) }), p.note ? _jsx(Text, { children: p.note }) : null, e?.last.length ? (_jsxs(Text, { style: styles.muted, children: ["Last time:", " ", e.last
55
- .map((s) => [
56
- s.reps,
57
- s.seconds !== null ? `${s.seconds}s` : null,
58
- s.load !== null ? `${s.load}kg` : null,
59
- ]
60
- .filter((x) => x !== null)
61
- .join(" "))
62
- .join(", ")] })) : null, p.sets.map((set, i) => (_jsx(NativeSet
63
- // biome-ignore lint/suspicious/noArrayIndexKey: sets are positions.
64
- , { programs: programs, sessionId: sessionId, personId: personId, itemLabel: item.label, level: item.kind === "levels" ? level?.level : undefined, exerciseId: p.exercise, setNumber: i + 1, target: set, done: loggedFor(logged, item.label, p.exercise, i + 1), onLogged: onLogged }, i)))] }, p.exercise));
65
- })] }));
112
+ const chosen = levelOf(state, item.label);
113
+ const level = levels.find((l) => l.level === chosen);
114
+ // Everyone's exercises (beside the levels, if any), then the level's.
115
+ const list = item.kind === "all"
116
+ ? item.exercises
117
+ : [...(item.exercises ?? []), ...(level ? levelExercises(level) : [])];
118
+ return (_jsxs(View, { style: styles.item, children: [_jsx(Text, { style: styles.heading, children: item.label }), (item.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), levels.length > 1 ? (_jsx(View, { style: styles.row, children: levels.map((l) => (_jsx(Button, { quiet: l.level !== level?.level, label: levelLabel(l), onPress: () => log.dispatch({ type: "level", item: item.label, level: l.level }) }, l.level))) })) : null, item.kind === "levels" && !level ? (_jsx(Text, { style: styles.muted, children: "Choose the level you take to log it." })) : null, list.map((p) => (_jsx(NativeExercise, { itemLabel: item.label, exerciseId: p.exercise, targets: p.sets, note: p.note, exercise: names.get(p.exercise), log: log, state: state, now: now, clock: clock, onClock: onClock, onTicked: onTicked }, p.exercise)))] }));
66
119
  }
67
- function NativeSet({ programs, sessionId, personId, itemLabel, level, exerciseId, setNumber, target, done, onLogged, }) {
68
- const add = programs.useLogSet();
69
- const update = programs.useUpdateSet();
70
- const timed = target.kind !== "reps";
71
- const [count, setCount] = useState(String((timed ? done?.actual.seconds : done?.actual.reps) ?? (timed ? target.seconds : target.reps)));
72
- const [load, setLoad] = useState(String(done?.actual.load ?? target.load ?? ""));
73
- const [effort, setEffort] = useState(String(done?.rpe ?? ""));
74
- const [error, setError] = useState(null);
75
- const actual = {
76
- ...(timed ? { seconds: numberFrom(count) } : { reps: numberFrom(count) }),
77
- ...(numberFrom(load) !== undefined ? { load: numberFrom(load) } : {}),
78
- };
79
- const rpe = numberFrom(effort);
80
- return (_jsxs(View, { style: styles.set, children: [_jsxs(Text, { children: ["Set ", setNumber, ": ", describeSet(target), " ", done ? "✓" : ""] }), _jsxs(View, { style: styles.row, children: [_jsx(Field, { label: timed ? "Seconds" : "Reps", keyboardType: "numeric", value: count, onChangeText: setCount }), _jsx(Field, { label: "kg", keyboardType: "decimal-pad", value: load, onChangeText: setLoad }), _jsx(Field, { label: "RPE", keyboardType: "decimal-pad", value: effort, onChangeText: setEffort, error: error })] }), _jsx(Button, { label: done ? "Update" : "Log set", quiet: Boolean(done), busy: add.isPending || update.isPending, onPress: async () => {
81
- setError(null);
82
- try {
83
- if (done)
84
- await update.mutateAsync({
85
- logId: done.id,
86
- actual,
87
- ...(rpe !== undefined ? { rpe } : {}),
88
- });
89
- else
90
- await add.mutateAsync({
91
- sessionId,
92
- item: itemLabel,
93
- exerciseId,
94
- ...(level !== undefined ? { level } : {}),
95
- setNumber,
96
- actual,
97
- ...(rpe !== undefined ? { rpe } : {}),
98
- ...(personId ? { personId } : {}),
99
- });
100
- onLogged(target);
101
- }
102
- catch (e) {
103
- setError(e.message ?? "Not logged");
104
- }
105
- } })] }));
120
+ function NativeExercise({ itemLabel, exerciseId, targets, note, exercise, log, state, now, clock, onClock, onTicked, }) {
121
+ const folded = exerciseDone(state, itemLabel, exerciseId);
122
+ const [open, setOpen] = useState(false);
123
+ const name = exercise?.name ?? "Exercise";
124
+ const withLoad = weighed(state.exercises[exerciseKey(itemLabel, exerciseId)], exercise?.measure ?? null);
125
+ if (folded && !open) {
126
+ return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: `${name}, all sets done. Show the sets`, onPress: () => setOpen(true), style: styles.folded, children: [_jsxs(Text, { style: styles.name, children: ["\u2713 ", name] }), _jsxs(Text, { style: styles.muted, children: [targets.length, " sets done"] })] }));
127
+ }
128
+ return (_jsxs(View, { style: styles.exercise, children: [_jsx(Pressable, { accessibilityRole: "button", disabled: !folded, onPress: () => setOpen(false), children: _jsx(Text, { style: styles.name, children: name }) }), _jsx(Text, { style: styles.muted, children: describeSets(targets) }), note ? _jsx(Text, { children: note }) : null, exercise?.last.length ? (_jsxs(Text, { style: styles.muted, children: ["Last time:", " ", exercise.last
129
+ .map((s) => [
130
+ s.reps,
131
+ s.seconds !== null ? `${s.seconds}s` : null,
132
+ s.load !== null ? `${s.load}kg` : null,
133
+ ]
134
+ .filter((x) => x !== null)
135
+ .join(" "))
136
+ .join(", ")] })) : null, targets.map((target, i) => (_jsx(NativeSet
137
+ // biome-ignore lint/suspicious/noArrayIndexKey: sets are positions.
138
+ , { itemLabel: itemLabel, exerciseId: exerciseId, setNumber: i + 1, target: target, withLoad: withLoad, log: log, state: state, now: now, clock: clock, onClock: onClock, onTicked: onTicked }, i)))] }));
139
+ }
140
+ function NativeSet({ itemLabel, exerciseId, setNumber, target, withLoad, log, state, now, clock, onClock, onTicked, }) {
141
+ const at = { item: itemLabel, exercise: exerciseId, setNumber };
142
+ const row = setRow(state, itemLabel, exerciseId, setNumber);
143
+ const [effortOpen, setEffortOpen] = useState(false);
144
+ const count = timed(target) ? "seconds" : "reps";
145
+ const key = setKey(itemLabel, exerciseId, setNumber);
146
+ const running = clock?.key === key;
147
+ const field = (name, label, keyboard) => (_jsx(TextInput, { accessibilityLabel: `Set ${setNumber} ${label}`, keyboardType: keyboard,
148
+ // A suggestion is greyed (the placeholder); what the person typed or ticked is the value.
149
+ placeholder: row.suggested ? (row.values[name] ?? label) : label, placeholderTextColor: theme.color.muted, value: row.suggested ? "" : (row.values[name] ?? ""), onChangeText: (text) => log.dispatch({ type: "edit", ...at, field: name, text }), selectTextOnFocus: true, style: [styles.input, row.done ? styles.inputDone : null] }));
150
+ return (_jsxs(View, { style: styles.set, children: [_jsxs(View, { style: styles.setRow, children: [_jsx(Text, { style: styles.setNumber, children: setNumber }), field(count, count === "reps" ? "reps" : "s", "number-pad"), withLoad ? field("load", "kg", "decimal-pad") : null, _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: row.rpe !== null ? `Set ${setNumber} effort ${row.rpe}` : `Set ${setNumber} effort`, onPress: () => setEffortOpen((o) => !o), style: styles.effort, children: _jsx(Text, { style: row.rpe !== null ? styles.effortSet : styles.muted, children: row.rpe !== null ? `@${row.rpe}` : "RPE" }) }), timed(target) && !row.done ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: running ? `Stop set ${setNumber}` : `Start set ${setNumber}`, onPress: () => {
151
+ if (!running) {
152
+ onClock({ key, from: Date.now() });
153
+ return;
154
+ }
155
+ onClock(null);
156
+ const seconds = String(secondsBetween(clock?.from ?? Date.now(), Date.now()));
157
+ log.dispatch({ type: "tick", ...at, values: { seconds } });
158
+ onTicked(target);
159
+ }, style: [styles.clock, running ? styles.clockRunning : null], children: _jsx(Text, { style: running ? styles.tickMarkDone : styles.heading, children: running ? `${secondsBetween(clock?.from ?? now, now)}s ■` : "▶" }) })) : null, _jsx(Pressable, { accessibilityRole: "checkbox", accessibilityLabel: `Set ${setNumber} done`, accessibilityState: { checked: row.done }, hitSlop: 8, onPress: () => {
160
+ if (!row.done)
161
+ onTicked(target);
162
+ log.dispatch({ type: "toggle", ...at });
163
+ }, style: [styles.tick, row.done ? styles.tickDone : null], children: _jsx(Text, { style: row.done ? styles.tickMarkDone : styles.tickMark, children: "\u2713" }) })] }), _jsx(Text, { style: styles.muted, children: describeSet(target) }), effortOpen ? (_jsx(View, { style: styles.row, children: EFFORTS.map((e) => (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: `Effort ${e}`, accessibilityState: { selected: row.rpe === e }, onPress: () => {
164
+ log.dispatch({ type: "rpe", ...at, rpe: row.rpe === e ? null : e });
165
+ setEffortOpen(false);
166
+ }, style: [styles.chip, row.rpe === e ? styles.chipOn : null], children: _jsx(Text, { style: row.rpe === e ? styles.tickMarkDone : styles.heading, children: e }) }, e))) })) : null, row.error ? _jsx(Text, { style: styles.error, children: row.error }) : null] }));
106
167
  }
107
168
  const styles = StyleSheet.create({
108
169
  muted: { color: theme.color.muted, fontSize: theme.font.small },
@@ -116,8 +177,73 @@ const styles = StyleSheet.create({
116
177
  borderRadius: theme.radius,
117
178
  },
118
179
  exercise: { gap: theme.space.xs },
119
- set: { gap: theme.space.xs, paddingVertical: theme.space.xs },
180
+ folded: {
181
+ flexDirection: "row",
182
+ justifyContent: "space-between",
183
+ paddingVertical: theme.space.sm,
184
+ },
185
+ set: { gap: 2, paddingVertical: theme.space.xs },
186
+ setRow: { flexDirection: "row", alignItems: "center", gap: theme.space.sm },
187
+ setNumber: { width: 20, color: theme.color.muted, fontWeight: "600" },
188
+ input: {
189
+ flex: 1,
190
+ minHeight: 44,
191
+ borderWidth: 1,
192
+ borderColor: theme.color.border,
193
+ borderRadius: theme.radius,
194
+ paddingHorizontal: theme.space.sm,
195
+ fontSize: theme.font.body,
196
+ color: theme.color.text,
197
+ backgroundColor: theme.color.background,
198
+ textAlign: "center",
199
+ },
200
+ inputDone: { borderColor: theme.color.primary },
201
+ effort: { minWidth: 44, minHeight: 44, alignItems: "center", justifyContent: "center" },
202
+ effortSet: { fontWeight: "600", color: theme.color.text },
203
+ clock: {
204
+ minWidth: 56,
205
+ minHeight: 44,
206
+ borderRadius: theme.radius,
207
+ alignItems: "center",
208
+ justifyContent: "center",
209
+ backgroundColor: theme.color.background,
210
+ },
211
+ clockRunning: { backgroundColor: theme.color.primary },
212
+ tick: {
213
+ width: 44,
214
+ height: 44,
215
+ borderRadius: theme.radius,
216
+ borderWidth: 2,
217
+ borderColor: theme.color.border,
218
+ alignItems: "center",
219
+ justifyContent: "center",
220
+ backgroundColor: theme.color.background,
221
+ },
222
+ tickDone: { backgroundColor: theme.color.primary, borderColor: theme.color.primary },
223
+ tickMark: { fontSize: 20, color: theme.color.muted },
224
+ tickMarkDone: { fontSize: 18, fontWeight: "700", color: theme.color.onPrimary },
225
+ chip: {
226
+ minWidth: 44,
227
+ minHeight: 40,
228
+ borderRadius: theme.radius,
229
+ alignItems: "center",
230
+ justifyContent: "center",
231
+ backgroundColor: theme.color.background,
232
+ },
233
+ chipOn: { backgroundColor: theme.color.primary },
120
234
  row: { flexDirection: "row", flexWrap: "wrap", gap: theme.space.sm },
235
+ progress: { gap: theme.space.xs },
236
+ track: { height: 6, borderRadius: 3, backgroundColor: theme.color.surface, overflow: "hidden" },
237
+ fill: { height: 6, backgroundColor: theme.color.primary },
238
+ warning: {
239
+ gap: theme.space.sm,
240
+ padding: theme.space.sm,
241
+ borderRadius: theme.radius,
242
+ borderWidth: 1,
243
+ borderColor: theme.color.danger,
244
+ },
245
+ warningText: { color: theme.color.text },
246
+ error: { color: theme.color.danger, fontSize: theme.font.small },
121
247
  timer: {
122
248
  flexDirection: "row",
123
249
  alignItems: "center",
@@ -1,6 +1,6 @@
1
1
  import type { PlannedSession, ProgramsHooks } from "@composable-os/pack-programs/client";
2
2
  export declare function TodayScreen({ programs, date, onOpen, }: {
3
- programs: Pick<ProgramsHooks, "useToday">;
3
+ programs: Pick<ProgramsHooks, "useToday" | "useUnsavedSets">;
4
4
  /** The member's local date (YYYY-MM-DD). */
5
5
  date?: string;
6
6
  onOpen: (session: PlannedSession) => void;
@@ -1,11 +1,30 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Text } from "react-native";
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ import { AppState, StyleSheet, View } from "react-native";
4
+ import { Button } from "../native-base/button.js";
3
5
  import { List } from "../native-base/list.js";
4
6
  import { Row } from "../native-base/row.js";
5
7
  import { Screen } from "../native-base/screen.js";
8
+ import { Text } from "../native-base/text.js";
9
+ import { theme } from "../native-base/theme.js";
6
10
  export function TodayScreen({ programs, date, onOpen, }) {
7
11
  const today = programs.useToday(date ? { date } : {});
8
- return (_jsxs(Screen, { title: "Today", children: [today.isPending ? _jsx(Text, { children: "Loading\u2026" }) : null, today.data ? (_jsx(List, { empty: "Nothing planned today.", children: today.data.sessions.map((s) => (_jsx(Row, { title: s.name ?? "Session", detail: [s.programTitle, s.state === "done" ? "Done" : null]
12
+ const unsaved = programs.useUnsavedSets();
13
+ const { flush } = unsaved;
14
+ useEffect(() => {
15
+ const sub = AppState.addEventListener("change", () => void flush());
16
+ return () => sub.remove();
17
+ }, [flush]);
18
+ return (_jsxs(Screen, { title: "Today", children: [unsaved.count ? (_jsxs(View, { style: styles.warning, accessibilityLiveRegion: "polite", children: [_jsxs(Text, { children: [unsaved.count === 1 ? "1 set is" : `${unsaved.count} sets are`, " not saved yet.", " ", unsaved.failure ?? "Sending…"] }), _jsx(Button, { quiet: true, label: "Try now", onPress: () => void flush() })] })) : null, today.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" })) : null, today.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load today's sessions. Check the connection and try again." })) : null, today.data ? (_jsx(List, { empty: "Nothing planned today.", children: today.data.sessions.map((s) => (_jsx(Row, { title: s.name ?? "Session", detail: [s.programTitle, s.state === "done" ? "Done" : null]
9
19
  .filter(Boolean)
10
20
  .join(" · "), onPress: () => onOpen(s) }, s.id))) })) : null] }));
11
21
  }
22
+ const styles = StyleSheet.create({
23
+ warning: {
24
+ gap: theme.space.sm,
25
+ padding: theme.space.sm,
26
+ borderRadius: theme.radius,
27
+ borderWidth: 1,
28
+ borderColor: theme.color.danger,
29
+ },
30
+ });
@@ -1,9 +1,13 @@
1
1
  import { type ProgramsHooks } from "@composable-os/pack-programs/client";
2
- export declare function SessionView({ programs, sessionId, personId, onRestDone, }: {
3
- programs: Pick<ProgramsHooks, "useLogSet" | "useMarkSession" | "useSession" | "useUpdateSet">;
2
+ type Programs = Pick<ProgramsHooks, "useMarkSession" | "useSessionLog">;
3
+ export declare function SessionView({ programs, sessionId, personId, onRestDone, defaultRest, }: {
4
+ programs: Programs;
4
5
  sessionId: string;
5
- /** A coach logging for a client names them on a class session. */
6
+ /** A coach logging for a client names them. */
6
7
  personId?: string;
7
8
  /** Called when a rest ends (a sound, a buzz): the app's. */
8
9
  onRestDone?: () => void;
10
+ /** Seconds of rest after a set whose plan names none. */
11
+ defaultRest?: number;
9
12
  }): import("react").JSX.Element;
13
+ export {};