From 287347168d9bd0309fc9177e1bdd741828b52dcb Mon Sep 17 00:00:00 2001 From: dmitriylaukhin Date: Tue, 26 May 2026 11:05:46 +0500 Subject: [PATCH] Add cross-module lesson navigation and admin edit button - Admin lesson editor now navigates across module boundaries (full course flat list) - Student lesson view shows "Edit" button for admins linking to lesson editor Co-Authored-By: Claude Sonnet 4.6 --- .../[slug]/lessons/[lessonId]/page.tsx | 12 +++++++++++ .../[moduleId]/lessons/[lessonId]/page.tsx | 21 ++++++++----------- src/components/admin/lesson-editor.tsx | 15 +++++++------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx b/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx index 9bb4a0c..127a158 100644 --- a/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx +++ b/src/app/(student)/courses/[slug]/lessons/[lessonId]/page.tsx @@ -107,6 +107,18 @@ export default async function LessonPage({ params }: Props) { return (
+ {/* Admin edit bar */} + {isAdmin && ( +
+ + Редактировать урок + +
+ )} + {/* Title */}

{lesson.title}

diff --git a/src/app/admin/courses/[courseId]/modules/[moduleId]/lessons/[lessonId]/page.tsx b/src/app/admin/courses/[courseId]/modules/[moduleId]/lessons/[lessonId]/page.tsx index 8335c6d..5fd41ac 100644 --- a/src/app/admin/courses/[courseId]/modules/[moduleId]/lessons/[lessonId]/page.tsx +++ b/src/app/admin/courses/[courseId]/modules/[moduleId]/lessons/[lessonId]/page.tsx @@ -13,7 +13,7 @@ interface Props { export default async function LessonEditorPage({ params }: Props) { const { courseId, moduleId, lessonId } = await params; - const [lesson, siblings] = await Promise.all([ + const [lesson, allCourseLessons] = await Promise.all([ prisma.lesson.findUnique({ where: { id: lessonId }, include: { @@ -28,29 +28,27 @@ export default async function LessonEditorPage({ params }: Props) { }, }), prisma.lesson.findMany({ - where: { moduleId }, - orderBy: { order: "asc" }, - select: { id: true, title: true }, + where: { module: { courseId } }, + orderBy: [{ module: { order: "asc" } }, { order: "asc" }], + select: { id: true, title: true, moduleId: true }, }), ]); if (!lesson || lesson.moduleId !== moduleId) notFound(); - const idx = siblings.findIndex((l) => l.id === lessonId); - const prevLesson = idx > 0 ? siblings[idx - 1] : null; - const nextLesson = idx < siblings.length - 1 ? siblings[idx + 1] : null; + const idx = allCourseLessons.findIndex((l) => l.id === lessonId); + const prevLesson = idx > 0 ? allCourseLessons[idx - 1] : null; + const nextLesson = idx < allCourseLessons.length - 1 ? allCourseLessons[idx + 1] : null; // Serialize all Prisma proxy objects (DateTime, relations) before passing to Client Components const plain = JSON.parse(JSON.stringify({ files: lesson.files, homework: lesson.homework, quiz: lesson.quiz, - siblings, })) as { files: typeof lesson.files; homework: typeof lesson.homework; quiz: typeof lesson.quiz; - siblings: typeof siblings; }; return ( @@ -76,10 +74,9 @@ export default async function LessonEditorPage({ params }: Props) { published: lesson.published, }} courseId={courseId} - moduleId={moduleId} courseSlug={lesson.module.course.slug} - prevLesson={plain.siblings[idx - 1] ?? null} - nextLesson={plain.siblings[idx + 1] ?? null} + prevLesson={prevLesson} + nextLesson={nextLesson} /> diff --git a/src/components/admin/lesson-editor.tsx b/src/components/admin/lesson-editor.tsx index 314101e..c0e1fd5 100644 --- a/src/components/admin/lesson-editor.tsx +++ b/src/components/admin/lesson-editor.tsx @@ -21,19 +21,18 @@ interface LessonData { interface SiblingLesson { id: string; title: string; + moduleId: string; } export function LessonEditor({ lesson, courseId, - moduleId, courseSlug, prevLesson, nextLesson, }: { lesson: LessonData; courseId: string; - moduleId: string; courseSlug: string; prevLesson?: SiblingLesson | null; nextLesson?: SiblingLesson | null; @@ -156,8 +155,8 @@ export function LessonEditor({ } } - function navigateTo(lessonId: string) { - router.push(`/admin/courses/${courseId}/modules/${moduleId}/lessons/${lessonId}`); + function navigateTo(target: SiblingLesson) { + router.push(`/admin/courses/${courseId}/modules/${target.moduleId}/lessons/${target.id}`); } return ( @@ -213,18 +212,18 @@ export function LessonEditor({