@composable-os/pack-programs 0.0.0-stage → 0.1.0-beta.11
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 +1723 -0
- package/dist/client/index.js +779 -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 +610 -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,130 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// One session to do, for the mobile app (stage 41): targets, last time's numbers, a row per set
|
|
3
|
+
// to log what was done and how hard it felt, a rest timer, and marking it done. A member's own
|
|
4
|
+
// session, a class's (choose the level you take), or a coach logging for a client (`personId`).
|
|
5
|
+
// The app gives the buzz at the end of a rest (`onRestDone`, for example `expo-haptics`), so this
|
|
6
|
+
// block needs no device package. It holds no rules: targets, whose session it is and what may be
|
|
7
|
+
// logged are the host's.
|
|
8
|
+
import { describeSet, describeSets, levelExercises, levelLabel, loggedFor, numberFrom, } from "@composable-os/pack-programs/client";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
11
|
+
import { Button } from "../native-base/button.js";
|
|
12
|
+
import { Field } from "../native-base/field.js";
|
|
13
|
+
import { Screen } from "../native-base/screen.js";
|
|
14
|
+
import { theme } from "../native-base/theme.js";
|
|
15
|
+
export function SessionScreen({ programs, sessionId, personId, onRestDone, }) {
|
|
16
|
+
const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
|
|
17
|
+
const mark = programs.useMarkSession();
|
|
18
|
+
const [rest, setRest] = useState(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (rest === null)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (rest <= 0) {
|
|
23
|
+
setRest(null);
|
|
24
|
+
onRestDone?.();
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const timer = setTimeout(() => setRest((s) => (s === null ? null : s - 1)), 1000);
|
|
28
|
+
return () => clearTimeout(timer);
|
|
29
|
+
}, [rest, onRestDone]);
|
|
30
|
+
if (detail.isPending)
|
|
31
|
+
return (_jsx(Screen, { title: "Session", children: _jsx(Text, { children: "Loading\u2026" }) }));
|
|
32
|
+
if (!detail.data)
|
|
33
|
+
return (_jsx(Screen, { title: "Session", children: _jsx(Text, { children: "We could not load this session." }) }));
|
|
34
|
+
const { session, exercises, logged } = detail.data;
|
|
35
|
+
const plan = session.plan;
|
|
36
|
+
const names = new Map(exercises.map((e) => [e.id, e]));
|
|
37
|
+
return (_jsxs(Screen, { title: session.name ?? "Session", children: [_jsx(Text, { style: styles.muted, children: [session.programTitle, session.classTypeName, session.date].filter(Boolean).join(" · ") }), rest !== null ? (_jsxs(View, { style: styles.timer, accessibilityRole: "timer", accessibilityLiveRegion: "polite", children: [_jsxs(Text, { style: styles.timerText, children: [rest, "s rest"] }), _jsx(Button, { quiet: true, label: "Skip", onPress: () => setRest(null) })] })) : null, plan?.warmup?.text ? _jsx(Text, { children: plan.warmup.text }) : null, (plan?.blocks ?? []).map((block) => (_jsxs(View, { style: styles.block, children: [_jsxs(Text, { style: styles.heading, children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), block.items.map((item) => (_jsx(NativeItem, { programs: programs, sessionId: sessionId, personId: personId, item: item, names: names, logged: logged, onLogged: (t) => {
|
|
38
|
+
detail.refetch?.();
|
|
39
|
+
if (t?.rest)
|
|
40
|
+
setRest(t.rest);
|
|
41
|
+
} }, item.label)))] }, block.label))), session.kind === "personal" ? (_jsx(Button, { label: session.state === "done" ? "Done" : "Mark done", busy: mark.isPending, disabled: session.state === "done", onPress: async () => {
|
|
42
|
+
await mark.mutateAsync({ sessionId, state: "done" });
|
|
43
|
+
detail.refetch?.();
|
|
44
|
+
} })) : null] }));
|
|
45
|
+
}
|
|
46
|
+
function NativeItem({ programs, sessionId, personId, item, names, logged, onLogged, }) {
|
|
47
|
+
const taken = logged.find((l) => l.item === item.label)?.level ?? null;
|
|
48
|
+
const [chosen, setChosen] = useState(taken);
|
|
49
|
+
const levels = item.kind === "levels" ? item.levels : [];
|
|
50
|
+
const level = levels.find((l) => l.level === chosen) ?? (levels.length === 1 ? levels[0] : undefined);
|
|
51
|
+
const list = item.kind === "all" ? item.exercises : level ? levelExercises(level) : [];
|
|
52
|
+
return (_jsxs(View, { style: styles.item, children: [_jsx(Text, { style: styles.heading, children: item.label }), (item.notes ?? []).map((n) => (_jsx(Text, { style: styles.muted, children: n.text }, n.text))), levels.length > 1 ? (_jsx(View, { style: styles.row, children: levels.map((l) => (_jsx(Button, { quiet: l.level !== level?.level, label: levelLabel(l), onPress: () => setChosen(l.level) }, l.level))) })) : null, list.map((p) => {
|
|
53
|
+
const e = names.get(p.exercise);
|
|
54
|
+
return (_jsxs(View, { style: styles.exercise, children: [_jsx(Text, { style: styles.name, children: e?.name ?? "Exercise" }), _jsx(Text, { style: styles.muted, children: describeSets(p.sets) }), p.note ? _jsx(Text, { children: p.note }) : null, e?.last.length ? (_jsxs(Text, { style: styles.muted, children: ["Last time:", " ", e.last
|
|
55
|
+
.map((s) => [
|
|
56
|
+
s.reps,
|
|
57
|
+
s.seconds !== null ? `${s.seconds}s` : null,
|
|
58
|
+
s.load !== null ? `${s.load}kg` : null,
|
|
59
|
+
]
|
|
60
|
+
.filter((x) => x !== null)
|
|
61
|
+
.join(" "))
|
|
62
|
+
.join(", ")] })) : null, p.sets.map((set, i) => (_jsx(NativeSet
|
|
63
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: sets are positions.
|
|
64
|
+
, { programs: programs, sessionId: sessionId, personId: personId, itemLabel: item.label, level: item.kind === "levels" ? level?.level : undefined, exerciseId: p.exercise, setNumber: i + 1, target: set, done: loggedFor(logged, item.label, p.exercise, i + 1), onLogged: onLogged }, i)))] }, p.exercise));
|
|
65
|
+
})] }));
|
|
66
|
+
}
|
|
67
|
+
function NativeSet({ programs, sessionId, personId, itemLabel, level, exerciseId, setNumber, target, done, onLogged, }) {
|
|
68
|
+
const add = programs.useLogSet();
|
|
69
|
+
const update = programs.useUpdateSet();
|
|
70
|
+
const timed = target.kind !== "reps";
|
|
71
|
+
const [count, setCount] = useState(String((timed ? done?.actual.seconds : done?.actual.reps) ?? (timed ? target.seconds : target.reps)));
|
|
72
|
+
const [load, setLoad] = useState(String(done?.actual.load ?? target.load ?? ""));
|
|
73
|
+
const [effort, setEffort] = useState(String(done?.rpe ?? ""));
|
|
74
|
+
const [error, setError] = useState(null);
|
|
75
|
+
const actual = {
|
|
76
|
+
...(timed ? { seconds: numberFrom(count) } : { reps: numberFrom(count) }),
|
|
77
|
+
...(numberFrom(load) !== undefined ? { load: numberFrom(load) } : {}),
|
|
78
|
+
};
|
|
79
|
+
const rpe = numberFrom(effort);
|
|
80
|
+
return (_jsxs(View, { style: styles.set, children: [_jsxs(Text, { children: ["Set ", setNumber, ": ", describeSet(target), " ", done ? "✓" : ""] }), _jsxs(View, { style: styles.row, children: [_jsx(Field, { label: timed ? "Seconds" : "Reps", keyboardType: "numeric", value: count, onChangeText: setCount }), _jsx(Field, { label: "kg", keyboardType: "decimal-pad", value: load, onChangeText: setLoad }), _jsx(Field, { label: "RPE", keyboardType: "decimal-pad", value: effort, onChangeText: setEffort, error: error })] }), _jsx(Button, { label: done ? "Update" : "Log set", quiet: Boolean(done), busy: add.isPending || update.isPending, onPress: async () => {
|
|
81
|
+
setError(null);
|
|
82
|
+
try {
|
|
83
|
+
if (done)
|
|
84
|
+
await update.mutateAsync({
|
|
85
|
+
logId: done.id,
|
|
86
|
+
actual,
|
|
87
|
+
...(rpe !== undefined ? { rpe } : {}),
|
|
88
|
+
});
|
|
89
|
+
else
|
|
90
|
+
await add.mutateAsync({
|
|
91
|
+
sessionId,
|
|
92
|
+
item: itemLabel,
|
|
93
|
+
exerciseId,
|
|
94
|
+
...(level !== undefined ? { level } : {}),
|
|
95
|
+
setNumber,
|
|
96
|
+
actual,
|
|
97
|
+
...(rpe !== undefined ? { rpe } : {}),
|
|
98
|
+
...(personId ? { personId } : {}),
|
|
99
|
+
});
|
|
100
|
+
onLogged(target);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
setError(e.message ?? "Not logged");
|
|
104
|
+
}
|
|
105
|
+
} })] }));
|
|
106
|
+
}
|
|
107
|
+
const styles = StyleSheet.create({
|
|
108
|
+
muted: { color: theme.color.muted, fontSize: theme.font.small },
|
|
109
|
+
heading: { fontSize: theme.font.body, fontWeight: "600", color: theme.color.text },
|
|
110
|
+
name: { fontSize: theme.font.body, fontWeight: "600" },
|
|
111
|
+
block: { gap: theme.space.sm, marginTop: theme.space.md },
|
|
112
|
+
item: {
|
|
113
|
+
gap: theme.space.sm,
|
|
114
|
+
padding: theme.space.sm,
|
|
115
|
+
backgroundColor: theme.color.surface,
|
|
116
|
+
borderRadius: theme.radius,
|
|
117
|
+
},
|
|
118
|
+
exercise: { gap: theme.space.xs },
|
|
119
|
+
set: { gap: theme.space.xs, paddingVertical: theme.space.xs },
|
|
120
|
+
row: { flexDirection: "row", flexWrap: "wrap", gap: theme.space.sm },
|
|
121
|
+
timer: {
|
|
122
|
+
flexDirection: "row",
|
|
123
|
+
alignItems: "center",
|
|
124
|
+
gap: theme.space.md,
|
|
125
|
+
padding: theme.space.md,
|
|
126
|
+
backgroundColor: theme.color.surface,
|
|
127
|
+
borderRadius: theme.radius,
|
|
128
|
+
},
|
|
129
|
+
timerText: { fontSize: theme.font.title, fontWeight: "700" },
|
|
130
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PlannedSession, ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function TodayScreen({ programs, date, onOpen, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useToday">;
|
|
4
|
+
/** The member's local date (YYYY-MM-DD). */
|
|
5
|
+
date?: string;
|
|
6
|
+
onOpen: (session: PlannedSession) => void;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 TodayScreen({ programs, date, onOpen, }) {
|
|
7
|
+
const today = programs.useToday(date ? { date } : {});
|
|
8
|
+
return (_jsxs(Screen, { title: "Today", children: [today.isPending ? _jsx(Text, { children: "Loading\u2026" }) : null, today.data ? (_jsx(List, { empty: "Nothing planned today.", children: today.data.sessions.map((s) => (_jsx(Row, { title: s.name ?? "Session", detail: [s.programTitle, s.state === "done" ? "Done" : null]
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.join(" · "), onPress: () => onOpen(s) }, s.id))) })) : null] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function Progress({ programs, personId, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useHistory" | "useProgress">;
|
|
4
|
+
personId?: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
export declare function History({ programs, exerciseId, personId, }: {
|
|
7
|
+
programs: Pick<ProgramsHooks, "useHistory" | "useProgress">;
|
|
8
|
+
exerciseId: string;
|
|
9
|
+
personId?: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
const best = (b) => [
|
|
6
|
+
b.load !== null ? `${b.load} kg` : null,
|
|
7
|
+
b.reps !== null ? `${b.reps} reps` : null,
|
|
8
|
+
b.seconds !== null ? `${b.seconds} s` : null,
|
|
9
|
+
]
|
|
10
|
+
.filter(Boolean)
|
|
11
|
+
.join(" · ") || "—";
|
|
12
|
+
export function Progress({ programs, personId, }) {
|
|
13
|
+
const progress = programs.useProgress(personId ? { personId } : {});
|
|
14
|
+
const [exercise, setExercise] = useState(null);
|
|
15
|
+
if (progress.isPending)
|
|
16
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading progress\u2026" });
|
|
17
|
+
if (progress.error || !progress.data)
|
|
18
|
+
return _jsx("p", { role: "alert", children: "We could not load progress." });
|
|
19
|
+
return (_jsxs("div", { className: "grid gap-4", "data-testid": "progress", children: [_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: "Programs" }) }), _jsx(CardContent, { children: _jsxs("ul", { className: "grid gap-1 text-sm", children: [progress.data.assignments.map((a) => (_jsxs("li", { children: [a.title, ": ", a.done, " done, ", a.skipped, " skipped, ", a.planned, " to come, of ", a.sessions] }, a.id))), !progress.data.assignments.length ? _jsx("li", { children: "No program yet." }) : null] }) })] }), _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: "Exercises" }) }), _jsxs(CardContent, { children: [_jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { className: "text-left text-xs text-muted-foreground", children: _jsxs("tr", { children: [_jsx("th", { children: "Exercise" }), _jsx("th", { children: "Sets" }), _jsx("th", { children: "Since" }), _jsx("th", { children: "Best" }), _jsx("th", {})] }) }), _jsx("tbody", { children: progress.data.exercises.map((e) => (_jsxs("tr", { children: [_jsx("td", { children: e.name }), _jsx("td", { children: e.sets }), _jsx("td", { children: e.first }), _jsx("td", { children: best(e.best) }), _jsx("td", { children: _jsx(Button, { size: "xs", variant: "ghost", onClick: () => setExercise(exercise === e.id ? null : e.id), children: "History" }) })] }, e.id))) })] }), progress.data.capped ? (_jsx("p", { className: "text-xs", children: "Worked out over the latest sets only." })) : null] })] }), exercise ? (_jsx(History, { programs: programs, exerciseId: exercise, ...(personId ? { personId } : {}) })) : null] }));
|
|
20
|
+
}
|
|
21
|
+
export function History({ programs, exerciseId, personId, }) {
|
|
22
|
+
const history = programs.useHistory({ exerciseId, ...(personId ? { personId } : {}) });
|
|
23
|
+
if (history.isPending)
|
|
24
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading history\u2026" });
|
|
25
|
+
if (!history.data)
|
|
26
|
+
return _jsx("p", { role: "alert", children: "We could not load this exercise's history." });
|
|
27
|
+
return (_jsxs(Card, { "data-testid": "history", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: history.data.exercise.name }) }), _jsxs(CardContent, { className: "grid gap-2 text-sm", children: [_jsxs("p", { children: ["Best: ", best(history.data.best)] }), _jsxs("table", { className: "w-full", children: [_jsx("thead", { className: "text-left text-xs text-muted-foreground", children: _jsxs("tr", { children: [_jsx("th", { children: "Date" }), _jsx("th", { children: "Set" }), _jsx("th", { children: "Level" }), _jsx("th", { children: "Target" }), _jsx("th", { children: "Done" }), _jsx("th", { children: "RPE" })] }) }), _jsx("tbody", { children: history.data.sets.map((s) => (_jsxs("tr", { children: [_jsx("td", { children: s.date }), _jsx("td", { children: s.setNumber }), _jsx("td", { children: s.level ?? "" }), _jsx("td", { children: [
|
|
28
|
+
s.target.reps,
|
|
29
|
+
s.target.seconds !== null ? `${s.target.seconds}s` : null,
|
|
30
|
+
s.target.load !== null ? `${s.target.load}kg` : null,
|
|
31
|
+
]
|
|
32
|
+
.filter((v) => v !== null)
|
|
33
|
+
.join(" ") }), _jsx("td", { children: [
|
|
34
|
+
s.actual.reps,
|
|
35
|
+
s.actual.seconds !== null ? `${s.actual.seconds}s` : null,
|
|
36
|
+
s.actual.load !== null ? `${s.actual.load}kg` : null,
|
|
37
|
+
]
|
|
38
|
+
.filter((v) => v !== null)
|
|
39
|
+
.join(" ") }), _jsx("td", { children: s.rpe ?? "" })] }, s.id))) })] })] })] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function SessionView({ programs, sessionId, personId, onRestDone, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useLogSet" | "useMarkSession" | "useSession" | "useUpdateSet">;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
/** A coach logging for a client names them on a class session. */
|
|
6
|
+
personId?: string;
|
|
7
|
+
/** Called when a rest ends (a sound, a buzz): the app's. */
|
|
8
|
+
onRestDone?: () => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// One session to do (stage 41): its plan with every target, last time's numbers at each exercise,
|
|
3
|
+
// a row per set to log what was done and how hard it felt, a rest timer after each set, and
|
|
4
|
+
// marking the session done. For a member (their own, or a class's: they choose the level they
|
|
5
|
+
// take) and for a coach logging for a client (`personId`). Built on the web base layer.
|
|
6
|
+
//
|
|
7
|
+
// It holds no rules: the targets, the last numbers and whose session it is come from the host
|
|
8
|
+
// (`useSession`); a set is logged by the host, which takes its target from the plan and refuses a
|
|
9
|
+
// session the caller may not log on; effort's bounds are the host's too.
|
|
10
|
+
import { describeSet, describeSets, levelExercises, levelLabel, loggedFor, numberFrom, } from "@composable-os/pack-programs/client";
|
|
11
|
+
import { useEffect, 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 SessionView({ programs, sessionId, personId, onRestDone, }) {
|
|
16
|
+
const detail = programs.useSession({ sessionId, ...(personId ? { personId } : {}) });
|
|
17
|
+
const mark = programs.useMarkSession();
|
|
18
|
+
const [rest, setRest] = useState(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (rest === null)
|
|
21
|
+
return undefined;
|
|
22
|
+
if (rest <= 0) {
|
|
23
|
+
setRest(null);
|
|
24
|
+
onRestDone?.();
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const timer = setTimeout(() => setRest((s) => (s === null ? null : s - 1)), 1000);
|
|
28
|
+
return () => clearTimeout(timer);
|
|
29
|
+
}, [rest, onRestDone]);
|
|
30
|
+
if (detail.isPending)
|
|
31
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the session\u2026" });
|
|
32
|
+
if (detail.error || !detail.data)
|
|
33
|
+
return _jsx("p", { role: "alert", children: "We could not load this session." });
|
|
34
|
+
const { session, exercises, logged } = detail.data;
|
|
35
|
+
const plan = session.plan;
|
|
36
|
+
const byId = new Map(exercises.map((e) => [e.id, e]));
|
|
37
|
+
const refresh = () => detail.refetch?.();
|
|
38
|
+
return (_jsxs(Card, { "data-testid": "session-view", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: session.name }), _jsx(CardDescription, { children: [session.programTitle, session.classTypeName, session.date, session.focus]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(" · ") })] }), _jsxs(CardContent, { className: "grid gap-5", children: [rest !== null ? (_jsxs("div", { role: "timer", "aria-live": "polite", className: "flex items-center gap-3 rounded-md bg-muted p-3", children: [_jsxs("strong", { className: "text-2xl tabular-nums", children: [rest, "s"] }), " rest", _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setRest(null), children: "Skip" })] })) : null, plan?.warmup?.text || plan?.warmup?.exercises?.length ? (_jsxs("section", { "aria-label": "Warm-up", className: "grid gap-1 text-sm", children: [_jsx("h3", { className: "font-semibold", children: "Warm-up" }), plan.warmup.text ? _jsx("p", { className: "whitespace-pre-wrap", children: plan.warmup.text }) : null, _jsx("ul", { children: (plan.warmup.exercises ?? []).map((p, i) => (_jsxs("li", { children: [byId.get(p.exercise)?.name ?? "Exercise", ": ", describeSets(p.sets)] }, i))) })] })) : null, (plan?.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), (plan?.blocks ?? []).map((block) => (_jsxs("section", { "aria-label": `Block ${block.label}`, className: "grid gap-3", children: [_jsxs("h3", { className: "font-semibold", children: ["Block ", block.label, block.rounds ? ` · ${block.rounds} rounds` : ""] }), (block.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), block.items.map((item) => (_jsx(ItemToDo, { programs: programs, sessionId: sessionId, personId: personId, item: item, exercises: byId, logged: logged, onLogged: (target) => {
|
|
41
|
+
refresh();
|
|
42
|
+
if (target?.rest)
|
|
43
|
+
setRest(target.rest);
|
|
44
|
+
} }, item.label)))] }, block.label))), session.kind === "personal" ? (_jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { disabled: mark.isPending || session.state === "done", onClick: async () => {
|
|
45
|
+
await mark.mutateAsync({ sessionId, state: "done" });
|
|
46
|
+
refresh();
|
|
47
|
+
}, children: session.state === "done" ? "Done" : "Mark done" }), session.state !== "done" ? (_jsx(Button, { variant: "ghost", disabled: mark.isPending, onClick: async () => {
|
|
48
|
+
await mark.mutateAsync({ sessionId, state: "skipped" });
|
|
49
|
+
refresh();
|
|
50
|
+
}, children: "Skip this session" })) : null] })) : null] })] }));
|
|
51
|
+
}
|
|
52
|
+
function ItemToDo({ programs, sessionId, personId, item, exercises, logged, onLogged, }) {
|
|
53
|
+
const taken = logged.find((l) => l.item === item.label)?.level ?? null;
|
|
54
|
+
const [chosen, setChosen] = useState(taken);
|
|
55
|
+
const levels = item.kind === "levels" ? item.levels : [];
|
|
56
|
+
const level = levels.find((l) => l.level === chosen) ?? (levels.length === 1 ? levels[0] : undefined);
|
|
57
|
+
const prescriptions = item.kind === "all" ? item.exercises : level ? levelExercises(level) : [];
|
|
58
|
+
return (_jsxs("div", { className: "grid gap-2 rounded-md border p-3", "data-testid": "item-to-do", "data-item": item.label, children: [_jsx("div", { className: "font-medium", children: item.label }), (item.notes ?? []).map((n) => (_jsx("p", { className: "text-sm italic", children: n.text }, n.text))), levels.length > 1 ? (_jsx("fieldset", { className: "flex flex-wrap gap-1", "aria-label": "The level you take", children: levels.map((l) => (_jsx(Button, { size: "sm", variant: l.level === level?.level ? "default" : "outline", "aria-pressed": l.level === level?.level, onClick: () => setChosen(l.level), children: levelLabel(l) }, l.level))) })) : null, level?.mode === "alternatives" ? (_jsx("p", { className: "text-xs text-muted-foreground", children: "Do one of these." })) : null, prescriptions.map((p) => (_jsx(ExerciseToDo, { programs: programs, sessionId: sessionId, personId: personId, itemLabel: item.label, level: item.kind === "levels" ? level?.level : undefined, prescription: p, exercise: exercises.get(p.exercise), logged: logged, onLogged: onLogged }, p.exercise))), item.kind === "levels" && !level ? (_jsx("p", { className: "text-sm", children: "Choose the level you take to log it." })) : null] }));
|
|
59
|
+
}
|
|
60
|
+
function ExerciseToDo({ programs, sessionId, personId, itemLabel, level, prescription, exercise, logged, onLogged, }) {
|
|
61
|
+
const last = exercise?.last ?? [];
|
|
62
|
+
return (_jsxs("div", { className: "grid gap-2", "data-testid": "exercise-to-do", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-2", children: [_jsx("strong", { children: exercise?.name ?? "Exercise" }), _jsx("span", { className: "text-sm text-muted-foreground", children: describeSets(prescription.sets) }), exercise?.video ? (_jsx("a", { href: exercise.video, target: "_blank", rel: "noreferrer", className: "text-sm underline", children: "Demo" })) : null] }), prescription.note ? _jsx("p", { className: "text-sm", children: prescription.note }) : null, exercise?.cues ? _jsx("p", { className: "text-xs text-muted-foreground", children: exercise.cues }) : null, last.length ? (_jsxs("p", { className: "text-xs text-muted-foreground", "data-testid": "last-time", children: ["Last time (", last[0]?.date, "):", " ", last
|
|
63
|
+
.map((s) => [
|
|
64
|
+
s.reps !== null ? `${s.reps} reps` : null,
|
|
65
|
+
s.seconds !== null ? `${s.seconds} s` : null,
|
|
66
|
+
s.load !== null ? `${s.load} kg` : null,
|
|
67
|
+
]
|
|
68
|
+
.filter(Boolean)
|
|
69
|
+
.join(" "))
|
|
70
|
+
.join(", ")] })) : null, _jsx("ol", { className: "grid gap-1", children: prescription.sets.map((set, i) => (_jsx(SetRow
|
|
71
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: sets are positions.
|
|
72
|
+
, { programs: programs, sessionId: sessionId, personId: personId, itemLabel: itemLabel, level: level, exerciseId: prescription.exercise, setNumber: i + 1, target: set, done: loggedFor(logged, itemLabel, prescription.exercise, i + 1), onLogged: onLogged }, i))) })] }));
|
|
73
|
+
}
|
|
74
|
+
function SetRow({ programs, sessionId, personId, itemLabel, level, exerciseId, setNumber, target, done, onLogged, }) {
|
|
75
|
+
const add = programs.useLogSet();
|
|
76
|
+
const update = programs.useUpdateSet();
|
|
77
|
+
const timed = target.kind !== "reps";
|
|
78
|
+
const [count, setCount] = useState(String((timed ? done?.actual.seconds : done?.actual.reps) ?? (timed ? target.seconds : target.reps)));
|
|
79
|
+
const [load, setLoad] = useState(String(done?.actual.load ?? target.load ?? ""));
|
|
80
|
+
const [effort, setEffort] = useState(String(done?.rpe ?? ""));
|
|
81
|
+
const [error, setError] = useState(null);
|
|
82
|
+
const busy = add.isPending || update.isPending;
|
|
83
|
+
const actual = {
|
|
84
|
+
...(timed ? { seconds: numberFrom(count) } : { reps: numberFrom(count) }),
|
|
85
|
+
...(numberFrom(load) !== undefined ? { load: numberFrom(load) } : {}),
|
|
86
|
+
};
|
|
87
|
+
const rpe = numberFrom(effort);
|
|
88
|
+
return (_jsxs("li", { className: "flex flex-wrap items-center gap-2 text-sm", "data-testid": "set-row", "data-done": Boolean(done), children: [_jsxs("span", { className: "w-12", children: ["Set ", setNumber] }), _jsx("span", { className: "w-40 text-muted-foreground", children: describeSet(target) }), _jsx(Input, { "aria-label": `Set ${setNumber} ${timed ? "seconds" : "reps"} done`, className: "h-8 w-16", inputMode: "numeric", value: count, onChange: (e) => setCount(e.target.value) }), _jsx(Input, { "aria-label": `Set ${setNumber} load`, placeholder: "kg", className: "h-8 w-16", inputMode: "decimal", value: load, onChange: (e) => setLoad(e.target.value) }), _jsx(Input, { "aria-label": `Set ${setNumber} effort`, placeholder: "RPE", className: "h-8 w-16", inputMode: "decimal", value: effort, onChange: (e) => setEffort(e.target.value) }), _jsx(Button, { size: "sm", variant: done ? "secondary" : "default", disabled: busy, onClick: async () => {
|
|
89
|
+
setError(null);
|
|
90
|
+
try {
|
|
91
|
+
if (done) {
|
|
92
|
+
await update.mutateAsync({
|
|
93
|
+
logId: done.id,
|
|
94
|
+
actual,
|
|
95
|
+
...(rpe !== undefined ? { rpe } : {}),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
await add.mutateAsync({
|
|
100
|
+
sessionId,
|
|
101
|
+
item: itemLabel,
|
|
102
|
+
exerciseId,
|
|
103
|
+
...(level !== undefined ? { level } : {}),
|
|
104
|
+
setNumber,
|
|
105
|
+
actual,
|
|
106
|
+
...(rpe !== undefined ? { rpe } : {}),
|
|
107
|
+
...(personId ? { personId } : {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
onLogged(target);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
setError(e.message ?? "Not logged");
|
|
114
|
+
}
|
|
115
|
+
}, children: done ? "Update" : "Log set" }), done ? _jsx("span", { title: "Logged", children: "\u2713" }) : null, error ? (_jsx("span", { role: "alert", className: "text-destructive", children: error })) : null] }));
|
|
116
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProgramsHooks } from "@composable-os/pack-programs/client";
|
|
2
|
+
export declare function Today({ programs, date, onRestDone, }: {
|
|
3
|
+
programs: Pick<ProgramsHooks, "useLogSet" | "useMarkSession" | "useSession" | "useToday" | "useUpdateSet">;
|
|
4
|
+
/** The member's local date (YYYY-MM-DD); the host's UTC today when left out. */
|
|
5
|
+
date?: string;
|
|
6
|
+
onRestDone?: () => void;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
export function Today({ programs, date, onRestDone, }) {
|
|
7
|
+
const [day, setDay] = useState(date ?? "");
|
|
8
|
+
const today = programs.useToday(day ? { date: day } : {});
|
|
9
|
+
const [open, setOpen] = useState(null);
|
|
10
|
+
return (_jsxs("div", { className: "grid gap-4", "data-testid": "today", children: [_jsx("div", { className: "flex items-center gap-2", children: _jsx(Input, { "aria-label": "Date", type: "date", value: day || today.data?.date || "", onChange: (e) => setDay(e.target.value), className: "w-44" }) }), today.isPending ? _jsx("p", { "aria-busy": "true", children: "Loading your day\u2026" }) : null, today.error ? _jsx("p", { role: "alert", children: "We could not load your sessions." }) : null, today.data && !today.data.sessions.length ? _jsx("p", { children: "Nothing planned for this day." }) : null, _jsx("ul", { className: "grid gap-2", children: (today.data?.sessions ?? []).map((s) => (_jsxs("li", { className: "grid gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: open === s.id ? "default" : "outline", onClick: () => setOpen(open === s.id ? null : s.id), children: s.name }), _jsx("span", { className: "text-sm text-muted-foreground", children: [
|
|
11
|
+
s.programTitle,
|
|
12
|
+
s.state === "done" ? "done" : s.state === "skipped" ? "skipped" : null,
|
|
13
|
+
]
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.join(" · ") })] }), open === s.id ? (_jsx(SessionView, { programs: programs, sessionId: s.id, ...(onRestDone ? { onRestDone } : {}) })) : null] }, s.id))) })] }));
|
|
16
|
+
}
|