d0c8c6dd53
- Toggle lesson completion via server action (LessonProgress table) - "Отметить как пройденный" button on lesson page, turns accent when done - Course sidebar: progress bar, checkmarks on completed lessons, X/Y counter per module - Dashboard: progress bar on each course card with completion percentage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
30 lines
901 B
TypeScript
30 lines
901 B
TypeScript
"use server";
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import { auth } from "@/lib/auth";
|
|
import { headers } from "next/headers";
|
|
import { revalidatePath } from "next/cache";
|
|
|
|
export async function toggleLessonProgress(lessonId: string, slug: string) {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session) throw new Error("Unauthorized");
|
|
|
|
const existing = await prisma.lessonProgress.findUnique({
|
|
where: { userId_lessonId: { userId: session.user.id, lessonId } },
|
|
});
|
|
|
|
if (existing) {
|
|
await prisma.lessonProgress.delete({
|
|
where: { userId_lessonId: { userId: session.user.id, lessonId } },
|
|
});
|
|
} else {
|
|
await prisma.lessonProgress.create({
|
|
data: { userId: session.user.id, lessonId },
|
|
});
|
|
}
|
|
|
|
revalidatePath(`/courses/${slug}/lessons/${lessonId}`);
|
|
revalidatePath(`/courses/${slug}`);
|
|
revalidatePath("/dashboard");
|
|
}
|