Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(academy): lesson navigation, duration formatting, and unrecorded videos (#642) (#1359)
Dhirender Choudhary566623cf1760
diff --git a/apps/academy/app/routes/course+/$moduleId.$courseId.tsx b/apps/academy/app/routes/course+/$moduleId.$courseId.tsxindex 1a088c46dd..76e22f5b08 100644--- a/apps/academy/app/routes/course+/$moduleId.$courseId.tsx+++ b/apps/academy/app/routes/course+/$moduleId.$courseId.tsx@@ -18,7 +18,7 @@ import {getNextLessonInCourse,toProgressSets} from "~/utils/progress";-import { formatDuration } from "~/utils/video";+import { formatDuration, isLessonComingSoon } from "~/utils/video";export const loader = async ({ params }: LoaderFunctionArgs) => {const { courseId } = params;@@ -50,6 +50,11 @@ export default function CourseRoute() {return acc + (topic.challenge === undefined ? 0 : 1);}, 0) ?? 0;+ // Counts every lesson listed below, including ones that aren't recorded yet —+ // `progress.lessonsTotal` only counts the ones that can actually be completed.+ const totalLessons =+ course?.topics.reduce((acc, topic) => acc + topic.lessons.length, 0) ?? 0;+if (!course || !module) {throw new Error("Course not found");}@@ -109,8 +114,8 @@ export default function CourseRoute() {<div className="flex items-center gap-5 font-mono text-ed-12 text-ed-ink/70"><span>{formatDuration(totalDuration)}</span><span>- {progress.lessonsTotal} lesson- {progress.lessonsTotal === 1 ? "" : "s"}+ {totalLessons} lesson+ {totalLessons === 1 ? "" : "s"}</span><span>{totalChallenges} challenge{totalChallenges === 1 ? "" : "s"}@@ -186,6 +191,7 @@ export default function CourseRoute() {name={lesson.name}duration={lesson.duration}completed={completedLessons.includes(lesson.id)}+ comingSoon={isLessonComingSoon(lesson)}tocAnchor/>))}@@ -204,6 +210,7 @@ export default function CourseRoute() {name={lesson.name}duration={lesson.duration}completed={completedLessons.includes(lesson.id)}+ comingSoon={isLessonComingSoon(lesson)}/>))}</div>@@ -263,12 +270,14 @@ function LessonRow({name,duration,completed,+ comingSoon,tocAnchor}: {lessonId: string;name: string;duration: number;completed: boolean;+ comingSoon?: boolean;tocAnchor?: boolean;}) {return (@@ -286,7 +295,7 @@ function LessonRow({</span></span><span className="shrink-0 font-mono text-ed-12 text-ed-ink/60">- {formatDuration(duration)}+ {comingSoon ? "Coming soon" : formatDuration(duration)}</span></Link>);diff --git a/apps/academy/app/routes/lesson+/$id.tsx b/apps/academy/app/routes/lesson+/$id.tsxindex 350716924b..221710674d 100644--- a/apps/academy/app/routes/lesson+/$id.tsx+++ b/apps/academy/app/routes/lesson+/$id.tsx@@ -3,7 +3,7 @@ import { getOrRefreshAuthSession } from "@carbon/auth/session.server";import { getLogger } from "@carbon/logger";import { Spinner } from "@carbon/react";import { useEffect } from "react";-import { LuCircleCheck, LuFlag } from "react-icons/lu";+import { LuCircleCheck, LuFlag, LuVideoOff } from "react-icons/lu";import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";import { data, Link, useFetcher, useParams } from "react-router";import { Breadcrumb } from "~/components/Breadcrumb";@@ -17,8 +17,11 @@ import { path } from "~/utils/path";import {formatDuration,getLessonContext,+ getLessonSiblings,+ getLoomEmbedId,getNextLesson,- getPreviousLesson+ getPreviousLesson,+ isLessonComingSoon} from "~/utils/video";const log = getLogger("academy");@@ -102,6 +105,9 @@ export default function LessonRoute() {const { module, course, topic, lesson } = context;const nextLesson = getNextLesson(id);const previousLesson = getPreviousLesson(id);+ const siblingLessons = getLessonSiblings(id) ?? topic.lessons;+ const embedId = getLoomEmbedId(lesson.loomUrl);+ const isComingSoon = isLessonComingSoon(lesson);const hasChallenge = topic.challenge && topic.challenge.length > 0;const completedLessons = lessonCompletions@@ -196,7 +202,7 @@ export default function LessonRoute() {</span><span className="inline-flex items-center gap-[5px] font-mono text-ed-12 leading-4 text-ed-ink/42"><ClockIcon />- {formatDuration(lesson.duration)}+ {isComingSoon ? "Coming soon" : formatDuration(lesson.duration)}</span></div>@@ -212,25 +218,38 @@ export default function LessonRoute() {height: "0"}}>- <div className="absolute inset-0 flex items-center justify-center">- <Spinner className="h-8 w-8 text-white/70" />- </div>- <iframe- key={id}- id="loom-embed"- title={lesson.name}- src={`https://www.loom.com/embed/${- lesson.loomUrl.split(/(?:share|embed)\//)[1]?.split("?")[0]- }?hideEmbedTopBar=true`}- allowFullScreen- style={{- position: "absolute",- top: 0,- left: 0,- width: "100%",- height: "100%"- }}- />+ {isComingSoon || !embedId ? (+ <div className="absolute inset-0 flex flex-col items-center justify-center gap-2 px-6 text-center">+ <LuVideoOff className="size-6 text-white/50" />+ <p className="font-mono text-ed-12 font-semibold uppercase tracking-[0.08em] text-white/70">+ Coming soon+ </p>+ <p className="max-w-sm text-ed-14 text-white/50">+ This lesson hasn't been recorded yet. The rest of the+ course is ready to watch.+ </p>+ </div>+ ) : (+ <>+ <div className="absolute inset-0 flex items-center justify-center">+ <Spinner className="h-8 w-8 text-white/70" />+ </div>+ <iframe+ key={id}+ id="loom-embed"+ title={lesson.name}+ src={`https://www.loom.com/embed/${embedId}?hideEmbedTopBar=true`}+ allowFullScreen+ style={{+ position: "absolute",+ top: 0,+ left: 0,+ width: "100%",+ height: "100%"+ }}+ />+ </>+ )}</div></div>@@ -273,10 +292,12 @@ export default function LessonRoute() {<div><p className="mb-2 px-1 font-mono text-ed-11 font-semibold uppercase tracking-[0.08em] text-ed-ink/50">- Lessons in this topic+ {context.lessonType === "supplemental"+ ? "Supplemental videos"+ : "Lessons in this topic"}</p><div className="flex flex-col gap-0.5">- {topic.lessons.map((topicLesson) => {+ {siblingLessons.map((topicLesson) => {const isCompleted = completedLessons.includes(topicLesson.id);const isCurrent = topicLesson.id === lesson.id;return (@@ -294,7 +315,9 @@ export default function LessonRoute() {<span className="truncate">{topicLesson.name}</span></span><span className="shrink-0 font-mono text-ed-11 text-ed-ink/60">- {formatDuration(topicLesson.duration)}+ {isLessonComingSoon(topicLesson)+ ? "Soon"+ : formatDuration(topicLesson.duration)}</span></Link>);diff --git a/apps/academy/app/utils/progress.ts b/apps/academy/app/utils/progress.tsindex c0344f9f18..08136b407d 100644--- a/apps/academy/app/utils/progress.ts+++ b/apps/academy/app/utils/progress.ts@@ -1,4 +1,5 @@import { modules } from "~/config";+import { isLessonComingSoon } from "~/utils/video";type Module = (typeof modules)[number];type Course = Module["courses"][number];@@ -39,6 +40,7 @@ export function getCourseProgress(for (const topic of course.topics) {for (const lesson of topic.lessons) {+ if (isLessonComingSoon(lesson)) continue;lessonsTotal += 1;if (completedLessonIds.has(lesson.id)) lessonsDone += 1;}@@ -95,6 +97,7 @@ export function getResumeLesson(for (const course of module.courses) {for (const topic of course.topics) {for (const lesson of topic.lessons) {+ if (isLessonComingSoon(lesson)) continue;if (!completedLessonIds.has(lesson.id)) {return { module, course, topic, lesson };}@@ -112,6 +115,7 @@ export function getNextLessonInCourse(): Lesson | null {for (const topic of course.topics) {for (const lesson of topic.lessons) {+ if (isLessonComingSoon(lesson)) continue;if (!completedLessonIds.has(lesson.id)) return lesson;}}diff --git a/apps/academy/app/utils/video.ts b/apps/academy/app/utils/video.tsindex 666d11e088..2611a8a65d 100644--- a/apps/academy/app/utils/video.ts+++ b/apps/academy/app/utils/video.ts@@ -1,11 +1,45 @@import { modules } from "~/config";export function formatDuration(duration: number) {- const minutes = Math.floor(duration / 60);- const seconds = duration % 60;+ const total = Number.isFinite(duration)+ ? Math.max(0, Math.floor(duration))+ : 0;+ const hours = Math.floor(total / 3600);+ const minutes = Math.floor((total % 3600) / 60);+ const seconds = total % 60;++ if (hours > 0) {+ return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds+ .toString()+ .padStart(2, "0")}`;+ }+return `${minutes}:${seconds.toString().padStart(2, "0")}`;}+/**+ * Pull the video id out of a Loom share/embed URL. Returns null when the URL is+ * missing or doesn't contain a `/share/` or `/embed/` segment, so callers can+ * render a fallback instead of an `embed/undefined` iframe.+ */+export function getLoomEmbedId(loomUrl: string | null | undefined) {+ if (!loomUrl) return null;+ const id = loomUrl.split(/(?:share|embed)\//)[1]?.split("?")[0];+ return id ? id : null;+}++/**+ * A lesson that has no recorded video yet. Placeholder entries carry+ * `duration: 0` (and share a stand-in Loom URL), so they're shown as "coming+ * soon" rather than embedded, and are left out of progress and navigation.+ */+export function isLessonComingSoon(lesson: {+ duration: number;+ loomUrl?: string | null;+}) {+ return lesson.duration <= 0 || getLoomEmbedId(lesson.loomUrl) === null;+}+export function findTopicContext(topicId: string) {for (const module of modules) {for (const course of module.courses) {@@ -63,32 +97,45 @@ export function getLessonContext(lessonId: string) {return null;}-export function getNextLesson(lessonId: string) {+/**+ * The list a lesson is navigated within: the topic's core lessons, or its+ * supplemental videos when the lesson is supplemental. Supplemental lessons are+ * a separate track, so they page through each other rather than the core path.+ */+export function getLessonSiblings(lessonId: string) {const context = getLessonContext(lessonId);if (!context) return null;- const { topic } = context;- const allLessons = topic.lessons;- const currentIndex = allLessons.findIndex((lesson) => lesson.id === lessonId);+ return context.lessonType === "supplemental"+ ? (context.topic.supplemental ?? [])+ : context.topic.lessons;+}- if (currentIndex === -1 || currentIndex === allLessons.length - 1) {- return null;- }+export function getNextLesson(lessonId: string) {+ const siblings = getLessonSiblings(lessonId);+ if (!siblings) return null;++ const currentIndex = siblings.findIndex((lesson) => lesson.id === lessonId);+ if (currentIndex === -1) return null;- return allLessons[currentIndex + 1];+ return (+ siblings+ .slice(currentIndex + 1)+ .find((lesson) => !isLessonComingSoon(lesson)) ?? null+ );}export function getPreviousLesson(lessonId: string) {- const context = getLessonContext(lessonId);- if (!context) return null;+ const siblings = getLessonSiblings(lessonId);+ if (!siblings) return null;- const { topic } = context;- const allLessons = topic.lessons;- const currentIndex = allLessons.findIndex((lesson) => lesson.id === lessonId);-- if (currentIndex <= 0) {- return null;- }+ const currentIndex = siblings.findIndex((lesson) => lesson.id === lessonId);+ if (currentIndex <= 0) return null;- return allLessons[currentIndex - 1];+ return (+ siblings+ .slice(0, currentIndex)+ .reverse()+ .find((lesson) => !isLessonComingSoon(lesson)) ?? null+ );}