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 <noreply@anthropic.com>
This commit is contained in:
2026-05-26 11:05:46 +05:00
parent f3428420e2
commit 287347168d
3 changed files with 28 additions and 20 deletions
@@ -107,6 +107,18 @@ export default async function LessonPage({ params }: Props) {
return (
<article className="max-w-3xl mx-auto px-6 py-8">
{/* Admin edit bar */}
{isAdmin && (
<div className="flex items-center justify-end mb-4">
<Link
href={`/admin/courses/${lesson.module.course.id}/modules/${lesson.moduleId}/lessons/${lessonId}`}
className="btn-aubade text-xs px-3 py-1.5"
>
Редактировать урок
</Link>
</div>
)}
{/* Title */}
<h1 className="text-2xl font-bold mb-6 leading-snug">{lesson.title}</h1>
@@ -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}
/>
</div>