@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,4 +1,4 @@
1
- import type { Layout, SetTarget } from "./layout.ts";
1
+ import { type Layout, type SetTarget } from "./layout.ts";
2
2
  export interface BankExercise {
3
3
  id: string;
4
4
  name: string;
@@ -12,8 +12,11 @@ export interface UnreadLine {
12
12
  text: string;
13
13
  reason: string;
14
14
  }
15
+ export type ProgramKind = "class" | "client" | "course";
15
16
  export interface ImportResult {
16
17
  title: string | null;
18
+ /** What a `Kind:` line said, if there was one. */
19
+ kind: ProgramKind | null;
17
20
  guidance: string | null;
18
21
  layout: Layout;
19
22
  unread: UnreadLine[];
package/dist/authoring.js CHANGED
@@ -1,3 +1,29 @@
1
+ // Building a working copy without the builder (stage 41, step 6): reading a coach's pasted
2
+ // shorthand, and laying out a draft from a brief. Pure functions over the bank: every exercise a
3
+ // layout names is one of the bank's, found by name, and a line that names one the bank does not
4
+ // have, or cannot be read, is listed for the coach to fix, never guessed. The host still checks
5
+ // the result against the layout schema and that every ref is a live exercise.
6
+ //
7
+ // The shorthand is the shape coaches already type (Ghetto Movement's prototype format):
8
+ //
9
+ // Title: Strength, term 1
10
+ // Kind: class (class, client or course; optional)
11
+ // Guidance: Reps and tempo are followed literally… (for coaches)
12
+ // Week: 1 (optional; else one week)
13
+ // Session: Monday (a weekday names its day)
14
+ // Focus: Slow, controlled reps
15
+ // Warm-up: Wrists and shoulders
16
+ // - Scap push ups x 10
17
+ // Block A: Approx 4-7 rounds (rounds: the first number)
18
+ // A1: L sit to planche (a name alone: levels follow)
19
+ // 1: L sit x 8-12 sec + Planche lean x 3 (32X1) ("+" together)
20
+ // 3: Pike push throughs x 3 | L-sit walk ups x 3 ("|" alternatives)
21
+ // * a note for coaches on the line above
22
+ // TV: a note shown to members
23
+ // B1: Ring rows x 5 (5050) (an exercise: for everyone)
24
+ // C1: Hollow hold x 30 sec (for everyone, and levels beside it)
25
+ // 2: Tuck planche x 3
26
+ import { MAX_SESSIONS_PER_WEEK, MAX_WEEKS, } from "./layout.js";
1
27
  const norm = (name) => name
2
28
  .toLowerCase()
3
29
  .replace(/[’'"“”]/g, "")
@@ -88,6 +114,7 @@ function splitExercise(raw) {
88
114
  }
89
115
  const RE = {
90
116
  title: /^title\s*:\s*(.*)$/i,
117
+ kind: /^kind\s*:\s*(.*)$/i,
91
118
  guidance: /^guidance\s*:\s*(.*)$/i,
92
119
  week: /^week\s*:?\s*(\d+)\s*(?::\s*(.*))?$/i,
93
120
  session: /^session\s*:\s*(.*)$/i,
@@ -106,6 +133,7 @@ export function readProgramText(text, bank) {
106
133
  const find = bankIndex(bank);
107
134
  const unread = [];
108
135
  let title = null;
136
+ let kind = null;
109
137
  let guidance = null;
110
138
  const weeks = [];
111
139
  let week = null;
@@ -197,6 +225,16 @@ export function readProgramText(text, bank) {
197
225
  continueTo = null;
198
226
  return;
199
227
  }
228
+ m = RE.kind.exec(line);
229
+ if (m) {
230
+ const said = norm(m[1] ?? "");
231
+ continueTo = null;
232
+ if (said === "class" || said === "client" || said === "course") {
233
+ kind = said;
234
+ return;
235
+ }
236
+ return skip(n, rawLine, "a kind is class, client or course");
237
+ }
200
238
  m = RE.guidance.exec(line);
201
239
  if (m) {
202
240
  guidance = (m[1] ?? "").trim();
@@ -216,7 +254,7 @@ export function readProgramText(text, bank) {
216
254
  if (m) {
217
255
  const name = (m[1] ?? "").trim().slice(0, 60) || "Session";
218
256
  const w = needWeek();
219
- if (w.sessions.length >= 14)
257
+ if (w.sessions.length >= MAX_SESSIONS_PER_WEEK)
220
258
  return skip(n, rawLine, "more than fourteen sessions in a week");
221
259
  const weekday = WEEKDAYS.findIndex((d) => norm(name).split(" ").includes(d));
222
260
  const used = new Set(w.sessions.map((s) => s.day));
@@ -323,6 +361,19 @@ export function readProgramText(text, bank) {
323
361
  return skip(n, rawLine, found);
324
362
  }
325
363
  m = RE.level.exec(line);
364
+ if (m && item?.kind === "all" && block) {
365
+ // Levels under an item that names an exercise: that exercise is everyone's, beside them.
366
+ const at = block.items.indexOf(item);
367
+ const both = {
368
+ kind: "levels",
369
+ label: item.label,
370
+ exercises: item.exercises,
371
+ levels: [],
372
+ ...(item.notes ? { notes: item.notes } : {}),
373
+ };
374
+ block.items[at] = both;
375
+ item = both;
376
+ }
326
377
  if (m && item?.kind === "levels") {
327
378
  const number = Number(m[1]);
328
379
  if (number < 1 || number > 5)
@@ -352,9 +403,18 @@ export function readProgramText(text, bank) {
352
403
  for (const [index, rawLine] of lines.entries())
353
404
  readLine(rawLine, index);
354
405
  // An item whose levels all failed, or a block left empty, cannot be in the layout: say so.
406
+ // One with exercises for everyone keeps them, as an item for everyone.
355
407
  for (const w of weeks) {
356
408
  for (const s of w.sessions) {
357
409
  for (const b of s.blocks) {
410
+ b.items = b.items.map((i) => i.kind === "levels" && !i.levels.length && i.exercises?.length
411
+ ? {
412
+ kind: "all",
413
+ label: i.label,
414
+ exercises: i.exercises,
415
+ ...(i.notes ? { notes: i.notes } : {}),
416
+ }
417
+ : i);
358
418
  const kept = b.items.filter((i) => i.kind === "all" || i.levels.length > 0);
359
419
  for (const dropped of b.items.filter((i) => !kept.includes(i))) {
360
420
  unread.push({
@@ -381,6 +441,7 @@ export function readProgramText(text, bank) {
381
441
  unread.sort((a, b) => a.line - b.line);
382
442
  return {
383
443
  title,
444
+ kind,
384
445
  guidance: guidance ? guidance.slice(0, 5000) : null,
385
446
  layout: { weeks },
386
447
  unread,
@@ -395,7 +456,7 @@ export function readBrief(brief) {
395
456
  .split(" ")
396
457
  .filter((word) => word.length > 3 && !/^\d+$/.test(word) && !STOP.has(word));
397
458
  return {
398
- weeks: clamp(weeks ? Number(weeks[1]) : 4, 1, 52),
459
+ weeks: clamp(weeks ? Number(weeks[1]) : 4, 1, MAX_WEEKS),
399
460
  sessionsPerWeek: clamp(perWeek ? Number(perWeek[1]) : 3, 1, 7),
400
461
  focus: [...new Set(focus)],
401
462
  };
@@ -462,17 +523,16 @@ export function draftLayout(plan, chosen) {
462
523
  [1, 2, 3, 4, 5, 6],
463
524
  [1, 2, 3, 4, 5, 6, 7],
464
525
  ][plan.sessionsPerWeek - 1];
465
- const pool = chosen.length ? chosen : [];
466
526
  let next = 0;
467
527
  const take = () => {
468
- const e = pool[next % pool.length];
528
+ const e = chosen[next % chosen.length];
469
529
  next += 1;
470
530
  return { exercise: e.id, sets: defaultSets(e.measure) };
471
531
  };
472
532
  const sessionsOfWeek = days.map((day, s) => ({
473
533
  name: `Session ${String.fromCharCode(65 + s)}`,
474
534
  day,
475
- blocks: pool.length
535
+ blocks: chosen.length
476
536
  ? ["A", "B"].map((label) => ({
477
537
  label,
478
538
  rounds: 3,
@@ -1,14 +1,23 @@
1
1
  import { type ProgramsHooks, type RecordOut } from "@composable-os/pack-programs/client";
2
2
  import { type ReactNode } from "react";
3
+ /** The hooks the builder calls. */
4
+ type BuilderHooks = Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
3
5
  interface Bank {
4
6
  byId: Map<string, RecordOut>;
5
7
  list: RecordOut[];
6
8
  /** The hooks, for a search of the whole bank on the host. */
7
- programs: Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
9
+ programs: BuilderHooks;
8
10
  }
11
+ /**
12
+ * The builder as the product's admin shows it (stage 47): the list of programs, and the one
13
+ * opened from it, with a way back. The admin passes it nothing but the hooks.
14
+ */
15
+ export declare function ProgramWorkspace({ programs, }: {
16
+ programs: Parameters<typeof ProgramBuilder>[0]["programs"];
17
+ }): import("react").JSX.Element;
9
18
  /** The whole builder for one program. */
10
19
  export declare function ProgramBuilder({ programs, programId, }: {
11
- programs: Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
20
+ programs: BuilderHooks;
12
21
  programId: string;
13
22
  }): import("react").JSX.Element;
14
23
  /** A search over the bank: type, then pick with a click, or Enter for the first match. */
@@ -20,7 +29,7 @@ export declare function ExercisePicker({ bank, label, onPick, compact, }: {
20
29
  }): import("react").JSX.Element;
21
30
  /** A list of programs with a button to open one, and to start one blank, drafted or imported. */
22
31
  export declare function ProgramList({ programs, onOpen, }: {
23
- programs: Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
32
+ programs: BuilderHooks;
24
33
  onOpen: (programId: string) => void;
25
34
  }): ReactNode;
26
35
  export {};
@@ -17,6 +17,16 @@ import { Label } from "../ui-label/label.js";
17
17
  const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
18
18
  const nameOf = (bank, id) => String(bank.byId.get(id)?.values.name ?? "Unknown exercise");
19
19
  const measureOf = (bank, id) => bank.byId.get(id)?.values.measure ?? null;
20
+ /**
21
+ * The builder as the product's admin shows it (stage 47): the list of programs, and the one
22
+ * opened from it, with a way back. The admin passes it nothing but the hooks.
23
+ */
24
+ export function ProgramWorkspace({ programs, }) {
25
+ const [open, setOpen] = useState(null);
26
+ if (!open)
27
+ return _jsx(ProgramList, { programs: programs, onOpen: setOpen });
28
+ return (_jsxs("div", { className: "grid gap-4", children: [_jsx(Button, { type: "button", variant: "outline", className: "w-fit", onClick: () => setOpen(null), children: "All programs" }), _jsx(ProgramBuilder, { programs: programs, programId: open }, open)] }));
29
+ }
20
30
  /** The whole builder for one program. */
21
31
  export function ProgramBuilder({ programs, programId, }) {
22
32
  const copy = programs.useWorkingCopy(programId);
@@ -138,7 +148,9 @@ function ItemEditor({ layout, at, item, bank, change, faults, count, onDragStart
138
148
  onDrop();
139
149
  }, className: "grid gap-2 rounded-md bg-muted/40 p-3", "data-testid": "item", "data-label": item.label, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("button", { type: "button", onKeyDown: onKey, className: "cursor-grab select-none rounded px-1 text-muted-foreground focus-visible:ring-2", "aria-label": `Move item ${item.label}: drag it, or Alt and the arrow keys`, children: "\u283F" }), _jsx(Input, { "aria-label": "Item label", className: "h-8 w-20", value: item.label, onChange: (e) => change(layoutEdits.setItemLabel(layout, at, e.target.value)) }), _jsxs("select", { "aria-label": "For", className: "h-8 rounded-md border px-2 text-sm", value: item.kind, onChange: (e) => change(layoutEdits.setItemKind(layout, at, e.target.value)), children: [_jsx("option", { value: "all", children: "For everyone" }), _jsx("option", { value: "levels", children: "With levels" })] }), _jsx(Button, { size: "xs", variant: "ghost", disabled: index === 0, onClick: () => moveTo(index - 1), children: "Up" }), _jsx(Button, { size: "xs", variant: "ghost", disabled: index === count - 1, onClick: () => moveTo(index + 1), children: "Down" }), _jsx(Button, { size: "xs", variant: "ghost", onClick: () => change(layoutEdits.removeItem(layout, at)), children: "Remove" })] }), _jsx(Faults, { faults: faults, path: pathOf(at) }), item.kind === "all" ? (_jsxs("div", { className: "grid gap-2", children: [item.exercises.map((p, e) => (_jsx(PrescriptionEditor
140
150
  // biome-ignore lint/suspicious/noArrayIndexKey: exercises are positions in their item.
141
- , { layout: layout, at: { ...at, exercise: e }, prescription: p, bank: bank, change: change, removable: item.exercises.length > 1 }, e))), _jsx(ExercisePicker, { bank: bank, label: "Add an exercise done together", compact: true, onPick: (id) => change(layoutEdits.addExercise(layout, at, id, measureOf(bank, id))) })] })) : (_jsx(LevelsEditor, { layout: layout, at: at, levels: item.levels, bank: bank, change: change })), _jsx(NotesEditor, { notes: item.notes ?? [], onAdd: (text, members) => change(layoutEdits.addNote(layout, at, text, members)), onChange: (i, note) => change(layoutEdits.setNote(layout, at, i, note)) })] }));
151
+ , { layout: layout, at: { ...at, exercise: e }, prescription: p, bank: bank, change: change, removable: item.exercises.length > 1 }, e))), _jsx(ExercisePicker, { bank: bank, label: "Add an exercise done together", compact: true, onPick: (id) => change(layoutEdits.addExercise(layout, at, id, measureOf(bank, id))) })] })) : (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-2", "data-testid": "everyone", children: [(item.exercises ?? []).map((p, e) => (_jsx(PrescriptionEditor
152
+ // biome-ignore lint/suspicious/noArrayIndexKey: exercises are positions in their item.
153
+ , { layout: layout, at: { ...at, everyone: true, exercise: e }, prescription: p, bank: bank, change: change, removable: true }, e))), _jsx(ExercisePicker, { bank: bank, label: "Add an exercise for everyone, beside the levels", compact: true, onPick: (id) => change(layoutEdits.addExercise(layout, { ...at, everyone: true }, id, measureOf(bank, id))) })] }), _jsx(LevelsEditor, { layout: layout, at: at, levels: item.levels, bank: bank, change: change })] })), _jsx(NotesEditor, { notes: item.notes ?? [], onAdd: (text, members) => change(layoutEdits.addNote(layout, at, text, members)), onChange: (i, note) => change(layoutEdits.setNote(layout, at, i, note)) })] }));
142
154
  }
143
155
  function LevelsEditor({ layout, at, levels, bank, change, }) {
144
156
  const used = new Set(levels.map((l) => l.level));
@@ -234,7 +246,7 @@ function Versions({ programs, programId, onRestored, }) {
234
246
  setSaid(`Version ${v.version} restored into the working copy. Publish to give it to people.`);
235
247
  }, children: "Restore" })] }, v.version))), versions.data && !versions.data.items.length ? _jsx("li", { children: "Not published yet." }) : null] })] })] }));
236
248
  }
237
- function Assign({ programs, programId, }) {
249
+ function Assign({ programs, programId }) {
238
250
  const [search, setSearch] = useState("");
239
251
  const [person, setPerson] = useState(null);
240
252
  const [classType, setClassType] = useState("");
@@ -290,6 +302,7 @@ export function ProgramList({ programs, onOpen, }) {
290
302
  }, children: "Start a program" })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Input, { "aria-label": "Brief for a draft", placeholder: "A brief: 12 weeks of handstands, 3 sessions a week", value: brief, onChange: (e) => setBrief(e.target.value), className: "max-w-md" }), _jsx(Button, { variant: "outline", disabled: brief.trim().length < 3 || draft.isPending, onClick: async () => onOpen((await draft.mutateAsync({ brief: brief.trim() })).programId), children: "Draft from the bank" })] }), _jsxs("div", { className: "grid gap-2", children: [_jsx(Label, { htmlFor: "import-text", children: "Paste a program" }), _jsx("textarea", { id: "import-text", className: "min-h-32 rounded-md border p-2 font-mono text-xs", value: text, onChange: (e) => setText(e.target.value) }), _jsx("div", { children: _jsx(Button, { variant: "outline", disabled: !text.trim() || importText.isPending, onClick: async () => {
291
303
  const out = await importText.mutateAsync({ text });
292
304
  setUnread(out.unread);
293
- onOpen(out.programId);
305
+ if (out.programId)
306
+ onOpen(out.programId);
294
307
  }, children: "Import" }) }), unread.length ? (_jsx("ul", { className: "grid gap-1 text-sm", "aria-label": "Lines not read", children: unread.map((u) => (_jsxs("li", { children: [u.line ? `Line ${u.line}: ` : "", _jsx("code", { children: u.text }), " (", u.reason, ")"] }, `${u.line}-${u.text}`))) })) : null] })] }));
295
308
  }
@@ -1,6 +1,6 @@
1
1
  import type { ProgramsHooks } from "@composable-os/pack-programs/client";
2
2
  export declare function ClassToday({ programs, classTypeId, date, }: {
3
- programs: Pick<ProgramsHooks, "useClassToday" | "useClassTypes" | "useLogSet" | "useMarkSession" | "useSession" | "useUpdateSet">;
3
+ programs: Pick<ProgramsHooks, "useClassToday" | "useClassTypes" | "useMarkSession" | "useSessionLog">;
4
4
  classTypeId?: string;
5
5
  date?: string;
6
6
  }): import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import type { ProgramsHooks } from "@composable-os/pack-programs/client";
2
2
  export declare function CoachClient({ programs, personId, }: {
3
- programs: Pick<ProgramsHooks, "useClientSessions" | "useHistory" | "useLogSet" | "useMarkSession" | "useProgress" | "useSession" | "useUpdateSet">;
3
+ programs: Pick<ProgramsHooks, "useClientSessions" | "useHistory" | "useMarkSession" | "useProgress" | "useSessionLog">;
4
4
  personId: string;
5
5
  }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { type PastSessionsHooks, type ProgramsHooks } from "@composable-os/pack-programs/client";
2
+ type HistoryHooks = PastSessionsHooks & Pick<ProgramsHooks, "useSession" | "useUpdateSet">;
3
+ export declare function SessionHistory({ programs, personId, until, }: {
4
+ /** A member's hooks (`usePastSessions`), or a coach's (`useClientPastSessions`). */
5
+ programs: HistoryHooks;
6
+ /** A coach's client. A member is always themselves. */
7
+ personId?: string;
8
+ /** The last date listed: the person's local today. Default today, UTC. */
9
+ until?: string;
10
+ }): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,84 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A person's past sessions (stage 41): newest first, each with its date, its name and how many of
3
+ // its sets were logged; one opened shows it set by set, read-only, with the target beside what was
4
+ // done, and a logged set can be corrected. For a member (their own) or a coach (`personId`, a
5
+ // client's). Built on the web base layer.
6
+ //
7
+ // It holds no rules: which sessions are the person's, the sets on each and what a correction may
8
+ // change are the host's (the seam for a member, `x.programs.logUpdate` for both: the numbers done,
9
+ // effort and the note, never the target, the exercise or who recorded it).
10
+ import { correctionOf, describeDone, describeSet, pastSessionsHook, sessionSets, } from "@composable-os/pack-programs/client";
11
+ import { useState } from "react";
12
+ import { Button } from "../ui-button/button.js";
13
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
14
+ import { Input } from "../ui-input/input.js";
15
+ export function SessionHistory({ programs, personId, until, }) {
16
+ // The cursors of the pages before this one: "Newer" goes back one.
17
+ const [cursors, setCursors] = useState([]);
18
+ const cursor = cursors.at(-1);
19
+ const usePastPage = pastSessionsHook(programs, personId);
20
+ const page = usePastPage({
21
+ ...(until ? { until } : {}),
22
+ ...(cursor ? { cursor } : {}),
23
+ });
24
+ const [open, setOpen] = useState(null);
25
+ if (page.isPending)
26
+ return _jsx("p", { "aria-busy": "true", children: "Loading past sessions\u2026" });
27
+ if (page.error || !page.data)
28
+ return _jsx("p", { role: "alert", children: "We could not load past sessions." });
29
+ const { sessions, nextCursor } = page.data;
30
+ return (_jsxs("div", { className: "grid gap-3", "data-testid": "session-history", children: [_jsx("ol", { className: "grid gap-2", "aria-label": "Past sessions", children: sessions.map((s) => (_jsxs("li", { className: "grid gap-2", "data-testid": "past-session", children: [_jsxs(Button, { variant: open === s.id ? "default" : "outline", className: "h-auto justify-between gap-3 py-2 text-left", "aria-expanded": open === s.id, onClick: () => setOpen(open === s.id ? null : s.id), children: [_jsxs("span", { className: "grid", children: [_jsx("span", { className: "font-medium", children: s.name ?? "Session" }), _jsx("span", { className: "text-xs opacity-80", children: [s.date, s.programTitle, s.state === "skipped" ? "skipped" : null]
31
+ .filter(Boolean)
32
+ .join(" · ") })] }), _jsxs("span", { className: "text-sm tabular-nums", "data-testid": "sets-done", children: [s.setsDone, " of ", s.setsPlanned, " sets"] })] }), open === s.id ? (_jsx(PastSession, { programs: programs, sessionId: s.id, personId: personId })) : null] }, s.id))) }), !sessions.length && !cursor ? _jsx("p", { children: "No past sessions yet." }) : null, _jsxs("div", { className: "flex gap-2", children: [cursor ? (_jsx(Button, { variant: "ghost", size: "sm", onClick: () => setCursors((c) => c.slice(0, -1)), children: "Newer" })) : null, nextCursor ? (_jsx(Button, { variant: "outline", size: "sm", onClick: () => {
33
+ setOpen(null);
34
+ setCursors((c) => [...c, nextCursor]);
35
+ }, children: "Older" })) : null] })] }));
36
+ }
37
+ /** One past session, set by set: the target and what was done, and a correction per set. */
38
+ function PastSession({ programs, sessionId, personId, }) {
39
+ const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
40
+ if (detail.isPending)
41
+ return _jsx("p", { "aria-busy": "true", children: "Loading the session\u2026" });
42
+ if (detail.error || !detail.data)
43
+ return _jsx("p", { role: "alert", children: "We could not load this session." });
44
+ const { session, exercises, logged } = detail.data;
45
+ const names = new Map(exercises.map((e) => [e.id, e.name]));
46
+ const sets = sessionSets(session.plan, logged);
47
+ return (_jsxs(Card, { "data-testid": "past-session-detail", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: session.name }), _jsx(CardDescription, { children: [session.programTitle, session.date, session.focus].filter(Boolean).join(" · ") })] }), _jsx(CardContent, { children: _jsxs("ol", { className: "grid gap-1 text-sm", children: [sets.map((s) => (_jsxs("li", { className: "grid gap-1 border-b py-1 last:border-0", "data-testid": "past-set", "data-item": s.item, children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-2", children: [_jsx("strong", { children: s.item }), _jsx("span", { children: s.logged?.exerciseName ?? names.get(s.exercise) ?? "Exercise" }), s.level !== null ? (_jsxs("span", { className: "text-xs text-muted-foreground", children: ["level ", s.level] })) : null, _jsxs("span", { className: "text-muted-foreground", children: ["set ", s.setNumber, s.target ? `: ${describeSet(s.target)}` : ""] })] }), s.logged ? (_jsx(LoggedRow, { programs: programs, set: s.logged, timed: s.target ? s.target.kind !== "reps" : s.logged.actual.seconds !== null, onCorrected: () => detail.refetch?.() })) : (_jsx("span", { className: "text-muted-foreground", children: "Not logged" }))] }, `${s.item}-${s.exercise}-${s.setNumber}`))), !sets.length ? _jsx("li", { children: "This session has no sets." }) : null] }) })] }));
48
+ }
49
+ function LoggedRow({ programs, set, timed, onCorrected, }) {
50
+ const update = programs.useUpdateSet();
51
+ const [editing, setEditing] = useState(false);
52
+ const [count, setCount] = useState("");
53
+ const [load, setLoad] = useState("");
54
+ const [effort, setEffort] = useState("");
55
+ const [note, setNote] = useState("");
56
+ const [error, setError] = useState(null);
57
+ const start = () => {
58
+ setCount(String((timed ? set.actual.seconds : set.actual.reps) ?? ""));
59
+ setLoad(String(set.actual.load ?? ""));
60
+ setEffort(String(set.rpe ?? ""));
61
+ setNote(set.note ?? "");
62
+ setError(null);
63
+ setEditing(true);
64
+ };
65
+ if (!editing)
66
+ return (_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { "data-testid": "past-set-done", children: describeDone(set) }), set.recordedAs === "staff" && set.recordedByName ? (_jsxs("span", { className: "text-xs text-muted-foreground", children: ["by ", set.recordedByName] })) : null, set.note ? _jsx("span", { className: "text-xs italic", children: set.note }) : null, _jsx(Button, { size: "sm", variant: "ghost", onClick: start, children: "Correct" })] }));
67
+ return (_jsxs("form", { className: "flex flex-wrap items-end gap-2", "aria-label": `Correct set ${set.setNumber ?? ""}`, onSubmit: async (event) => {
68
+ event.preventDefault();
69
+ const correction = correctionOf(set, { count, load, rpe: effort, note }, timed);
70
+ if (!correction) {
71
+ setEditing(false);
72
+ return;
73
+ }
74
+ setError(null);
75
+ try {
76
+ await update.mutateAsync(correction);
77
+ setEditing(false);
78
+ onCorrected();
79
+ }
80
+ catch (e) {
81
+ setError(e.message ?? "Not corrected");
82
+ }
83
+ }, children: [_jsx(Input, { "aria-label": `Set ${set.setNumber ?? ""} ${timed ? "seconds" : "reps"} done`, placeholder: timed ? "Seconds" : "Reps", className: "h-8 w-20", inputMode: "numeric", value: count, onChange: (e) => setCount(e.target.value) }), _jsx(Input, { "aria-label": `Set ${set.setNumber ?? ""} load`, placeholder: "kg", className: "h-8 w-20", inputMode: "decimal", value: load, onChange: (e) => setLoad(e.target.value) }), _jsx(Input, { "aria-label": `Set ${set.setNumber ?? ""} effort`, placeholder: "RPE", className: "h-8 w-16", inputMode: "decimal", value: effort, onChange: (e) => setEffort(e.target.value) }), _jsx(Input, { "aria-label": `Set ${set.setNumber ?? ""} note`, placeholder: "Note", className: "h-8 w-48", value: note, onChange: (e) => setNote(e.target.value) }), _jsx(Button, { size: "sm", type: "submit", disabled: update.isPending, children: "Save" }), _jsx(Button, { size: "sm", variant: "ghost", type: "button", onClick: () => setEditing(false), children: "Cancel" }), error ? (_jsx("p", { role: "alert", className: "w-full text-xs text-destructive", children: error })) : null] }));
84
+ }
@@ -1,14 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
- import { Text, View } from "react-native";
3
+ import { View } from "react-native";
4
4
  import { Button } from "../native-base/button.js";
5
5
  import { List } from "../native-base/list.js";
6
6
  import { Row } from "../native-base/row.js";
7
7
  import { Screen } from "../native-base/screen.js";
8
+ import { Text } from "../native-base/text.js";
8
9
  export function ClassTodayScreen({ programs, date, onOpen, }) {
9
10
  const types = programs.useClassTypes();
10
11
  const [chosen, setChosen] = useState(null);
11
12
  const id = chosen ?? types.data?.items[0]?.id ?? "none";
12
13
  const classes = programs.useClassToday({ classTypeId: id, ...(date ? { date } : {}) });
13
- return (_jsxs(Screen, { title: "Class", children: [_jsx(View, { style: { flexDirection: "row", flexWrap: "wrap", gap: 8 }, children: (types.data?.items ?? []).map((t) => (_jsx(Button, { quiet: t.id !== id, label: String(t.values.name ?? "Class"), onPress: () => setChosen(t.id) }, t.id))) }), classes.isPending ? _jsx(Text, { children: "Loading\u2026" }) : null, classes.data ? (_jsx(List, { empty: "No class session today.", children: classes.data.sessions.map((s) => (_jsx(Row, { title: s.name ?? "Session", detail: s.classTypeName, onPress: () => onOpen(s) }, s.id))) })) : null] }));
14
+ return (_jsxs(Screen, { title: "Class", children: [_jsx(View, { style: { flexDirection: "row", flexWrap: "wrap", gap: 8 }, children: (types.data?.items ?? []).map((t) => (_jsx(Button, { quiet: t.id !== id, label: String(t.values.name ?? "Class"), onPress: () => setChosen(t.id) }, t.id))) }), classes.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" })) : null, types.error || classes.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load today's classes. Check the connection and try again." })) : null, classes.data ? (_jsx(List, { empty: "No class session today.", children: classes.data.sessions.map((s) => (_jsx(Row, { title: s.name ?? "Session", detail: s.classTypeName, onPress: () => onOpen(s) }, s.id))) })) : null] }));
14
15
  }
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Text } from "react-native";
3
2
  import { List } from "../native-base/list.js";
4
3
  import { Row } from "../native-base/row.js";
5
4
  import { Screen } from "../native-base/screen.js";
5
+ import { Text } from "../native-base/text.js";
6
6
  export function CoachClientScreen({ programs, personId, name, onOpen, }) {
7
7
  const sessions = programs.useClientSessions(personId);
8
- return (_jsxs(Screen, { title: name, children: [sessions.isPending ? _jsx(Text, { children: "Loading\u2026" }) : null, sessions.data ? (_jsx(List, { empty: "No sessions yet.", children: sessions.data.items.map((s) => (_jsx(Row, { title: `${String(s.values.date ?? "")} · ${String(s.values.name ?? "")}`, detail: String(s.values.state ?? ""), onPress: () => onOpen(s.id) }, s.id))) })) : null] }));
8
+ return (_jsxs(Screen, { title: name, children: [sessions.isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" })) : null, sessions.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load their sessions. Check the connection and try again." })) : null, sessions.data ? (_jsx(List, { empty: "No sessions yet.", children: sessions.data.items.map((s) => (_jsx(Row, { title: `${String(s.values.date ?? "")} · ${String(s.values.name ?? "")}`, detail: String(s.values.state ?? ""), onPress: () => onOpen(s.id) }, s.id))) })) : null] }));
9
9
  }
@@ -0,0 +1,11 @@
1
+ import { type PastSessionsHooks, type ProgramsHooks } from "@composable-os/pack-programs/client";
2
+ type HistoryHooks = PastSessionsHooks & Pick<ProgramsHooks, "useSession" | "useUpdateSet">;
3
+ export declare function HistoryScreen({ programs, personId, until, }: {
4
+ /** A member's hooks (`usePastSessions`), or a coach's (`useClientPastSessions`). */
5
+ programs: HistoryHooks;
6
+ /** A coach's client. A member is always themselves. */
7
+ personId?: string;
8
+ /** The last date listed: the person's local today. Default today, UTC. */
9
+ until?: string;
10
+ }): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A person's past sessions, for the mobile app (stage 41): newest first, each with its date, its
3
+ // name and how many of its sets were logged; pressing one shows it set by set, read-only, and a
4
+ // logged set can be corrected. For a member (their own) or a coach (`personId`, a client's).
5
+ // It holds no rules: whose sessions they are and what a correction may change are the host's
6
+ // (`x.programs.logUpdate`: the numbers done, effort and the note).
7
+ import { correctionOf, describeDone, describeSet, pastSessionsHook, sessionSets, } from "@composable-os/pack-programs/client";
8
+ import { useState } from "react";
9
+ import { StyleSheet, View } from "react-native";
10
+ import { Button } from "../native-base/button.js";
11
+ import { Field } from "../native-base/field.js";
12
+ import { List } from "../native-base/list.js";
13
+ import { Row } from "../native-base/row.js";
14
+ import { Screen } from "../native-base/screen.js";
15
+ import { Text } from "../native-base/text.js";
16
+ import { theme } from "../native-base/theme.js";
17
+ export function HistoryScreen({ programs, personId, until, }) {
18
+ const [cursors, setCursors] = useState([]);
19
+ const cursor = cursors.at(-1);
20
+ const usePastPage = pastSessionsHook(programs, personId);
21
+ const page = usePastPage({
22
+ ...(until ? { until } : {}),
23
+ ...(cursor ? { cursor } : {}),
24
+ });
25
+ const [open, setOpen] = useState(null);
26
+ if (open)
27
+ return (_jsx(PastSessionScreen, { programs: programs, sessionId: open, personId: personId, onBack: () => {
28
+ setOpen(null);
29
+ page.refetch?.();
30
+ } }));
31
+ if (page.isPending)
32
+ return (_jsx(Screen, { title: "History", children: _jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" }) }));
33
+ if (!page.data)
34
+ return (_jsx(Screen, { title: "History", children: _jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load past sessions." }) }));
35
+ const { sessions, nextCursor } = page.data;
36
+ return (_jsxs(Screen, { title: "History", children: [_jsx(List, { empty: "No past sessions yet.", children: sessions.map((s) => (_jsx(Row, { title: `${s.date ?? ""} · ${s.name ?? "Session"}`, detail: [
37
+ `${s.setsDone} of ${s.setsPlanned} sets`,
38
+ s.programTitle,
39
+ s.state === "skipped" ? "skipped" : null,
40
+ ]
41
+ .filter(Boolean)
42
+ .join(" · "), onPress: () => setOpen(s.id) }, s.id))) }), _jsxs(View, { style: styles.row, children: [cursor ? (_jsx(Button, { quiet: true, label: "Newer", onPress: () => setCursors((c) => c.slice(0, -1)) })) : null, nextCursor ? (_jsx(Button, { quiet: true, label: "Older", onPress: () => setCursors((c) => [...c, nextCursor]) })) : null] })] }));
43
+ }
44
+ function PastSessionScreen({ programs, sessionId, personId, onBack, }) {
45
+ const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
46
+ if (!detail.data)
47
+ return (_jsxs(Screen, { title: "Session", children: [_jsx(Text, { children: detail.isPending ? "Loading…" : "We could not load this session." }), _jsx(Button, { quiet: true, label: "Back", onPress: onBack })] }));
48
+ const { session, exercises, logged } = detail.data;
49
+ const names = new Map(exercises.map((e) => [e.id, e.name]));
50
+ const sets = sessionSets(session.plan, logged);
51
+ return (_jsxs(Screen, { title: session.name ?? "Session", children: [_jsx(Button, { quiet: true, label: "Back", onPress: onBack }), _jsx(Text, { style: styles.muted, children: [session.programTitle, session.date, session.focus].filter(Boolean).join(" · ") }), sets.map((s) => (_jsxs(View, { style: styles.set, children: [_jsxs(Text, { style: styles.heading, children: [s.item, " \u00B7 ", s.logged?.exerciseName ?? names.get(s.exercise) ?? "Exercise", s.level !== null ? ` · level ${s.level}` : ""] }), _jsxs(Text, { style: styles.muted, children: ["Set ", s.setNumber, s.target ? `: ${describeSet(s.target)}` : ""] }), s.logged ? (_jsx(NativeLogged, { programs: programs, set: s.logged, timed: s.target ? s.target.kind !== "reps" : s.logged.actual.seconds !== null, onCorrected: () => detail.refetch?.() })) : (_jsx(Text, { style: styles.muted, children: "Not logged" }))] }, `${s.item}-${s.exercise}-${s.setNumber}`))), !sets.length ? _jsx(Text, { children: "This session has no sets." }) : null] }));
52
+ }
53
+ function NativeLogged({ programs, set, timed, onCorrected, }) {
54
+ const update = programs.useUpdateSet();
55
+ const [editing, setEditing] = useState(false);
56
+ const [count, setCount] = useState("");
57
+ const [load, setLoad] = useState("");
58
+ const [effort, setEffort] = useState("");
59
+ const [note, setNote] = useState("");
60
+ const [error, setError] = useState(null);
61
+ if (!editing)
62
+ return (_jsxs(View, { style: styles.row, children: [_jsxs(Text, { children: [describeDone(set), set.recordedAs === "staff" && set.recordedByName ? ` · by ${set.recordedByName}` : "", set.note ? ` · ${set.note}` : ""] }), _jsx(Button, { quiet: true, label: "Correct", onPress: () => {
63
+ setCount(String((timed ? set.actual.seconds : set.actual.reps) ?? ""));
64
+ setLoad(String(set.actual.load ?? ""));
65
+ setEffort(String(set.rpe ?? ""));
66
+ setNote(set.note ?? "");
67
+ setError(null);
68
+ setEditing(true);
69
+ } })] }));
70
+ return (_jsxs(View, { style: styles.form, children: [_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 })] }), _jsx(Field, { label: "Note", value: note, onChangeText: setNote, error: error }), _jsxs(View, { style: styles.row, children: [_jsx(Button, { label: "Save", busy: update.isPending, onPress: async () => {
71
+ const correction = correctionOf(set, { count, load, rpe: effort, note }, timed);
72
+ if (!correction) {
73
+ setEditing(false);
74
+ return;
75
+ }
76
+ setError(null);
77
+ try {
78
+ await update.mutateAsync(correction);
79
+ setEditing(false);
80
+ onCorrected();
81
+ }
82
+ catch (e) {
83
+ setError(e.message ?? "Not corrected");
84
+ }
85
+ } }), _jsx(Button, { quiet: true, label: "Cancel", onPress: () => setEditing(false) })] })] }));
86
+ }
87
+ const styles = StyleSheet.create({
88
+ muted: { color: theme.color.muted, fontSize: theme.font.small },
89
+ heading: { fontSize: theme.font.body, fontWeight: "600", color: theme.color.text },
90
+ set: {
91
+ gap: theme.space.xs,
92
+ padding: theme.space.sm,
93
+ backgroundColor: theme.color.surface,
94
+ borderRadius: theme.radius,
95
+ },
96
+ form: { gap: theme.space.sm },
97
+ row: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", gap: theme.space.sm },
98
+ });
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
- import { Text } from "react-native";
4
3
  import { List } from "../native-base/list.js";
5
4
  import { Row } from "../native-base/row.js";
6
5
  import { Screen } from "../native-base/screen.js";
6
+ import { Text } from "../native-base/text.js";
7
7
  const best = (b) => [
8
8
  b.load !== null ? `${b.load} kg` : null,
9
9
  b.reps !== null ? `${b.reps} reps` : null,
10
10
  b.seconds !== null ? `${b.seconds} s` : null,
11
11
  ]
12
12
  .filter(Boolean)
13
- .join(" · ");
13
+ .join(" · ") || "—";
14
14
  export function ProgressScreen({ programs, personId, }) {
15
15
  const progress = programs.useProgress(personId ? { personId } : {});
16
16
  const [exercise, setExercise] = useState(null);
@@ -19,8 +19,8 @@ export function ProgressScreen({ programs, personId, }) {
19
19
  ...(personId ? { personId } : {}),
20
20
  });
21
21
  if (!progress.data)
22
- return (_jsx(Screen, { title: "Progress", children: _jsx(Text, { children: "Loading\u2026" }) }));
23
- return (_jsxs(Screen, { title: "Progress", children: [_jsx(List, { empty: "No program yet.", children: progress.data.assignments.map((a) => (_jsx(Row, { title: a.title ?? "Program", detail: `${a.done} of ${a.sessions} done` }, a.id))) }), _jsx(List, { empty: "Nothing logged yet.", children: progress.data.exercises.map((e) => (_jsx(Row, { title: e.name ?? "Exercise", detail: `${e.sets} sets · best ${best(e.best)}`, onPress: () => setExercise(e.id) }, e.id))) }), exercise && history.data ? (_jsx(List, { children: history.data.sets.map((s) => (_jsx(Row, { title: `${s.date ?? ""} · set ${s.setNumber ?? ""}${s.level ? ` · level ${s.level}` : ""}`, detail: [
22
+ return (_jsx(Screen, { title: "Progress", children: progress.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load your progress. Check the connection and try again." })) : (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading\u2026" })) }));
23
+ return (_jsxs(Screen, { title: "Progress", children: [_jsx(List, { empty: "No program yet.", children: progress.data.assignments.map((a) => (_jsx(Row, { title: a.title ?? "Program", detail: `${a.done} of ${a.sessions} done` }, a.id))) }), _jsx(List, { empty: "Nothing logged yet.", children: progress.data.exercises.map((e) => (_jsx(Row, { title: e.name ?? "Exercise", detail: `${e.sets} sets · best ${best(e.best)}`, onPress: () => setExercise(e.id) }, e.id))) }), exercise && history.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not load the sets. Check the connection and try again." })) : null, exercise && history.data ? (_jsx(List, { children: history.data.sets.map((s) => (_jsx(Row, { title: `${s.date ?? ""} · set ${s.setNumber ?? ""}${s.level ? ` · level ${s.level}` : ""}`, detail: [
24
24
  s.actual.reps,
25
25
  s.actual.seconds !== null ? `${s.actual.seconds}s` : null,
26
26
  s.actual.load !== null ? `${s.actual.load}kg` : null,
@@ -1,7 +1,11 @@
1
1
  import { type ProgramsHooks } from "@composable-os/pack-programs/client";
2
- export declare function SessionScreen({ programs, sessionId, personId, onRestDone, }: {
3
- programs: Pick<ProgramsHooks, "useLogSet" | "useMarkSession" | "useSession" | "useUpdateSet">;
2
+ type Programs = Pick<ProgramsHooks, "useMarkSession" | "useSessionLog">;
3
+ export declare function SessionScreen({ programs, sessionId, personId, onRestDone, defaultRest, }: {
4
+ programs: Programs;
4
5
  sessionId: string;
5
6
  personId?: string;
6
7
  onRestDone?: () => void;
8
+ /** Seconds of rest after a set whose plan names none. */
9
+ defaultRest?: number;
7
10
  }): import("react").JSX.Element;
11
+ export {};