@composable-os/pack-courses 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/automations.d.ts +12 -0
- package/dist/automations.js +84 -0
- package/dist/blocks/courses-builder/course-builder.d.ts +5 -0
- package/dist/blocks/courses-builder/course-builder.js +69 -0
- package/dist/blocks/courses-catalogue/catalogue.d.ts +6 -0
- package/dist/blocks/courses-catalogue/catalogue.js +21 -0
- package/dist/blocks/courses-course/course-page.d.ts +10 -0
- package/dist/blocks/courses-course/course-page.js +51 -0
- package/dist/blocks/courses-my-courses/my-courses.d.ts +5 -0
- package/dist/blocks/courses-my-courses/my-courses.js +20 -0
- package/dist/blocks/courses-native-catalogue/catalogue-screen.d.ts +6 -0
- package/dist/blocks/courses-native-catalogue/catalogue-screen.js +15 -0
- package/dist/blocks/courses-native-course/course-screen.d.ts +7 -0
- package/dist/blocks/courses-native-course/course-screen.js +18 -0
- package/dist/blocks/courses-native-my-courses/my-courses-screen.d.ts +5 -0
- package/dist/blocks/courses-native-my-courses/my-courses-screen.js +9 -0
- package/dist/blocks/courses-native-player/lesson-screen.d.ts +19 -0
- package/dist/blocks/courses-native-player/lesson-screen.js +11 -0
- package/dist/blocks/courses-native-subscription/subscription-screen.d.ts +4 -0
- package/dist/blocks/courses-native-subscription/subscription-screen.js +17 -0
- package/dist/blocks/courses-player/player.d.ts +12 -0
- package/dist/blocks/courses-player/player.js +51 -0
- package/dist/blocks/courses-subscribe/subscribe.d.ts +28 -0
- package/dist/blocks/courses-subscribe/subscribe.js +146 -0
- package/dist/blocks/courses-subscription/my-subscription.d.ts +6 -0
- package/dist/blocks/courses-subscription/my-subscription.js +50 -0
- package/dist/client/index.d.ts +1319 -0
- package/dist/client/index.js +414 -0
- package/dist/dashboards.d.ts +5 -0
- package/dist/dashboards.js +119 -0
- package/dist/index.d.ts +809 -0
- package/dist/index.js +427 -0
- package/dist/outline.d.ts +85 -0
- package/dist/outline.js +188 -0
- package/dist/tools.d.ts +255 -0
- package/dist/tools.js +826 -0
- package/package.json +36 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
> This licence covers the repository except the directories listed in NOTICE. In particular, the
|
|
4
|
+
> assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
|
|
5
|
+
> licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
|
|
6
|
+
|
|
7
|
+
## Abbreviation
|
|
8
|
+
|
|
9
|
+
FSL-1.1-ALv2
|
|
10
|
+
|
|
11
|
+
## Notice
|
|
12
|
+
|
|
13
|
+
Copyright 2026 Tim O'Connell
|
|
14
|
+
|
|
15
|
+
## Terms and Conditions
|
|
16
|
+
|
|
17
|
+
### Licensor ("We")
|
|
18
|
+
|
|
19
|
+
The party offering the Software under these Terms and Conditions.
|
|
20
|
+
|
|
21
|
+
### The Software
|
|
22
|
+
|
|
23
|
+
The "Software" is each version of the software that we make available under
|
|
24
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
25
|
+
Conditions with the Software.
|
|
26
|
+
|
|
27
|
+
### License Grant
|
|
28
|
+
|
|
29
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
30
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
31
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
32
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
33
|
+
|
|
34
|
+
### Permitted Purpose
|
|
35
|
+
|
|
36
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
37
|
+
means making the Software available to others in a commercial product or
|
|
38
|
+
service that:
|
|
39
|
+
|
|
40
|
+
1. substitutes for the Software;
|
|
41
|
+
|
|
42
|
+
2. substitutes for any other product or service we offer using the Software
|
|
43
|
+
that exists as of the date we make the Software available; or
|
|
44
|
+
|
|
45
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
46
|
+
|
|
47
|
+
Permitted Purposes specifically include using the Software:
|
|
48
|
+
|
|
49
|
+
1. for your internal use and access;
|
|
50
|
+
|
|
51
|
+
2. for non-commercial education;
|
|
52
|
+
|
|
53
|
+
3. for non-commercial research; and
|
|
54
|
+
|
|
55
|
+
4. in connection with professional services that you provide to a licensee
|
|
56
|
+
using the Software in accordance with these Terms and Conditions.
|
|
57
|
+
|
|
58
|
+
### Patents
|
|
59
|
+
|
|
60
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
61
|
+
patents, the license grant above includes a license under our patents. If you
|
|
62
|
+
make a claim against any party that the Software infringes or contributes to
|
|
63
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
64
|
+
immediately.
|
|
65
|
+
|
|
66
|
+
### Redistribution
|
|
67
|
+
|
|
68
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
69
|
+
the Software.
|
|
70
|
+
|
|
71
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
72
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
73
|
+
remove any copyright notices provided in or with the Software.
|
|
74
|
+
|
|
75
|
+
### Disclaimer
|
|
76
|
+
|
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
78
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
79
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
80
|
+
|
|
81
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
82
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
83
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
84
|
+
|
|
85
|
+
### Trademarks
|
|
86
|
+
|
|
87
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
88
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
89
|
+
trademarks, trade names, service marks or product names.
|
|
90
|
+
|
|
91
|
+
## Grant of Future License
|
|
92
|
+
|
|
93
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
94
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
95
|
+
the date we make the Software available. On or after that date, you may use the
|
|
96
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
97
|
+
will apply:
|
|
98
|
+
|
|
99
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
100
|
+
this file except in compliance with the License.
|
|
101
|
+
|
|
102
|
+
You may obtain a copy of the License at
|
|
103
|
+
|
|
104
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
105
|
+
|
|
106
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
107
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
108
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
109
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const assignSessions: import("@composable-os/sdk").AutomationSpec<{
|
|
2
|
+
readonly type: "record";
|
|
3
|
+
readonly object: "courses.progress";
|
|
4
|
+
readonly on: readonly ["created"];
|
|
5
|
+
}>;
|
|
6
|
+
export declare const coursesAutomations: {
|
|
7
|
+
assignSessions: import("@composable-os/sdk").AutomationSpec<{
|
|
8
|
+
readonly type: "record";
|
|
9
|
+
readonly object: "courses.progress";
|
|
10
|
+
readonly on: readonly ["created"];
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The Courses automation (stage 42, step 6): when a student first opens a course that has session
|
|
2
|
+
// lessons, each program those lessons use is assigned to them from that day, as Programs assigns
|
|
3
|
+
// any program (`x.programs.assign`): one dated session per session of its layout, the dates a
|
|
4
|
+
// suggested pace. They then log sets with Programs' own tools. It runs as the extension, a few
|
|
5
|
+
// seconds after the student's first progress row; that row exists only for a student who holds
|
|
6
|
+
// access to the course (the host's `requireAccess`), so no one else is assigned anything.
|
|
7
|
+
import { defineAutomation } from "@composable-os/sdk";
|
|
8
|
+
import { asOutline, sessionPrograms } from "./outline.js";
|
|
9
|
+
const COURSE = "courses.course";
|
|
10
|
+
const PROGRESS = "courses.progress";
|
|
11
|
+
const ASSIGNMENT = "programs.assignment";
|
|
12
|
+
export const assignSessions = defineAutomation({
|
|
13
|
+
label: "Assign a course's sessions",
|
|
14
|
+
description: "When a student first opens a course with session lessons, assigns them each Programs " +
|
|
15
|
+
"program those lessons use, from that day. A program already assigned to them is left as it is.",
|
|
16
|
+
trigger: { type: "record", object: PROGRESS, on: ["created"] },
|
|
17
|
+
steps: [
|
|
18
|
+
{
|
|
19
|
+
name: "findPrograms",
|
|
20
|
+
label: "Find the course's session programs and the student's assignments",
|
|
21
|
+
reads: [PROGRESS, COURSE, ASSIGNMENT],
|
|
22
|
+
calls: ["record.get", "record.version", "record.list"],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "assign",
|
|
26
|
+
label: "Assign each program not yet assigned",
|
|
27
|
+
writes: [{ object: ASSIGNMENT }, { object: "programs.session" }],
|
|
28
|
+
calls: ["x.programs.assign"],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
async run(event, step, ctx) {
|
|
32
|
+
const progressId = event.record?.id;
|
|
33
|
+
if (!progressId)
|
|
34
|
+
return { skipped: "no progress row" };
|
|
35
|
+
const wanted = await step.do("findPrograms", async () => {
|
|
36
|
+
const row = await ctx.ops.call("record.get", {
|
|
37
|
+
object: PROGRESS,
|
|
38
|
+
id: progressId,
|
|
39
|
+
});
|
|
40
|
+
const person = String(row.values.holder ?? "");
|
|
41
|
+
const courseId = String(row.values.course ?? "");
|
|
42
|
+
if (!person || !courseId)
|
|
43
|
+
return { person, programs: [] };
|
|
44
|
+
const version = await ctx.ops.call("record.version", {
|
|
45
|
+
object: COURSE,
|
|
46
|
+
id: courseId,
|
|
47
|
+
});
|
|
48
|
+
const programs = sessionPrograms(asOutline(version.values.outline));
|
|
49
|
+
const missing = [];
|
|
50
|
+
for (const program of programs) {
|
|
51
|
+
const had = await ctx.ops.call("record.list", {
|
|
52
|
+
object: ASSIGNMENT,
|
|
53
|
+
filter: {
|
|
54
|
+
and: [
|
|
55
|
+
{ field: "person", op: "eq", value: person },
|
|
56
|
+
{ field: "program", op: "eq", value: program },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
limit: 1,
|
|
60
|
+
});
|
|
61
|
+
if (!had.items.length)
|
|
62
|
+
missing.push(program);
|
|
63
|
+
}
|
|
64
|
+
return { person, programs: missing };
|
|
65
|
+
});
|
|
66
|
+
if (!wanted.programs.length)
|
|
67
|
+
return { assigned: 0 };
|
|
68
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
69
|
+
const made = await step.do("assign", async () => {
|
|
70
|
+
const ids = [];
|
|
71
|
+
for (const programId of wanted.programs) {
|
|
72
|
+
const out = await ctx.ops.call("x.programs.assign", {
|
|
73
|
+
programId,
|
|
74
|
+
personId: wanted.person,
|
|
75
|
+
startDate: today,
|
|
76
|
+
});
|
|
77
|
+
ids.push(out.assignmentId);
|
|
78
|
+
}
|
|
79
|
+
return ids;
|
|
80
|
+
});
|
|
81
|
+
return { assigned: made.length };
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
export const coursesAutomations = { assignSessions };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function CourseBuilder({ courses, courseId, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useWorkingCopy" | "useSaveOutline" | "usePublishCourse" | "useLibraryVideos" | "usePublishedPrograms">;
|
|
4
|
+
courseId: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { outlineEdits } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
import { Label } from "../ui-label/label.js";
|
|
7
|
+
const KINDS = [
|
|
8
|
+
{ value: "video", label: "Video" },
|
|
9
|
+
{ value: "text", label: "Text" },
|
|
10
|
+
{ value: "session", label: "Training session" },
|
|
11
|
+
{ value: "download", label: "Download" },
|
|
12
|
+
];
|
|
13
|
+
export function CourseBuilder({ courses, courseId, }) {
|
|
14
|
+
const working = courses.useWorkingCopy(courseId);
|
|
15
|
+
const videos = courses.useLibraryVideos();
|
|
16
|
+
const programs = courses.usePublishedPrograms();
|
|
17
|
+
const save = courses.useSaveOutline();
|
|
18
|
+
const publish = courses.usePublishCourse();
|
|
19
|
+
const [outline, setOutline] = useState(null);
|
|
20
|
+
const [message, setMessage] = useState(null);
|
|
21
|
+
const [newSection, setNewSection] = useState("");
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const value = working.data?.values.outline;
|
|
24
|
+
if (value && !outline)
|
|
25
|
+
setOutline(value?.sections ? value : { sections: [] });
|
|
26
|
+
else if (working.data && !outline)
|
|
27
|
+
setOutline({ sections: [] });
|
|
28
|
+
}, [working.data, outline]);
|
|
29
|
+
if (working.isPending || !outline)
|
|
30
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the course\u2026" });
|
|
31
|
+
if (working.error)
|
|
32
|
+
return _jsx("p", { role: "alert", children: "This course is not here." });
|
|
33
|
+
const onSave = async () => {
|
|
34
|
+
setMessage(null);
|
|
35
|
+
try {
|
|
36
|
+
await save.mutateAsync({ object: "courses.course", id: courseId, values: { outline } });
|
|
37
|
+
setMessage("Saved");
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
setMessage(e instanceof Error ? e.message : "Not saved");
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const onPublish = async () => {
|
|
44
|
+
setMessage(null);
|
|
45
|
+
try {
|
|
46
|
+
await save.mutateAsync({ object: "courses.course", id: courseId, values: { outline } });
|
|
47
|
+
await publish.mutateAsync({ object: "courses.course", id: courseId });
|
|
48
|
+
setMessage("Published");
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
setMessage(e instanceof Error ? e.message : "Not published");
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return (_jsxs("section", { className: "grid gap-6", "aria-label": "Course builder", children: [outline.sections.map((section, s) => (_jsxs("fieldset", { className: "grid gap-3 rounded-lg border p-4", children: [_jsx("legend", { className: "px-1 font-semibold", children: section.title }), _jsx("ol", { className: "grid gap-3", children: (section.lessons ?? []).map((lesson, i) => (_jsxs("li", { className: "grid gap-2 rounded border p-3", "aria-label": lesson.title, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Input, { "aria-label": "Lesson title", value: lesson.title, onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, { title: e.target.value })) }), _jsx("span", { className: "text-sm", children: KINDS.find((k) => k.value === lesson.kind)?.label }), _jsx(Button, { size: "sm", variant: "ghost", "aria-label": "Move up", disabled: i === 0, onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, section.key, i - 1)), children: "\u2191" }), _jsx(Button, { size: "sm", variant: "ghost", "aria-label": "Move down", onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, section.key, i + 1)), children: "\u2193" }), s > 0 ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, outline.sections[s - 1]?.key ?? section.key, 999)), children: "To the section above" })) : null, _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setOutline(outlineEdits.removeLesson(outline, lesson.key)), children: "Remove" })] }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: lesson.preview === true, onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, {
|
|
55
|
+
preview: e.target.checked,
|
|
56
|
+
})) }), "Free preview"] }), lesson.kind === "video" || lesson.kind === "session" ? (_jsxs("label", { className: "grid gap-1 text-sm", children: [lesson.kind === "video" ? "Video" : "Video to follow along to (optional)", _jsxs("select", { value: ("video" in lesson && lesson.video?.media) || "", onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, {
|
|
57
|
+
video: e.target.value ? { media: e.target.value } : undefined,
|
|
58
|
+
})), children: [_jsx("option", { value: "", children: "Choose a ready video" }), (videos.data?.items ?? []).map((v) => (_jsx("option", { value: v.id, children: String(v.values.name ?? v.id) }, v.id)))] })] })) : null, lesson.kind === "session" ? (_jsxs("label", { className: "grid gap-1 text-sm", children: ["Program (week 1, first session)", _jsxs("select", { value: ("program" in lesson && lesson.program) || "", onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, {
|
|
59
|
+
program: e.target.value,
|
|
60
|
+
week: 1,
|
|
61
|
+
session: 0,
|
|
62
|
+
})), children: [_jsx("option", { value: "", children: "Choose a published program" }), (programs.data?.items ?? []).map((p) => (_jsx("option", { value: p.id, children: String(p.values.title ?? p.title ?? p.id) }, p.id)))] })] })) : null] }, lesson.key))) }), _jsx("div", { className: "flex flex-wrap gap-2", children: KINDS.map((kind) => (_jsx(Button, { size: "sm", variant: "outline", onClick: () => setOutline(outlineEdits.addLesson(outline, section.key, kind.value, `New ${kind.label.toLowerCase()}`)), children: `Add ${kind.label.toLowerCase()}` }, kind.value))) })] }, section.key))), _jsxs("form", { className: "flex items-end gap-2", onSubmit: (e) => {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
if (!newSection.trim())
|
|
65
|
+
return;
|
|
66
|
+
setOutline(outlineEdits.addSection(outline, newSection.trim()));
|
|
67
|
+
setNewSection("");
|
|
68
|
+
}, children: [_jsxs("div", { className: "grid gap-1", children: [_jsx(Label, { htmlFor: "new-section", children: "New section" }), _jsx(Input, { id: "new-section", value: newSection, onChange: (e) => setNewSection(e.target.value) })] }), _jsx(Button, { type: "submit", variant: "outline", children: "Add section" })] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { onClick: () => void onSave(), disabled: save.isPending, children: "Save" }), _jsx(Button, { variant: "secondary", onClick: () => void onPublish(), disabled: save.isPending || publish.isPending, children: "Publish" })] }), message ? _jsx("p", { role: "status", children: message }) : null] }));
|
|
69
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function CourseCatalogue({ courses, onOpenCourse, onOpenBundle, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useCatalogue">;
|
|
4
|
+
onOpenCourse: (slug: string) => void;
|
|
5
|
+
onOpenBundle?: (slug: string) => void;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatPrice, mediaPath } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
6
|
+
const LEVELS = { 1: "Beginner", 2: "Intermediate", 3: "Advanced" };
|
|
7
|
+
export function CourseCatalogue({ courses, onOpenCourse, onOpenBundle, }) {
|
|
8
|
+
const [theme, setTheme] = useState(undefined);
|
|
9
|
+
const { data, isPending, error } = courses.useCatalogue(theme ? { theme } : {});
|
|
10
|
+
if (isPending)
|
|
11
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading courses\u2026" });
|
|
12
|
+
if (error || !data)
|
|
13
|
+
return _jsx("p", { role: "alert", children: "We could not load the courses. Try again soon." });
|
|
14
|
+
return (_jsxs("section", { className: "grid gap-6", "aria-label": "Courses", children: [data.themes.length ? (_jsxs("nav", { className: "flex flex-wrap gap-2", "aria-label": "Themes", children: [_jsx(Button, { variant: theme ? "outline" : "default", size: "sm", onClick: () => setTheme(undefined), children: "All" }), data.themes.map((t) => (_jsx(Button, { size: "sm", variant: theme === t.id ? "default" : "outline", onClick: () => setTheme(t.id), children: t.name }, t.id)))] })) : null, data.courses.length ? null : _jsx("p", { children: "No courses yet." }), _jsx("ul", { className: "grid gap-4 sm:grid-cols-2", children: data.courses.map((course) => (_jsx("li", { children: _jsxs(Card, { children: [course.cover ? (_jsx("img", { src: mediaPath(course.cover.media, 640), alt: "", className: "w-full rounded-t-lg" })) : null, _jsxs(CardHeader, { children: [_jsx(CardTitle, { children: course.title }), _jsx(CardDescription, { children: [
|
|
15
|
+
course.level ? LEVELS[course.level] : null,
|
|
16
|
+
`${course.lessons} lessons`,
|
|
17
|
+
formatPrice(course.price, data.currency),
|
|
18
|
+
]
|
|
19
|
+
.filter(Boolean)
|
|
20
|
+
.join(" · ") })] }), _jsxs(CardContent, { className: "grid gap-3", children: [course.summary ? _jsx("p", { children: course.summary }) : null, _jsx(Button, { onClick: () => course.slug && onOpenCourse(course.slug), children: "See the course" })] })] }) }, course.id))) }), data.bundles.length ? (_jsxs("section", { "aria-label": "Bundles", className: "grid gap-4", children: [_jsx("h2", { className: "text-xl font-semibold", children: "Bundles" }), _jsx("ul", { className: "grid gap-4 sm:grid-cols-2", children: data.bundles.map((bundle) => (_jsx("li", { children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: bundle.title }), _jsx(CardDescription, { children: `${bundle.courses.length} courses · ${formatPrice(bundle.price, data.currency)}` })] }), _jsxs(CardContent, { children: [bundle.summary ? _jsx("p", { children: bundle.summary }) : null, onOpenBundle && bundle.slug ? (_jsx(Button, { variant: "outline", onClick: () => onOpenBundle(bundle.slug), children: "See the bundle" })) : null] })] }) }, bundle.id))) })] })) : null] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function CoursePage({ courses, slug, returnUrl, signedIn, onOpenLesson, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useCourse" | "useBuy" | "usePlayback">;
|
|
4
|
+
slug: string;
|
|
5
|
+
/** Where the provider's page sends the buyer back to (one of the host's listed origins). */
|
|
6
|
+
returnUrl: string;
|
|
7
|
+
/** A signed-in customer buys as themselves; a guest gives their email. */
|
|
8
|
+
signedIn: boolean;
|
|
9
|
+
onOpenLesson: (courseId: string, lessonKey: string) => void;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatPrice, minutes } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
import { Input } from "../ui-input/input.js";
|
|
6
|
+
import { Label } from "../ui-label/label.js";
|
|
7
|
+
export function CoursePage({ courses, slug, returnUrl, signedIn, onOpenLesson, }) {
|
|
8
|
+
const { data: course, isPending, error } = courses.useCourse(slug);
|
|
9
|
+
const trailer = courses.usePlayback(course?.trailer
|
|
10
|
+
? {
|
|
11
|
+
media: course.trailer.media,
|
|
12
|
+
record: { object: "courses.course", id: course.id },
|
|
13
|
+
field: "trailer",
|
|
14
|
+
}
|
|
15
|
+
: null);
|
|
16
|
+
const buy = courses.useBuy();
|
|
17
|
+
const [email, setEmail] = useState("");
|
|
18
|
+
const [problem, setProblem] = useState(null);
|
|
19
|
+
if (isPending)
|
|
20
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the course\u2026" });
|
|
21
|
+
if (error || !course)
|
|
22
|
+
return _jsx("p", { role: "alert", children: "This course is not here." });
|
|
23
|
+
async function onBuy() {
|
|
24
|
+
if (!course)
|
|
25
|
+
return;
|
|
26
|
+
setProblem(null);
|
|
27
|
+
try {
|
|
28
|
+
const order = await buy.start.mutateAsync({
|
|
29
|
+
courseId: course.id,
|
|
30
|
+
...(signedIn ? {} : { email }),
|
|
31
|
+
});
|
|
32
|
+
const checkout = await buy.checkout.mutateAsync({
|
|
33
|
+
id: order.id,
|
|
34
|
+
...(order.token ? { token: order.token } : {}),
|
|
35
|
+
returnUrl,
|
|
36
|
+
});
|
|
37
|
+
window.location.assign(checkout.url);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
setProblem(e instanceof Error ? e.message : "We could not start your order");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return (_jsxs("article", { className: "grid gap-6", "aria-labelledby": "course-title", children: [_jsx("h1", { id: "course-title", className: "text-3xl font-semibold", children: course.title }), course.summary ? _jsx("p", { className: "text-lg", children: course.summary }) : null, trailer.data ? (_jsx("video", { controls: true, playsInline: true, src: trailer.data.hls, poster: trailer.data.poster, className: "w-full rounded-lg" })) : null, course.holds ? (_jsx("p", { children: _jsx(Button, { onClick: () => {
|
|
44
|
+
const first = course.sections[0]?.lessons[0];
|
|
45
|
+
if (first)
|
|
46
|
+
onOpenLesson(course.id, first.key);
|
|
47
|
+
}, children: "Open the course" }) })) : (_jsxs("form", { className: "grid max-w-sm gap-2", onSubmit: (e) => {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
void onBuy();
|
|
50
|
+
}, children: [signedIn ? null : (_jsxs(_Fragment, { children: [_jsx(Label, { htmlFor: "buyer-email", children: "Your email" }), _jsx(Input, { id: "buyer-email", type: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), _jsx(Button, { type: "submit", disabled: buy.start.isPending || buy.checkout.isPending, children: `Buy · ${formatPrice(course.price, course.currency)}` }), problem ? _jsx("p", { role: "alert", children: problem }) : null] })), _jsx("ol", { className: "grid gap-4", "aria-label": "Outline", children: course.sections.map((section) => (_jsxs("li", { children: [_jsx("h2", { className: "text-xl font-semibold", children: section.title }), _jsx("ul", { className: "grid gap-1", children: section.lessons.map((lesson) => (_jsxs("li", { className: "flex items-center justify-between gap-2", children: [_jsxs("span", { children: [course.done.includes(lesson.key) ? "✓ " : "", lesson.title, lesson.duration ? ` · ${minutes(lesson.duration)}` : ""] }), course.holds || lesson.preview ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => onOpenLesson(course.id, lesson.key), children: lesson.preview && !course.holds ? "Watch the preview" : "Open" })) : null] }, lesson.key))) })] }, section.key))) })] }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function MyCourses({ courses, onContinue, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useMyCourses">;
|
|
4
|
+
onContinue: (courseId: string, lessonKey: string | null) => void;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "../ui-button/button.js";
|
|
3
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
4
|
+
const WHY = {
|
|
5
|
+
bought: "Bought",
|
|
6
|
+
bundle: "In a bundle",
|
|
7
|
+
given: "Given to you",
|
|
8
|
+
imported: "From your old account",
|
|
9
|
+
subscription: "Through your subscription",
|
|
10
|
+
};
|
|
11
|
+
export function MyCourses({ courses, onContinue, }) {
|
|
12
|
+
const { data, isPending, error } = courses.useMyCourses();
|
|
13
|
+
if (isPending)
|
|
14
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading your courses\u2026" });
|
|
15
|
+
if (error || !data)
|
|
16
|
+
return _jsx("p", { role: "alert", children: "We could not load your courses." });
|
|
17
|
+
if (!data.courses.length)
|
|
18
|
+
return _jsx("p", { children: "You have no courses yet." });
|
|
19
|
+
return (_jsx("ul", { className: "grid gap-4", "aria-label": "My courses", children: data.courses.map((course) => (_jsx("li", { children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: course.title }), _jsx(CardDescription, { children: `${WHY[course.why]} · ${course.complete ? "Complete" : `${course.done} of ${course.counted} lessons done`}` })] }), _jsxs(CardContent, { children: [_jsx("progress", { value: course.done, max: Math.max(course.counted, 1), "aria-label": "Progress", className: "w-full" }), _jsx(Button, { onClick: () => onContinue(course.id, course.continueWith), children: course.done ? "Carry on" : "Start" })] })] }) }, course.id))) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function CatalogueScreen({ courses, onOpen, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useCatalogue">;
|
|
4
|
+
/** Pushes the course's screen (CourseScreen) on the app's native stack. */
|
|
5
|
+
onOpen: (slug: string) => void;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
const LEVELS = { 1: "Beginner", 2: "Intermediate", 3: "Advanced" };
|
|
7
|
+
export function CatalogueScreen({ courses, onOpen, }) {
|
|
8
|
+
const { data, isPending, error } = courses.useCatalogue({});
|
|
9
|
+
return (_jsxs(Screen, { title: "Courses", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading courses\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load the courses." }) : null, data ? (_jsx(List, { empty: "No courses yet.", children: data.courses.map((course) => (_jsx(Row, { title: course.title ?? "Course", detail: [
|
|
10
|
+
course.level ? LEVELS[course.level] : null,
|
|
11
|
+
`${course.lessons} lessons`,
|
|
12
|
+
]
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join(" · "), onPress: course.slug ? () => onOpen(course.slug) : undefined }, course.id))) })) : null] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function CourseScreen({ courses, slug, onOpenLesson, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useCourse">;
|
|
4
|
+
slug: string;
|
|
5
|
+
/** Pushes the lesson's screen (LessonScreen). */
|
|
6
|
+
onOpenLesson: (courseId: string, lessonKey: string) => void;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { minutes } from "@composable-os/pack-courses/client";
|
|
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
|
+
export function CourseScreen({ courses, slug, onOpenLesson, }) {
|
|
8
|
+
const { data: course, isPending, error } = courses.useCourse(slug);
|
|
9
|
+
return (_jsxs(Screen, { title: course?.title ?? "Course", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading the course\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This course is not here." }) : null, course ? (_jsxs(_Fragment, { children: [course.summary ? _jsx(Text, { children: course.summary }) : null, course.holds ? null : _jsx(Text, { children: "Find this course on the studio's website." }), _jsx(List, { empty: "No lessons yet.", children: course.sections.flatMap((section) => section.lessons.map((lesson) => (_jsx(Row, { title: `${course.done.includes(lesson.key) ? "✓ " : ""}${lesson.title}`, detail: [
|
|
10
|
+
section.title,
|
|
11
|
+
minutes(lesson.duration),
|
|
12
|
+
lesson.preview ? "Free preview" : null,
|
|
13
|
+
]
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.join(" · "), onPress: course.holds || lesson.preview
|
|
16
|
+
? () => onOpenLesson(course.id, lesson.key)
|
|
17
|
+
: undefined }, lesson.key)))) })] })) : null] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
export declare function MyCoursesScreen({ courses, onContinue, }: {
|
|
3
|
+
courses: Pick<CoursesHooks, "useMyCourses">;
|
|
4
|
+
onContinue: (courseId: string, lessonKey: string | null) => void;
|
|
5
|
+
}): 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 MyCoursesScreen({ courses, onContinue, }) {
|
|
7
|
+
const { data, isPending, error } = courses.useMyCourses();
|
|
8
|
+
return (_jsxs(Screen, { title: "My courses", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading your courses\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your courses." }) : null, data ? (_jsx(List, { empty: "You have no courses yet.", children: data.courses.map((course) => (_jsx(Row, { title: course.title ?? "Course", detail: course.complete ? "Complete" : `${course.done} of ${course.counted} lessons done`, onPress: () => onContinue(course.id, course.continueWith) }, course.id))) })) : null] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CoursesHooks, Playback } from "@composable-os/pack-courses/client";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
/** What the app's player is given, and how it reports where it is. */
|
|
4
|
+
export interface NativePlayerProps {
|
|
5
|
+
playback: Playback;
|
|
6
|
+
/** Seconds to start from: where the student left the video. */
|
|
7
|
+
startAt: number;
|
|
8
|
+
onPosition: (seconds: number, duration: number) => void;
|
|
9
|
+
onEnded: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function LessonScreen({ courses, courseId, lessonKey, Player, onNext, renderText, renderSession, }: {
|
|
12
|
+
courses: Pick<CoursesHooks, "useLesson" | "usePlayback" | "useProgress">;
|
|
13
|
+
courseId: string;
|
|
14
|
+
lessonKey: string;
|
|
15
|
+
Player: (props: NativePlayerProps) => ReactNode;
|
|
16
|
+
onNext: (lessonKey: string) => void;
|
|
17
|
+
renderText?: (value: unknown) => ReactNode;
|
|
18
|
+
renderSession?: (courseId: string, lessonKey: string) => ReactNode;
|
|
19
|
+
}): 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 { Button } from "../native-base/button.js";
|
|
4
|
+
import { Screen } from "../native-base/screen.js";
|
|
5
|
+
export function LessonScreen({ courses, courseId, lessonKey, Player, onNext, renderText, renderSession, }) {
|
|
6
|
+
const { data, isPending, error } = courses.useLesson(courseId, lessonKey);
|
|
7
|
+
const playback = courses.usePlayback(data?.video ?? null);
|
|
8
|
+
const progress = courses.useProgress();
|
|
9
|
+
const lesson = data?.lesson;
|
|
10
|
+
return (_jsxs(Screen, { title: lesson?.title ?? "Lesson", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading the lesson\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This lesson is not here." }) : null, data && playback.data ? (_jsx(Player, { playback: playback.data, startAt: data.position ?? 0, onPosition: (position, duration) => progress.mutate({ courseId, lessonKey, position, duration }), onEnded: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, lesson?.kind === "text" && renderText ? renderText(lesson.body) : null, lesson?.kind === "video" && lesson.notes && renderText ? renderText(lesson.notes) : null, lesson?.kind === "session" && renderSession ? renderSession(courseId, lessonKey) : null, data ? (_jsx(Button, { label: data.state === "done" ? "Done" : "Mark as done", quiet: data.state === "done", onPress: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, data?.next ? (_jsx(Button, { label: `Next: ${data.next.title}`, quiet: true, onPress: () => data.next && onNext(data.next.key) })) : null] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { day, isLive, PLAN, subscriptionStatus } from "@composable-os/pack-courses/client";
|
|
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
|
+
export function SubscriptionScreen({ courses, }) {
|
|
8
|
+
const { data, isPending, error } = courses.useMySubscriptions();
|
|
9
|
+
const offers = courses.useMyOffers();
|
|
10
|
+
const live = data?.items.filter(isLive) ?? [];
|
|
11
|
+
const offer = offers.data?.offers.find((o) => o.planObject === PLAN);
|
|
12
|
+
return (_jsxs(Screen, { title: "My subscription", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading your subscription\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your subscription." }) : null, data ? (_jsx(List, { empty: "You have no course subscription.", children: live.map((sub) => (_jsx(Row, { title: `${sub.planTitle}: every course`, detail: subscriptionStatus(sub) }, sub.id))) })) : null, offer && !live.length ? (_jsx(Text, { children: offer.askUs
|
|
13
|
+
? `Your subscription with us is paid up to ${day(offer.freeUntil)}. Ask the studio to continue it.`
|
|
14
|
+
: offer.chargedNow
|
|
15
|
+
? `Your subscription with us was paid up to ${day(offer.freeUntil)}. Continue it on the studio's website.`
|
|
16
|
+
: `Your subscription with us is paid up to ${day(offer.freeUntil)}. Continue it on the studio's website, free until then.` })) : null, live.length ? _jsx(Text, { children: "Manage your subscription on the studio's website." }) : null] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
export declare function LessonPlayer({ courses, courseId, lessonKey, onNext, renderText, renderSession, }: {
|
|
4
|
+
courses: Pick<CoursesHooks, "useLesson" | "usePlayback" | "useProgress">;
|
|
5
|
+
courseId: string;
|
|
6
|
+
lessonKey: string;
|
|
7
|
+
onNext: (lessonKey: string) => void;
|
|
8
|
+
/** Draws rich text (the Content pack's renderer, `content-rich-text`). */
|
|
9
|
+
renderText?: (value: unknown) => ReactNode;
|
|
10
|
+
/** Draws a session lesson's own Programs session (the Programs session block). */
|
|
11
|
+
renderSession?: (courseId: string, lessonKey: string) => ReactNode;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { mediaPath } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { Button } from "../ui-button/button.js";
|
|
5
|
+
/** How often the player keeps the position while a video plays, in seconds of video. */
|
|
6
|
+
const KEEP_EVERY = 15;
|
|
7
|
+
export function LessonPlayer({ courses, courseId, lessonKey, onNext, renderText, renderSession, }) {
|
|
8
|
+
const { data, isPending, error } = courses.useLesson(courseId, lessonKey);
|
|
9
|
+
const playback = courses.usePlayback(data?.video ?? null);
|
|
10
|
+
const progress = courses.useProgress();
|
|
11
|
+
const video = useRef(null);
|
|
12
|
+
const kept = useRef(0);
|
|
13
|
+
const [doneNow, setDoneNow] = useState(false);
|
|
14
|
+
// A new lesson starts with nothing kept yet.
|
|
15
|
+
const [shown, setShown] = useState(lessonKey);
|
|
16
|
+
if (shown !== lessonKey) {
|
|
17
|
+
setShown(lessonKey);
|
|
18
|
+
setDoneNow(false);
|
|
19
|
+
kept.current = 0;
|
|
20
|
+
}
|
|
21
|
+
if (isPending)
|
|
22
|
+
return _jsx("p", { "aria-busy": "true", children: "Loading the lesson\u2026" });
|
|
23
|
+
if (error || !data)
|
|
24
|
+
return _jsx("p", { role: "alert", children: "This lesson is not here." });
|
|
25
|
+
const lesson = data.lesson;
|
|
26
|
+
const keep = (state) => progress
|
|
27
|
+
.mutateAsync({
|
|
28
|
+
courseId,
|
|
29
|
+
lessonKey,
|
|
30
|
+
...(state ? { state } : {}),
|
|
31
|
+
...(video.current && Number.isFinite(video.current.duration)
|
|
32
|
+
? { position: video.current.currentTime, duration: video.current.duration }
|
|
33
|
+
: {}),
|
|
34
|
+
})
|
|
35
|
+
.then((kept) => {
|
|
36
|
+
if (kept.state === "done")
|
|
37
|
+
setDoneNow(true);
|
|
38
|
+
})
|
|
39
|
+
.catch(() => undefined);
|
|
40
|
+
const done = doneNow || data.state === "done";
|
|
41
|
+
return (_jsxs("article", { className: "grid gap-4", "aria-labelledby": "lesson-title", children: [_jsx("h1", { id: "lesson-title", className: "text-2xl font-semibold", children: lesson.title }), playback.data ? (_jsx("video", { ref: video, controls: true, playsInline: true, src: playback.data.hls, poster: playback.data.poster, className: "w-full rounded-lg", onLoadedMetadata: (e) => {
|
|
42
|
+
if (data.position)
|
|
43
|
+
e.currentTarget.currentTime = data.position;
|
|
44
|
+
}, onTimeUpdate: (e) => {
|
|
45
|
+
const at = e.currentTarget.currentTime;
|
|
46
|
+
if (Math.abs(at - kept.current) >= KEEP_EVERY) {
|
|
47
|
+
kept.current = at;
|
|
48
|
+
void keep();
|
|
49
|
+
}
|
|
50
|
+
}, onEnded: () => void keep("done") })) : null, lesson.kind === "video" && lesson.notes && renderText ? renderText(lesson.notes) : null, lesson.kind === "text" && renderText ? renderText(lesson.body) : null, lesson.kind === "download" && lesson.file ? (_jsxs("p", { children: [_jsx("a", { href: mediaPath(lesson.file), download: true, children: "Download" }), lesson.note ? ` · ${lesson.note}` : null] })) : null, lesson.kind === "session" && renderSession ? renderSession(courseId, lessonKey) : null, _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { variant: done ? "outline" : "default", onClick: () => void keep("done"), children: done ? "Done" : "Mark as done" }), data.next ? (_jsx(Button, { variant: "outline", onClick: () => data.next && onNext(data.next.key), children: `Next: ${data.next.title}` })) : null] }), playback.data?.captions.length ? (_jsxs("p", { className: "text-sm", children: ["Captions: ", playback.data.captions.map((c) => c.label).join(", ")] })) : null] }));
|
|
51
|
+
}
|