nomadro/apps/nomadvip/lib/content/course-utils.ts
eric 56b29205e7 Integrate four verticals into nomadro portal with shared packages and API gateway.
Mount /vip with nomadvip+payjsapi, add @nomadro/pay|pb|sdk, apps/api, /admin shell, and backup/rollback scripts under git.nomadro.cn workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 20:16:44 -05:00

27 lines
787 B
TypeScript

/**
* 课程工具 - 获取上一节/下一节
*/
export type LessonRef = { moduleIndex: number; lessonIndex: number };
export function getPrevNextLesson(
modules: readonly { lessons: readonly unknown[] }[],
moduleIndex: number,
lessonIndex: number
): { prev: LessonRef | null; next: LessonRef | null } {
const allLessons: LessonRef[] = [];
modules.forEach((m, mi) => {
m.lessons.forEach((_, li) => {
allLessons.push({ moduleIndex: mi, lessonIndex: li });
});
});
const idx = allLessons.findIndex((l) => l.moduleIndex === moduleIndex && l.lessonIndex === lessonIndex);
if (idx < 0) return { prev: null, next: null };
return {
prev: idx > 0 ? allLessons[idx - 1] : null,
next: idx < allLessons.length - 1 ? allLessons[idx + 1] : null,
};
}