Add coverImage poster to player, fix TipTap v3 editor reset, quiz admin preview
- Add coverImage field to Lesson model (prisma) - Pass coverImage as poster prop to KinescopePlayer - Show quiz in read-only preview mode for admin on lesson page - Fix TipTap v3 editor reset on save: pass [lesson.id] as deps to useEditor to prevent setOptions() from reinitializing content on every re-render - Replace saveLesson Server Action call with fetch PATCH /api/admin/lessons/[id] to avoid Next.js 16 automatic RSC refresh after Server Actions - Simplify revalidatePath: only revalidate module page, not lesson editor page
This commit is contained in:
@@ -113,7 +113,7 @@ export default async function LessonPage({ params }: Props) {
|
||||
{/* Video */}
|
||||
{lesson.kinescopeId && (
|
||||
<div className="mb-8">
|
||||
<KinescopePlayer videoId={lesson.kinescopeId} />
|
||||
<KinescopePlayer videoId={lesson.kinescopeId} poster={lesson.coverImage ?? undefined} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -180,17 +180,30 @@ export default async function LessonPage({ params }: Props) {
|
||||
)}
|
||||
|
||||
{/* Quiz */}
|
||||
{lesson.quiz && !isAdmin && (
|
||||
{lesson.quiz && (
|
||||
<div className="mb-8">
|
||||
<p className="text-xs font-bold uppercase tracking-widest mb-3" style={{ color: "var(--muted-foreground)" }}>
|
||||
Тест
|
||||
Тест{isAdmin && <span className="ml-2 opacity-50">(предпросмотр)</span>}
|
||||
</p>
|
||||
<QuizSection
|
||||
quiz={lesson.quiz}
|
||||
attempt={quizAttempt ? { answers: quizAttempt.answers as Record<string, string> } : null}
|
||||
slug={slug}
|
||||
lessonId={lessonId}
|
||||
/>
|
||||
{isAdmin ? (
|
||||
<div className="space-y-4 opacity-70">
|
||||
{lesson.quiz.questions.map((q, idx) => (
|
||||
<div key={q.id} className="space-y-1">
|
||||
<p className="text-sm font-medium">{idx + 1}. {q.text}</p>
|
||||
<div className="px-4 py-3 text-sm" style={{ border: "2px solid var(--border)", color: "var(--muted-foreground)" }}>
|
||||
Поле для ответа студента
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<QuizSection
|
||||
quiz={lesson.quiz}
|
||||
attempt={quizAttempt ? { answers: quizAttempt.answers as Record<string, string> } : null}
|
||||
slug={slug}
|
||||
lessonId={lessonId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ lessonId: string }> }
|
||||
) {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session || session.user.role !== "admin") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const { lessonId } = await params;
|
||||
const body = await req.json() as {
|
||||
title: string;
|
||||
kinescopeId: string;
|
||||
content: object;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
await prisma.lesson.update({
|
||||
where: { id: lessonId },
|
||||
data: {
|
||||
title: body.title,
|
||||
kinescopeId: body.kinescopeId || null,
|
||||
content: body.content,
|
||||
published: body.published,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
Reference in New Issue
Block a user