@composable-os/pack-programs 0.0.0-stage → 0.1.0-beta.7
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.
- package/LICENSE +109 -0
- package/dist/authoring.d.ts +47 -0
- package/dist/authoring.js +493 -0
- package/dist/blocks/programs-bank/exercise-bank.d.ts +4 -0
- package/dist/blocks/programs-bank/exercise-bank.js +68 -0
- package/dist/blocks/programs-builder/program-builder.d.ts +26 -0
- package/dist/blocks/programs-builder/program-builder.js +295 -0
- package/dist/blocks/programs-class-today/class-today.d.ts +6 -0
- package/dist/blocks/programs-class-today/class-today.js +15 -0
- package/dist/blocks/programs-coach-client/coach-client.d.ts +5 -0
- package/dist/blocks/programs-coach-client/coach-client.js +10 -0
- package/dist/blocks/programs-native-class-today/class-today-screen.d.ts +6 -0
- package/dist/blocks/programs-native-class-today/class-today-screen.js +14 -0
- package/dist/blocks/programs-native-coach-client/coach-client-screen.d.ts +7 -0
- package/dist/blocks/programs-native-coach-client/coach-client-screen.js +9 -0
- package/dist/blocks/programs-native-progress/progress-screen.d.ts +5 -0
- package/dist/blocks/programs-native-progress/progress-screen.js +31 -0
- package/dist/blocks/programs-native-session/session-screen.d.ts +7 -0
- package/dist/blocks/programs-native-session/session-screen.js +130 -0
- package/dist/blocks/programs-native-today/today-screen.d.ts +7 -0
- package/dist/blocks/programs-native-today/today-screen.js +11 -0
- package/dist/blocks/programs-progress/progress.d.ts +10 -0
- package/dist/blocks/programs-progress/progress.js +40 -0
- package/dist/blocks/programs-session/session-view.d.ts +9 -0
- package/dist/blocks/programs-session/session-view.js +116 -0
- package/dist/blocks/programs-today/today.d.ts +7 -0
- package/dist/blocks/programs-today/today.js +16 -0
- package/dist/client/index.d.ts +1721 -0
- package/dist/client/index.js +778 -0
- package/dist/dashboards.d.ts +5 -0
- package/dist/dashboards.js +145 -0
- package/dist/index.d.ts +1181 -0
- package/dist/index.js +608 -0
- package/dist/layout.d.ts +88 -0
- package/dist/layout.js +268 -0
- package/dist/tools.d.ts +344 -0
- package/dist/tools.js +930 -0
- package/package.json +36 -4
- package/README.md +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Button } from "../ui-button/button.js";
|
|
4
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
5
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
import { Label } from "../ui-label/label.js";
|
|
7
|
+
const MEASURES = [
|
|
8
|
+
{ value: "weight_reps", label: "Weight and reps" },
|
|
9
|
+
{ value: "reps", label: "Reps" },
|
|
10
|
+
{ value: "time", label: "Time" },
|
|
11
|
+
{ value: "hold", label: "Hold" },
|
|
12
|
+
];
|
|
13
|
+
export function ExerciseBank({ programs, }) {
|
|
14
|
+
const [search, setSearch] = useState("");
|
|
15
|
+
const bank = programs.useBank(search);
|
|
16
|
+
const all = programs.useBank();
|
|
17
|
+
const [editing, setEditing] = useState(null);
|
|
18
|
+
return (_jsxs("div", { className: "grid gap-4", "data-testid": "exercise-bank", children: [_jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Input, { "aria-label": "Search the bank", placeholder: "Search the bank", value: search, onChange: (e) => setSearch(e.target.value), className: "max-w-sm" }), _jsx(Button, { onClick: () => setEditing("new"), children: "Add exercise" })] }), editing ? (_jsx(ExerciseForm, { programs: programs, exercise: editing === "new" ? null : editing, bank: all.data?.items ?? [], onDone: () => {
|
|
19
|
+
setEditing(null);
|
|
20
|
+
bank.refetch?.();
|
|
21
|
+
all.refetch?.();
|
|
22
|
+
} })) : null, _jsxs("ul", { className: "grid gap-2", "aria-label": "Exercises", children: [(bank.data?.items ?? []).map((e) => (_jsxs("li", { className: "flex flex-wrap items-center gap-2 text-sm", children: [_jsx(Button, { variant: "link", onClick: () => setEditing(e), children: String(e.values.name) }), _jsx("span", { className: "text-muted-foreground", children: [
|
|
23
|
+
MEASURES.find((m) => m.value === e.values.measure)?.label,
|
|
24
|
+
e.values.theme,
|
|
25
|
+
e.values.level,
|
|
26
|
+
]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join(" · ") })] }, e.id))), bank.data && !bank.data.items.length ? _jsx("li", { children: "No exercise matches." }) : null] })] }));
|
|
29
|
+
}
|
|
30
|
+
function ExerciseForm({ programs, exercise, bank, onDone, }) {
|
|
31
|
+
const create = programs.useCreateExercise();
|
|
32
|
+
const update = programs.useUpdateExercise();
|
|
33
|
+
const v = exercise?.values ?? {};
|
|
34
|
+
const [name, setName] = useState(String(v.name ?? ""));
|
|
35
|
+
const [video, setVideo] = useState(String(v.video ?? ""));
|
|
36
|
+
const [cues, setCues] = useState(String(v.cues ?? ""));
|
|
37
|
+
const [measure, setMeasure] = useState(String(v.measure ?? "reps"));
|
|
38
|
+
const [easier, setEasier] = useState(v.easier ?? []);
|
|
39
|
+
const [harder, setHarder] = useState(v.harder ?? []);
|
|
40
|
+
const [error, setError] = useState(null);
|
|
41
|
+
const others = bank.filter((e) => e.id !== exercise?.id);
|
|
42
|
+
const toggle = (list, id) => list.includes(id) ? list.filter((x) => x !== id) : [...list, id];
|
|
43
|
+
const save = async () => {
|
|
44
|
+
setError(null);
|
|
45
|
+
const values = {
|
|
46
|
+
name: name.trim(),
|
|
47
|
+
video: video.trim() || null,
|
|
48
|
+
cues: cues.trim() || null,
|
|
49
|
+
measure,
|
|
50
|
+
easier: easier.length ? easier : null,
|
|
51
|
+
harder: harder.length ? harder : null,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
if (exercise)
|
|
55
|
+
await update.mutateAsync({ object: "programs.exercise", id: exercise.id, values });
|
|
56
|
+
else
|
|
57
|
+
await create.mutateAsync({ object: "programs.exercise", values });
|
|
58
|
+
onDone();
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
setError(e.message ?? "Not saved");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: exercise ? `Edit ${String(v.name ?? "")}` : "New exercise" }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "exercise-name", children: "Name" }), _jsx(Input, { id: "exercise-name", value: name, onChange: (e) => setName(e.target.value) })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "exercise-video", children: "Demo video (a link)" }), _jsx(Input, { id: "exercise-video", value: video, onChange: (e) => setVideo(e.target.value) })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "exercise-cues", children: "Coaching cues" }), _jsx("textarea", { id: "exercise-cues", className: "min-h-16 rounded-md border p-2", value: cues, onChange: (e) => setCues(e.target.value) })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "exercise-measure", children: "Measured by" }), _jsx("select", { id: "exercise-measure", className: "h-9 rounded-md border px-2", value: measure, onChange: (e) => setMeasure(e.target.value), children: MEASURES.map((m) => (_jsx("option", { value: m.value, children: m.label }, m.value))) })] }), [
|
|
65
|
+
["Easier versions", easier, setEasier],
|
|
66
|
+
["Harder versions", harder, setHarder],
|
|
67
|
+
].map(([label, list, set]) => (_jsxs("fieldset", { className: "grid gap-1", children: [_jsx("legend", { className: "text-xs text-muted-foreground", children: label }), _jsx("div", { className: "flex flex-wrap gap-1", children: others.map((e) => (_jsx(Button, { size: "xs", variant: list.includes(e.id) ? "default" : "outline", "aria-pressed": list.includes(e.id), onClick: () => set(toggle(list, e.id)), children: String(e.values.name) }, e.id))) })] }, label))), error ? (_jsx("p", { role: "alert", className: "text-destructive", children: error })) : null, _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { disabled: !name.trim() || create.isPending || update.isPending, onClick: () => void save(), children: "Save" }), _jsx(Button, { variant: "ghost", onClick: onDone, children: "Cancel" })] })] })] }));
|
|
68
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ProgramsHooks, type RecordOut } from "@composable-os/pack-programs/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
interface Bank {
|
|
4
|
+
byId: Map<string, RecordOut>;
|
|
5
|
+
list: RecordOut[];
|
|
6
|
+
/** 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">;
|
|
8
|
+
}
|
|
9
|
+
/** The whole builder for one program. */
|
|
10
|
+
export declare function ProgramBuilder({ programs, programId, }: {
|
|
11
|
+
programs: Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
|
|
12
|
+
programId: string;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
/** A search over the bank: type, then pick with a click, or Enter for the first match. */
|
|
15
|
+
export declare function ExercisePicker({ bank, label, onPick, compact, }: {
|
|
16
|
+
bank: Bank;
|
|
17
|
+
label: string;
|
|
18
|
+
onPick: (exerciseId: string) => void;
|
|
19
|
+
compact?: boolean;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
/** A list of programs with a button to open one, and to start one blank, drafted or imported. */
|
|
22
|
+
export declare function ProgramList({ programs, onOpen, }: {
|
|
23
|
+
programs: Pick<ProgramsHooks, "useAssign" | "useBank" | "useClassTypes" | "useCreateProgram" | "useDraft" | "useExercises" | "useImportText" | "usePeople" | "usePrograms" | "usePublish" | "usePublishOffered" | "useRestoreVersion" | "useVersions" | "useWorkingCopy">;
|
|
24
|
+
onOpen: (programId: string) => void;
|
|
25
|
+
}): ReactNode;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// The coach's program builder (stage 41): weeks, sessions, blocks and items, by drag and by
|
|
3
|
+
// keyboard; exercises picked from the bank; typed sets; levels; notes, for coaches or shown to
|
|
4
|
+
// members; copying a week or a session; the working copy saved as the coach goes, with the host's
|
|
5
|
+
// faults shown where they are; versions, restoring one, publishing, and assigning.
|
|
6
|
+
//
|
|
7
|
+
// Built on the web base layer. It holds no rules: what a layout may hold is the host's schema
|
|
8
|
+
// (a refused save shows the host's words at the part it names), who may publish is the host's
|
|
9
|
+
// (the button is offered from what `user.me` says, and the host decides), and assigning makes
|
|
10
|
+
// its dates in the host. Editing is `layoutEdits` from the pack's client.
|
|
11
|
+
import { describeSets, exercisesIn, faultsUnder, layoutEdits, layoutSummary, levelExercises, levelLabel, numberFrom, pathOf, } from "@composable-os/pack-programs/client";
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
import { Button } from "../ui-button/button.js";
|
|
14
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
15
|
+
import { Input } from "../ui-input/input.js";
|
|
16
|
+
import { Label } from "../ui-label/label.js";
|
|
17
|
+
const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
18
|
+
const nameOf = (bank, id) => String(bank.byId.get(id)?.values.name ?? "Unknown exercise");
|
|
19
|
+
const measureOf = (bank, id) => bank.byId.get(id)?.values.measure ?? null;
|
|
20
|
+
/** The whole builder for one program. */
|
|
21
|
+
export function ProgramBuilder({ programs, programId, }) {
|
|
22
|
+
const copy = programs.useWorkingCopy(programId);
|
|
23
|
+
const bankQuery = programs.useBank();
|
|
24
|
+
// The program's own exercises by id, so a bank larger than one page still names them.
|
|
25
|
+
const ownQuery = programs.useExercises(copy.layout ? exercisesIn(copy.layout) : []);
|
|
26
|
+
const [week, setWeek] = useState(0);
|
|
27
|
+
if (copy.isPending || bankQuery.isPending)
|
|
28
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the program\u2026" });
|
|
29
|
+
if (copy.error || !copy.layout)
|
|
30
|
+
return _jsx("p", { role: "alert", children: "We could not load this program." });
|
|
31
|
+
const list = bankQuery.data?.items ?? [];
|
|
32
|
+
const byId = new Map([...list, ...(ownQuery.data?.items ?? [])].map((e) => [e.id, e]));
|
|
33
|
+
const bank = { list, byId, programs };
|
|
34
|
+
const layout = copy.layout;
|
|
35
|
+
const current = Math.min(week, layout.weeks.length - 1);
|
|
36
|
+
const summary = layoutSummary(layout);
|
|
37
|
+
const missing = ownQuery.isPending ? [] : exercisesIn(layout).filter((id) => !bank.byId.has(id));
|
|
38
|
+
return (_jsxs("div", { className: "grid gap-6", "data-testid": "program-builder", children: [_jsxs("header", { className: "grid gap-2", children: [_jsx(Label, { htmlFor: "program-title", children: "Title" }), _jsx(Input, { id: "program-title", value: copy.title, onChange: (e) => copy.rename(e.target.value), className: "text-lg font-semibold" }), _jsxs("div", { className: "flex flex-wrap items-center gap-3 text-sm text-muted-foreground", children: [_jsxs("span", { children: [summary.weeks, " weeks \u00B7 ", summary.sessions, " sessions \u00B7 ", summary.items, " items"] }), _jsx(SaveStatus, { state: copy.state }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => void copy.saveNow(), children: "Save now" })] }), copy.state === "refused" && copy.message ? (_jsxs("p", { role: "alert", className: "text-sm text-destructive", "data-testid": "save-refused", children: ["Not saved: ", copy.message] })) : null, missing.length ? (_jsxs("p", { className: "text-sm text-destructive", children: [missing.length, " exercise(s) in this layout are no longer in the bank."] })) : null] }), _jsx(WeekTabs, { layout: layout, current: current, onSelect: setWeek, change: copy.change, faults: copy.faults }), _jsx(WeekView, { layout: layout, week: current, bank: bank, change: copy.change, faults: copy.faults }), _jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [_jsx(Versions, { programs: programs, programId: programId, onRestored: (l, t) => copy.reset(l, t) }), _jsx(Assign, { programs: programs, programId: programId })] })] }));
|
|
39
|
+
}
|
|
40
|
+
function SaveStatus({ state }) {
|
|
41
|
+
const text = state === "saving"
|
|
42
|
+
? "Saving…"
|
|
43
|
+
: state === "unsaved"
|
|
44
|
+
? "Unsaved changes"
|
|
45
|
+
: state === "refused"
|
|
46
|
+
? "Not saved"
|
|
47
|
+
: "Saved";
|
|
48
|
+
return (_jsx("span", { "aria-live": "polite", "data-testid": "save-status", "data-state": state, children: text }));
|
|
49
|
+
}
|
|
50
|
+
function Faults({ faults, path }) {
|
|
51
|
+
const here = faultsUnder(faults, path);
|
|
52
|
+
if (!here.length)
|
|
53
|
+
return null;
|
|
54
|
+
return (_jsx("ul", { role: "alert", className: "grid gap-1 text-sm text-destructive", "data-testid": "fault", children: here.map((m) => (_jsx("li", { children: m }, m))) }));
|
|
55
|
+
}
|
|
56
|
+
// --- Weeks ---------------------------------------------------------------------------------------
|
|
57
|
+
function WeekTabs({ layout, current, onSelect, change, faults, }) {
|
|
58
|
+
const onKey = (event) => {
|
|
59
|
+
if (event.key === "ArrowRight")
|
|
60
|
+
onSelect(Math.min(current + 1, layout.weeks.length - 1));
|
|
61
|
+
if (event.key === "ArrowLeft")
|
|
62
|
+
onSelect(Math.max(current - 1, 0));
|
|
63
|
+
};
|
|
64
|
+
return (_jsxs("nav", { className: "grid gap-2", "aria-label": "Weeks", children: [_jsx("div", { role: "tablist", className: "flex flex-wrap gap-1", onKeyDown: onKey, children: layout.weeks.map((w, i) => (_jsx(Button
|
|
65
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: weeks are positions.
|
|
66
|
+
, { role: "tab", "aria-selected": i === current, size: "sm", variant: i === current
|
|
67
|
+
? "default"
|
|
68
|
+
: faultsUnder(faults, `weeks.${i}`).length
|
|
69
|
+
? "destructive"
|
|
70
|
+
: "outline", onClick: () => onSelect(i), children: w.label || `Week ${i + 1}` }, i))) }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
71
|
+
change(layoutEdits.addWeek(layout));
|
|
72
|
+
onSelect(layout.weeks.length);
|
|
73
|
+
}, children: "Add week" }), _jsx(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
74
|
+
change(layoutEdits.copyWeek(layout, current));
|
|
75
|
+
onSelect(current + 1);
|
|
76
|
+
}, children: "Copy this week" }), _jsx(Button, { size: "sm", variant: "ghost", disabled: layout.weeks.length < 2, onClick: () => {
|
|
77
|
+
change(layoutEdits.removeWeek(layout, current));
|
|
78
|
+
onSelect(Math.max(0, current - 1));
|
|
79
|
+
}, children: "Remove this week" }), _jsx(Input, { "aria-label": "Week name", placeholder: `Week ${current + 1}`, value: layout.weeks[current]?.label ?? "", onChange: (e) => change(layoutEdits.setWeekLabel(layout, current, e.target.value)), className: "h-8 w-48" })] })] }));
|
|
80
|
+
}
|
|
81
|
+
function WeekView({ layout, week, bank, change, faults, }) {
|
|
82
|
+
const sessions = layout.weeks[week]?.sessions ?? [];
|
|
83
|
+
return (_jsxs("section", { className: "grid gap-4", "aria-label": `Week ${week + 1}`, children: [_jsx(Faults, { faults: new Map([...faults].filter(([p]) => p === `weeks.${week}.sessions`)), path: `weeks.${week}.sessions` }), sessions.map((session, s) => (_jsx(SessionCard
|
|
84
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: sessions are positions in their week.
|
|
85
|
+
, { layout: layout, at: { week, session: s }, bank: bank, change: change, faults: faults, last: s === sessions.length - 1, title: session.name }, s))), _jsx("div", { children: _jsx(Button, { variant: "outline", onClick: () => change(layoutEdits.addSession(layout, week)), children: "Add session" }) })] }));
|
|
86
|
+
}
|
|
87
|
+
// --- Sessions ------------------------------------------------------------------------------------
|
|
88
|
+
function SessionCard({ layout, at, bank, change, faults, last, title, }) {
|
|
89
|
+
const session = layout.weeks[at.week]?.sessions[at.session ?? 0];
|
|
90
|
+
const [dragging, setDragging] = useState(null);
|
|
91
|
+
if (!session)
|
|
92
|
+
return null;
|
|
93
|
+
const path = pathOf(at);
|
|
94
|
+
const later = layout.weeks.length - at.week - 1;
|
|
95
|
+
return (_jsxs(Card, { "data-testid": "session", "aria-label": `Session ${title}`, children: [_jsxs(CardHeader, { className: "grid gap-2", children: [_jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: "Session name" }), _jsx(Input, { "aria-label": "Session name", value: session.name, onChange: (e) => change(layoutEdits.setSession(layout, at, { name: e.target.value })) })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: "Day" }), _jsx("select", { "aria-label": "Day", className: "h-9 rounded-md border px-2", value: session.day, onChange: (e) => change(layoutEdits.setSession(layout, at, { day: Number(e.target.value) })), children: DAYS.map((d, i) => (_jsx("option", { value: i + 1, children: d }, d))) })] }), _jsxs("div", { className: "grid flex-1 gap-1", children: [_jsx(Label, { children: "Focus" }), _jsx(Input, { "aria-label": "Focus", value: session.focus ?? "", onChange: (e) => change(layoutEdits.setSession(layout, at, { focus: e.target.value })) })] })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { size: "sm", variant: "outline", onClick: () => change(layoutEdits.copySession(layout, at)), children: "Copy session" }), _jsxs(Button, { size: "sm", variant: "outline", disabled: later === 0, onClick: () => {
|
|
96
|
+
let next = layout;
|
|
97
|
+
for (let w = at.week + 1; w < layout.weeks.length; w += 1)
|
|
98
|
+
next = layoutEdits.copySession(next, at, w);
|
|
99
|
+
change(next);
|
|
100
|
+
}, children: ["Copy to the ", later, " following week(s)"] }), _jsx(Button, { size: "sm", variant: "ghost", disabled: at.session === 0, onClick: () => change(layoutEdits.moveSession(layout, at.week, at.session ?? 0, (at.session ?? 0) - 1)), children: "Move up" }), _jsx(Button, { size: "sm", variant: "ghost", disabled: last, onClick: () => change(layoutEdits.moveSession(layout, at.week, at.session ?? 0, (at.session ?? 0) + 1)), children: "Move down" }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => change(layoutEdits.removeSession(layout, at)), children: "Remove session" })] }), _jsx(Faults, { faults: new Map([...faults].filter(([p]) => !p.includes(".blocks.") && p.startsWith(path))), path: path })] }), _jsxs(CardContent, { className: "grid gap-4", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: "Warm-up" }), _jsx("textarea", { "aria-label": "Warm-up", className: "min-h-16 rounded-md border p-2 text-sm", value: session.warmup?.text ?? "", onChange: (e) => change(layoutEdits.setWarmup(layout, at, e.target.value)) })] }), session.blocks.map((block, b) => {
|
|
101
|
+
const blockAt = { ...at, block: b };
|
|
102
|
+
return (_jsxs("section", { className: "grid gap-3 rounded-md border p-3", "aria-label": `Block ${block.label}`, "data-testid": "block", onDragOver: (e) => e.preventDefault(), onDrop: () => {
|
|
103
|
+
if (dragging)
|
|
104
|
+
change(layoutEdits.moveItem(layout, { ...at, ...dragging }, { block: b, item: block.items.length }));
|
|
105
|
+
setDragging(null);
|
|
106
|
+
}, children: [_jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: "Block" }), _jsx(Input, { "aria-label": "Block label", className: "w-20", value: block.label, onChange: (e) => change(layoutEdits.setBlock(layout, blockAt, { label: e.target.value })) })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { children: "Rounds" }), _jsx(Input, { "aria-label": "Rounds", className: "w-24", inputMode: "numeric", value: block.rounds ?? "", onChange: (e) => change(layoutEdits.setBlock(layout, blockAt, {
|
|
107
|
+
rounds: numberFrom(e.target.value) ?? null,
|
|
108
|
+
})) })] }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => change(layoutEdits.removeBlock(layout, blockAt)), children: "Remove block" })] }), _jsx(Faults, { faults: new Map([...faults].filter(([p]) => !p.includes(".items.") && p.startsWith(pathOf(blockAt)))), path: pathOf(blockAt) }), _jsx("ol", { className: "grid gap-3", children: block.items.map((item, i) => (_jsx(ItemEditor
|
|
109
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: items are positions in their block.
|
|
110
|
+
, { layout: layout, at: { ...blockAt, item: i }, item: item, bank: bank, change: change, faults: faults, count: block.items.length, onDragStart: () => setDragging({ block: b, item: i }), onDrop: () => {
|
|
111
|
+
if (dragging)
|
|
112
|
+
change(layoutEdits.moveItem(layout, { ...at, ...dragging }, { block: b, item: i }));
|
|
113
|
+
setDragging(null);
|
|
114
|
+
} }, i))) }), _jsx(ExercisePicker, { bank: bank, label: `Add an item to block ${block.label}`, onPick: (id) => change(layoutEdits.addItem(layout, blockAt, id, measureOf(bank, id))) }), _jsx(NotesEditor, { notes: block.notes ?? [], onAdd: (text, members) => change(layoutEdits.addNote(layout, blockAt, text, members)), onChange: (index, note) => change(layoutEdits.setNote(layout, blockAt, index, note)) })] }, b));
|
|
115
|
+
}), _jsx("div", { className: "flex flex-wrap gap-2", children: _jsx(Button, { variant: "outline", onClick: () => change(layoutEdits.addBlock(layout, at)), children: "Add block" }) }), _jsx(NotesEditor, { notes: session.notes ?? [], onAdd: (text, members) => change(layoutEdits.addNote(layout, at, text, members)), onChange: (index, note) => change(layoutEdits.setNote(layout, at, index, note)) })] })] }));
|
|
116
|
+
}
|
|
117
|
+
// --- Items ---------------------------------------------------------------------------------------
|
|
118
|
+
function ItemEditor({ layout, at, item, bank, change, faults, count, onDragStart, onDrop, }) {
|
|
119
|
+
const index = at.item ?? 0;
|
|
120
|
+
const moveTo = (to) => change(layoutEdits.moveItem(layout, at, { block: at.block ?? 0, item: to }));
|
|
121
|
+
const onKey = (event) => {
|
|
122
|
+
if (!event.altKey)
|
|
123
|
+
return;
|
|
124
|
+
if (event.key === "ArrowUp" && index > 0) {
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
moveTo(index - 1);
|
|
127
|
+
}
|
|
128
|
+
if (event.key === "ArrowDown" && index < count - 1) {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
moveTo(index + 1);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
return (_jsxs("li", { draggable: true, onDragStart: (e) => {
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
onDragStart();
|
|
136
|
+
}, onDragOver: (e) => e.preventDefault(), onDrop: (e) => {
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
onDrop();
|
|
139
|
+
}, 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
|
+
// 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)) })] }));
|
|
142
|
+
}
|
|
143
|
+
function LevelsEditor({ layout, at, levels, bank, change, }) {
|
|
144
|
+
const used = new Set(levels.map((l) => l.level));
|
|
145
|
+
return (_jsxs("div", { className: "grid gap-3", children: [levels.map((level, l) => {
|
|
146
|
+
const levelAt = { ...at, level: l };
|
|
147
|
+
const exercises = levelExercises(level);
|
|
148
|
+
return (_jsxs("div", { className: "grid gap-2 border-l-2 pl-3", "data-testid": "level", "data-level": level.level, title: levelLabel(level), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("select", { "aria-label": "Level", className: "h-8 rounded-md border px-2 text-sm", value: level.level, onChange: (e) => change(layoutEdits.setLevelNumber(layout, levelAt, Number(e.target.value))), children: [1, 2, 3, 4, 5].map((n) => (_jsxs("option", { value: n, disabled: n !== level.level && used.has(n), children: ["Level ", n] }, n))) }), _jsxs("select", { "aria-label": "Done as", className: "h-8 rounded-md border px-2 text-sm", value: level.mode, onChange: (e) => change(layoutEdits.setLevelMode(layout, levelAt, e.target.value)), children: [_jsx("option", { value: "one", children: "One exercise" }), _jsx("option", { value: "together", disabled: exercises.length < 2, children: "Together" }), _jsx("option", { value: "alternatives", disabled: exercises.length < 2, children: "One of these" })] }), _jsx(Button, { size: "xs", variant: "ghost", onClick: () => change(layoutEdits.removeLevel(layout, levelAt)), children: "Remove level" })] }), exercises.map((p, e) => (_jsx(PrescriptionEditor
|
|
149
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: exercises are positions in their level.
|
|
150
|
+
, { layout: layout, at: { ...levelAt, exercise: e }, prescription: p, bank: bank, change: change, removable: exercises.length > 1 }, e))), _jsx(ExercisePicker, { bank: bank, compact: true, label: `Add another exercise to level ${level.level}`, onPick: (id) => change(layoutEdits.addExercise(layout, levelAt, id, measureOf(bank, id))) })] }, l));
|
|
151
|
+
}), levels.length < 5 ? (_jsx(ExercisePicker, { bank: bank, label: "Add a level", onPick: (id) => change(layoutEdits.addLevel(layout, at, id, measureOf(bank, id))) })) : null] }));
|
|
152
|
+
}
|
|
153
|
+
function PrescriptionEditor({ layout, at, prescription, bank, change, removable, }) {
|
|
154
|
+
const [swapping, setSwapping] = useState(false);
|
|
155
|
+
return (_jsxs("div", { className: "grid gap-2 rounded-md border bg-background p-2", "data-testid": "prescription", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("strong", { className: "text-sm", children: nameOf(bank, prescription.exercise) }), _jsx("span", { className: "text-xs text-muted-foreground", children: describeSets(prescription.sets) }), _jsx(Button, { size: "xs", variant: "ghost", onClick: () => setSwapping(!swapping), children: "Swap" }), removable ? (_jsx(Button, { size: "xs", variant: "ghost", onClick: () => change(layoutEdits.removeExercise(layout, at)), children: "Remove" })) : null] }), swapping ? (_jsx(ExercisePicker, { bank: bank, compact: true, label: "Swap for", onPick: (id) => {
|
|
156
|
+
change(layoutEdits.swapExercise(layout, at, id));
|
|
157
|
+
setSwapping(false);
|
|
158
|
+
} })) : null, _jsx(SetsEditor, { layout: layout, at: at, sets: prescription.sets, change: change }), _jsx(Input, { "aria-label": "Coach's words beside the numbers", placeholder: "In your words: legs as straight as possible", value: prescription.note ?? "", onChange: (e) => change(layoutEdits.setPrescriptionNote(layout, at, e.target.value)), className: "h-8 text-sm" })] }));
|
|
159
|
+
}
|
|
160
|
+
function SetsEditor({ layout, at, sets, change, }) {
|
|
161
|
+
const field = (set, key, value) => change(layoutEdits.setSet(layout, { ...at, set }, {
|
|
162
|
+
[key]: key === "tempo" ? value.toUpperCase() : numberFrom(value),
|
|
163
|
+
}));
|
|
164
|
+
return (_jsxs("table", { className: "text-sm", "data-testid": "sets", children: [_jsx("thead", { className: "text-xs text-muted-foreground", children: _jsxs("tr", { children: [_jsx("th", { className: "text-left font-normal", children: "Set" }), _jsx("th", { className: "text-left font-normal", children: "Kind" }), _jsx("th", { className: "text-left font-normal", children: "Reps / seconds" }), _jsx("th", { className: "text-left font-normal", children: "Load (kg)" }), _jsx("th", { className: "text-left font-normal", children: "Tempo" }), _jsx("th", { className: "text-left font-normal", children: "Rest (s)" }), _jsx("th", {})] }) }), _jsxs("tbody", { children: [sets.map((set, s) => (_jsxs("tr", { children: [_jsx("td", { className: "pr-2", children: s + 1 }), _jsx("td", { className: "pr-2", children: _jsxs("select", { "aria-label": `Set ${s + 1} kind`, className: "h-8 rounded-md border px-1", value: set.kind, onChange: (e) => change(layoutEdits.setSet(layout, { ...at, set: s }, { kind: e.target.value })), children: [_jsx("option", { value: "reps", children: "Reps" }), _jsx("option", { value: "time", children: "Time" }), _jsx("option", { value: "hold", children: "Hold" })] }) }), _jsx("td", { className: "pr-2", children: set.kind === "reps" ? (_jsxs("span", { className: "flex items-center gap-1", children: [_jsx(Input, { "aria-label": `Set ${s + 1} reps`, className: "h-8 w-14", inputMode: "numeric", value: set.reps, onChange: (e) => field(s, "reps", e.target.value) }), "to", _jsx(Input, { "aria-label": `Set ${s + 1} up to reps`, className: "h-8 w-14", inputMode: "numeric", value: set.repsMax ?? "", onChange: (e) => field(s, "repsMax", e.target.value) })] })) : (_jsxs("span", { className: "flex items-center gap-1", children: [_jsx(Input, { "aria-label": `Set ${s + 1} seconds`, className: "h-8 w-16", inputMode: "numeric", value: set.seconds, onChange: (e) => field(s, "seconds", e.target.value) }), set.kind === "hold" ? (_jsxs(_Fragment, { children: ["\u00D7", _jsx(Input, { "aria-label": `Set ${s + 1} holds`, className: "h-8 w-12", inputMode: "numeric", value: set.holds ?? "", onChange: (e) => field(s, "holds", e.target.value) })] })) : null] })) }), _jsx("td", { className: "pr-2", children: _jsx(Input, { "aria-label": `Set ${s + 1} load`, className: "h-8 w-16", inputMode: "decimal", value: set.load ?? "", onChange: (e) => field(s, "load", e.target.value) }) }), _jsx("td", { className: "pr-2", children: set.kind === "reps" ? (_jsx(Input, { "aria-label": `Set ${s + 1} tempo`, className: "h-8 w-16", maxLength: 4, value: set.tempo ?? "", onChange: (e) => field(s, "tempo", e.target.value) })) : null }), _jsx("td", { className: "pr-2", children: _jsx(Input, { "aria-label": `Set ${s + 1} rest`, className: "h-8 w-16", inputMode: "numeric", value: set.rest ?? "", onChange: (e) => field(s, "rest", e.target.value) }) }), _jsx("td", { children: _jsx(Button, { size: "xs", variant: "ghost", "aria-label": `Remove set ${s + 1}`, onClick: () => change(layoutEdits.removeSet(layout, { ...at, set: s })), children: "\u00D7" }) })] }, s))), _jsx("tr", { children: _jsx("td", { colSpan: 7, children: _jsx(Button, { size: "xs", variant: "outline", onClick: () => change(layoutEdits.addSet(layout, at)), children: "Add set" }) }) })] })] }));
|
|
165
|
+
}
|
|
166
|
+
// --- Picking from the bank, notes --------------------------------------------------------------------
|
|
167
|
+
/** A search over the bank: type, then pick with a click, or Enter for the first match. */
|
|
168
|
+
export function ExercisePicker({ bank, label, onPick, compact, }) {
|
|
169
|
+
const [search, setSearch] = useState("");
|
|
170
|
+
const words = search.trim().toLowerCase();
|
|
171
|
+
// The host searches the whole bank; until it answers, the page already loaded is searched.
|
|
172
|
+
const found = bank.programs.useBank(words);
|
|
173
|
+
const matches = words
|
|
174
|
+
? (found.data?.items ??
|
|
175
|
+
bank.list.filter((e) => String(e.values.name ?? "")
|
|
176
|
+
.toLowerCase()
|
|
177
|
+
.includes(words))).slice(0, 8)
|
|
178
|
+
: [];
|
|
179
|
+
const pick = (id) => {
|
|
180
|
+
onPick(id);
|
|
181
|
+
setSearch("");
|
|
182
|
+
};
|
|
183
|
+
return (_jsxs("div", { className: "grid gap-1", children: [_jsx(Input, { "aria-label": label, placeholder: `${label}: search the bank`, className: compact ? "h-8 text-sm" : "", value: search, onChange: (e) => setSearch(e.target.value), onKeyDown: (e) => {
|
|
184
|
+
if (e.key === "Enter" && matches[0]) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
pick(matches[0].id);
|
|
187
|
+
}
|
|
188
|
+
if (e.key === "Escape")
|
|
189
|
+
setSearch("");
|
|
190
|
+
} }), matches.length ? (_jsx("ul", { className: "flex flex-wrap gap-1", "aria-label": "Matching exercises", children: matches.map((e) => (_jsx("li", { children: _jsx(Button, { size: "xs", variant: "secondary", onClick: () => pick(e.id), children: String(e.values.name) }) }, e.id))) })) : words ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "No exercise in the bank matches. Add it to the bank first." })) : null] }));
|
|
191
|
+
}
|
|
192
|
+
function NotesEditor({ notes, onAdd, onChange, }) {
|
|
193
|
+
const [text, setText] = useState("");
|
|
194
|
+
const [members, setMembers] = useState(false);
|
|
195
|
+
return (_jsxs("div", { className: "grid gap-1 text-sm", children: [notes.map((note, i) => (_jsxs("div", { className: "flex items-center gap-2", "data-testid": "note", children: [_jsx(Input, { "aria-label": `Note ${i + 1}`, className: "h-8 flex-1 text-sm", value: note.text, onChange: (e) => onChange(i, { ...note, text: e.target.value }) }), _jsxs("label", { className: "flex items-center gap-1 text-xs", children: [_jsx("input", { type: "checkbox", checked: Boolean(note.members), onChange: (e) => onChange(i, { ...note, members: e.target.checked }) }), "Shown to members"] }), _jsx(Button, { size: "xs", variant: "ghost", onClick: () => onChange(i, null), children: "\u00D7" })] }, i))), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { "aria-label": "New note", placeholder: "A note (for coaches unless shown to members)", className: "h-8 flex-1 text-sm", value: text, onChange: (e) => setText(e.target.value), onKeyDown: (e) => {
|
|
196
|
+
if (e.key === "Enter" && text.trim()) {
|
|
197
|
+
onAdd(text.trim(), members);
|
|
198
|
+
setText("");
|
|
199
|
+
}
|
|
200
|
+
} }), _jsxs("label", { className: "flex items-center gap-1 text-xs", children: [_jsx("input", { type: "checkbox", checked: members, onChange: (e) => setMembers(e.target.checked) }), "Shown to members"] }), _jsx(Button, { size: "xs", variant: "outline", disabled: !text.trim(), onClick: () => {
|
|
201
|
+
onAdd(text.trim(), members);
|
|
202
|
+
setText("");
|
|
203
|
+
}, children: "Add note" })] })] }));
|
|
204
|
+
}
|
|
205
|
+
// --- Versions, publishing and assigning ----------------------------------------------------------
|
|
206
|
+
function Versions({ programs, programId, onRestored, }) {
|
|
207
|
+
const versions = programs.useVersions(programId);
|
|
208
|
+
const offered = programs.usePublishOffered();
|
|
209
|
+
const publish = programs.usePublish();
|
|
210
|
+
const restore = programs.useRestoreVersion();
|
|
211
|
+
const [note, setNote] = useState("");
|
|
212
|
+
const [said, setSaid] = useState(null);
|
|
213
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: "Versions" }) }), _jsxs(CardContent, { className: "grid gap-3", children: [offered ? (_jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Input, { "aria-label": "What changed", placeholder: "What changed (optional)", value: note, onChange: (e) => setNote(e.target.value), className: "h-9 flex-1" }), _jsx(Button, { disabled: publish.isPending, onClick: async () => {
|
|
214
|
+
try {
|
|
215
|
+
const out = await publish.mutateAsync({
|
|
216
|
+
object: "programs.program",
|
|
217
|
+
id: programId,
|
|
218
|
+
...(note.trim() ? { note: note.trim() } : {}),
|
|
219
|
+
});
|
|
220
|
+
setSaid(`Published as version ${out.version}.`);
|
|
221
|
+
setNote("");
|
|
222
|
+
versions.refetch?.();
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
setSaid(error.message ?? "Not published.");
|
|
226
|
+
}
|
|
227
|
+
}, children: "Publish" })] })) : (_jsx("p", { className: "text-sm text-muted-foreground", children: "A person who may publish programs publishes this working copy." })), said ? (_jsx("p", { "aria-live": "polite", className: "text-sm", "data-testid": "publish-said", children: said })) : null, _jsxs("ul", { className: "grid gap-1 text-sm", "aria-label": "Published versions", children: [(versions.data?.items ?? []).map((v) => (_jsxs("li", { className: "flex items-center gap-2", children: [_jsxs("span", { children: ["Version ", v.version, v.current ? " (what people are given)" : "", " \u00B7", " ", new Date(v.publishedAt).toLocaleDateString(), v.note ? ` · ${v.note}` : ""] }), _jsx(Button, { size: "xs", variant: "ghost", disabled: restore.isPending, onClick: async () => {
|
|
228
|
+
const out = await restore.mutateAsync({
|
|
229
|
+
object: "programs.program",
|
|
230
|
+
id: programId,
|
|
231
|
+
version: v.version,
|
|
232
|
+
});
|
|
233
|
+
onRestored(out.record.values.layout, String(out.record.values.title ?? ""));
|
|
234
|
+
setSaid(`Version ${v.version} restored into the working copy. Publish to give it to people.`);
|
|
235
|
+
}, children: "Restore" })] }, v.version))), versions.data && !versions.data.items.length ? _jsx("li", { children: "Not published yet." }) : null] })] })] }));
|
|
236
|
+
}
|
|
237
|
+
function Assign({ programs, programId, }) {
|
|
238
|
+
const [search, setSearch] = useState("");
|
|
239
|
+
const [person, setPerson] = useState(null);
|
|
240
|
+
const [classType, setClassType] = useState("");
|
|
241
|
+
const [startDate, setStartDate] = useState("");
|
|
242
|
+
const [said, setSaid] = useState(null);
|
|
243
|
+
const people = programs.usePeople(search);
|
|
244
|
+
const classTypes = programs.useClassTypes();
|
|
245
|
+
const assign = programs.useAssign();
|
|
246
|
+
return (_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: "Assign" }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm", children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "assign-person", children: "A client" }), _jsx(Input, { id: "assign-person", placeholder: "Search people", value: person ? person.name : search, onChange: (e) => {
|
|
247
|
+
setPerson(null);
|
|
248
|
+
setSearch(e.target.value);
|
|
249
|
+
} }), !person && people.data?.items.length ? (_jsx("ul", { className: "flex flex-wrap gap-1", children: people.data.items.map((p) => (_jsx("li", { children: _jsx(Button, { size: "xs", variant: "secondary", onClick: () => {
|
|
250
|
+
setPerson({ id: p.id, name: p.displayName ?? p.id });
|
|
251
|
+
setClassType("");
|
|
252
|
+
}, children: p.displayName ?? p.id }) }, p.id))) })) : null] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "assign-class", children: "Or a class type" }), _jsxs("select", { id: "assign-class", className: "h-9 rounded-md border px-2", value: classType, onChange: (e) => {
|
|
253
|
+
setClassType(e.target.value);
|
|
254
|
+
setPerson(null);
|
|
255
|
+
}, children: [_jsx("option", { value: "", children: "None" }), (classTypes.data?.items ?? []).map((c) => (_jsx("option", { value: c.id, children: String(c.values.name ?? c.id) }, c.id)))] })] }), _jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "assign-start", children: "Starts" }), _jsx(Input, { id: "assign-start", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), _jsx(Button, { disabled: assign.isPending || !startDate || (!person && !classType), onClick: async () => {
|
|
256
|
+
try {
|
|
257
|
+
const out = await assign.mutateAsync({
|
|
258
|
+
programId,
|
|
259
|
+
startDate,
|
|
260
|
+
...(person ? { personId: person.id } : { classTypeId: classType }),
|
|
261
|
+
});
|
|
262
|
+
setSaid(`Assigned version ${out.programVersion}: ${out.sessions} sessions from ${out.startDate} to ${out.endDate}.`);
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
setSaid(error.message ?? "Not assigned.");
|
|
266
|
+
}
|
|
267
|
+
}, children: "Assign the published version" }), said ? (_jsx("p", { "aria-live": "polite", "data-testid": "assign-said", children: said })) : null] })] }));
|
|
268
|
+
}
|
|
269
|
+
/** A list of programs with a button to open one, and to start one blank, drafted or imported. */
|
|
270
|
+
export function ProgramList({ programs, onOpen, }) {
|
|
271
|
+
const list = programs.usePrograms();
|
|
272
|
+
const create = programs.useCreateProgram();
|
|
273
|
+
const draft = programs.useDraft();
|
|
274
|
+
const importText = programs.useImportText();
|
|
275
|
+
const [title, setTitle] = useState("");
|
|
276
|
+
const [brief, setBrief] = useState("");
|
|
277
|
+
const [text, setText] = useState("");
|
|
278
|
+
const [unread, setUnread] = useState([]);
|
|
279
|
+
return (_jsxs("div", { className: "grid gap-4", children: [_jsx("ul", { className: "grid gap-2", "aria-label": "Programs", children: (list.data?.items ?? []).map((p) => (_jsxs("li", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "link", onClick: () => onOpen(p.id), children: String(p.values.title ?? p.id) }), _jsx("span", { className: "text-xs text-muted-foreground", children: p.values.publishedVersion ? `version ${p.values.publishedVersion}` : "not published" })] }, p.id))) }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Input, { "aria-label": "New program title", placeholder: "New program title", value: title, onChange: (e) => setTitle(e.target.value), className: "max-w-xs" }), _jsx(Button, { disabled: !title.trim() || create.isPending, onClick: async () => {
|
|
280
|
+
const out = await create.mutateAsync({
|
|
281
|
+
object: "programs.program",
|
|
282
|
+
values: {
|
|
283
|
+
title: title.trim(),
|
|
284
|
+
kind: "client",
|
|
285
|
+
layout: { weeks: [{ sessions: [] }] },
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
setTitle("");
|
|
289
|
+
onOpen(out.id);
|
|
290
|
+
}, 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
|
+
const out = await importText.mutateAsync({ text });
|
|
292
|
+
setUnread(out.unread);
|
|
293
|
+
onOpen(out.programId);
|
|
294
|
+
}, 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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function ClassToday({ programs, classTypeId, date, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useClassToday" | "useClassTypes" | "useLogSet" | "useMarkSession" | "useSession" | "useUpdateSet">;
|
|
4
|
+
classTypeId?: string;
|
|
5
|
+
date?: string;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { SessionView } from "../programs-session/session-view.js";
|
|
4
|
+
import { Input } from "../ui-input/input.js";
|
|
5
|
+
export function ClassToday({ programs, classTypeId, date, }) {
|
|
6
|
+
const types = programs.useClassTypes();
|
|
7
|
+
const [chosen, setChosen] = useState(classTypeId ?? "");
|
|
8
|
+
const [day, setDay] = useState(date ?? "");
|
|
9
|
+
const id = chosen || String(types.data?.items[0]?.id ?? "");
|
|
10
|
+
const classes = programs.useClassToday({
|
|
11
|
+
classTypeId: id || "none",
|
|
12
|
+
...(day ? { date: day } : {}),
|
|
13
|
+
});
|
|
14
|
+
return (_jsxs("div", { className: "grid gap-4", "data-testid": "class-today", children: [_jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx("select", { "aria-label": "Class", className: "h-9 rounded-md border px-2", value: id, onChange: (e) => setChosen(e.target.value), children: (types.data?.items ?? []).map((t) => (_jsx("option", { value: t.id, children: String(t.values.name ?? t.id) }, t.id))) }), _jsx(Input, { "aria-label": "Date", type: "date", value: day || classes.data?.date || "", onChange: (e) => setDay(e.target.value), className: "w-44" })] }), classes.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading the class\u2026" }) : null, classes.data && !classes.data.sessions.length ? _jsx("p", { children: "No class session on this day." }) : null, (classes.data?.sessions ?? []).map((s) => (_jsx(SessionView, { programs: programs, sessionId: s.id }, s.id)))] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function CoachClient({ programs, personId, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useClientSessions" | "useHistory" | "useLogSet" | "useMarkSession" | "useProgress" | "useSession" | "useUpdateSet">;
|
|
4
|
+
personId: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Progress } from "../programs-progress/progress.js";
|
|
4
|
+
import { SessionView } from "../programs-session/session-view.js";
|
|
5
|
+
import { Button } from "../ui-button/button.js";
|
|
6
|
+
export function CoachClient({ programs, personId, }) {
|
|
7
|
+
const sessions = programs.useClientSessions(personId);
|
|
8
|
+
const [open, setOpen] = useState(null);
|
|
9
|
+
return (_jsxs("div", { className: "grid gap-4", "data-testid": "coach-client", children: [_jsxs("section", { "aria-label": "Sessions", className: "grid gap-2", children: [sessions.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading sessions\u2026" }) : null, (sessions.data?.items ?? []).map((s) => (_jsxs("div", { className: "grid gap-2", children: [_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsxs(Button, { size: "sm", variant: open === s.id ? "default" : "outline", onClick: () => setOpen(open === s.id ? null : s.id), children: [String(s.values.date ?? ""), " \u00B7 ", String(s.values.name ?? "")] }), _jsx("span", { className: "text-muted-foreground", children: String(s.values.state ?? "") })] }), open === s.id ? (_jsx(SessionView, { programs: programs, sessionId: s.id, personId: personId })) : null] }, s.id))), sessions.data && !sessions.data.items.length ? (_jsx("p", { children: "No sessions yet: assign a program." })) : null] }), _jsx(Progress, { programs: programs, personId: personId })] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PlannedSession, ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function ClassTodayScreen({ programs, date, onOpen, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useClassToday" | "useClassTypes">;
|
|
4
|
+
date?: string;
|
|
5
|
+
onOpen: (session: PlannedSession) => void;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Text, View } from "react-native";
|
|
4
|
+
import { Button } from "../native-base/button.js";
|
|
5
|
+
import { List } from "../native-base/list.js";
|
|
6
|
+
import { Row } from "../native-base/row.js";
|
|
7
|
+
import { Screen } from "../native-base/screen.js";
|
|
8
|
+
export function ClassTodayScreen({ programs, date, onOpen, }) {
|
|
9
|
+
const types = programs.useClassTypes();
|
|
10
|
+
const [chosen, setChosen] = useState(null);
|
|
11
|
+
const id = chosen ?? types.data?.items[0]?.id ?? "none";
|
|
12
|
+
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function CoachClientScreen({ programs, personId, name, onOpen, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useClientSessions">;
|
|
4
|
+
personId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
onOpen: (sessionId: string) => void;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import { List } from "../native-base/list.js";
|
|
4
|
+
import { Row } from "../native-base/row.js";
|
|
5
|
+
import { Screen } from "../native-base/screen.js";
|
|
6
|
+
export function CoachClientScreen({ programs, personId, name, onOpen, }) {
|
|
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] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
import { List } from "../native-base/list.js";
|
|
5
|
+
import { Row } from "../native-base/row.js";
|
|
6
|
+
import { Screen } from "../native-base/screen.js";
|
|
7
|
+
const best = (b) => [
|
|
8
|
+
b.load !== null ? `${b.load} kg` : null,
|
|
9
|
+
b.reps !== null ? `${b.reps} reps` : null,
|
|
10
|
+
b.seconds !== null ? `${b.seconds} s` : null,
|
|
11
|
+
]
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.join(" · ");
|
|
14
|
+
export function ProgressScreen({ programs, personId, }) {
|
|
15
|
+
const progress = programs.useProgress(personId ? { personId } : {});
|
|
16
|
+
const [exercise, setExercise] = useState(null);
|
|
17
|
+
const history = programs.useHistory({
|
|
18
|
+
exerciseId: exercise ?? "none",
|
|
19
|
+
...(personId ? { personId } : {}),
|
|
20
|
+
});
|
|
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: [
|
|
24
|
+
s.actual.reps,
|
|
25
|
+
s.actual.seconds !== null ? `${s.actual.seconds}s` : null,
|
|
26
|
+
s.actual.load !== null ? `${s.actual.load}kg` : null,
|
|
27
|
+
s.rpe !== null ? `RPE ${s.rpe}` : null,
|
|
28
|
+
]
|
|
29
|
+
.filter((x) => x !== null)
|
|
30
|
+
.join(" ") }, s.id))) })) : null] }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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">;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
personId?: string;
|
|
6
|
+
onRestDone?: () => void;
|
|
7
|
+
}): import("react").JSX.Element;
|