Polish UX: auto-redirect on create, fix design consistency
- createModule now redirects to module page after creation - createLesson now redirects to lesson editor after creation - Regenerate Prisma client to fix missing types (category, accessLog, expiresAt) - Rewrite sortable-modules/lessons with Second Brain design tokens (remove amber/slate) - Rewrite lesson-editor toolbar and toggle with design tokens - Fix register page/form: replace amber theme with card-aubade design Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,6 @@ import {
|
||||
} from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { createModule, deleteModule, updateModule, reorderModules } from "@/app/admin/courses/[courseId]/actions";
|
||||
|
||||
interface Module {
|
||||
@@ -28,14 +26,9 @@ interface Module {
|
||||
_count: { lessons: number };
|
||||
}
|
||||
|
||||
function SortableModule({
|
||||
mod,
|
||||
courseId,
|
||||
}: {
|
||||
mod: Module;
|
||||
courseId: string;
|
||||
}) {
|
||||
function SortableModule({ mod, courseId }: { mod: Module; courseId: string }) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [editValue, setEditValue] = useState(mod.title);
|
||||
const [pending, startTransition] = useTransition();
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
|
||||
useSortable({ id: mod.id });
|
||||
@@ -43,7 +36,7 @@ function SortableModule({
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0.5 : 1,
|
||||
opacity: isDragging ? 0.4 : 1,
|
||||
};
|
||||
|
||||
function handleUpdate(e: React.FormEvent<HTMLFormElement>) {
|
||||
@@ -59,30 +52,72 @@ function SortableModule({
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={setNodeRef} style={style} className="flex items-center gap-3 bg-slate-50 border border-slate-200 rounded-xl px-4 py-3">
|
||||
<button type="button" {...attributes} {...listeners} className="text-slate-300 hover:text-slate-500 cursor-grab active:cursor-grabbing">
|
||||
⋮⋮
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
style={{ ...style, border: "2px solid var(--border)", background: "var(--color-surface)" }}
|
||||
className="flex items-center gap-3 px-4 py-3"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
className="cursor-grab active:cursor-grabbing text-lg select-none"
|
||||
style={{ color: "var(--muted-foreground)" }}
|
||||
aria-label="Перетащить"
|
||||
>
|
||||
⠿
|
||||
</button>
|
||||
|
||||
{editing ? (
|
||||
<form onSubmit={handleUpdate} className="flex items-center gap-2 flex-1">
|
||||
<Input name="title" defaultValue={mod.title} autoFocus className="h-8 text-sm" />
|
||||
<Button type="submit" size="sm" disabled={pending}>Сохранить</Button>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={() => setEditing(false)}>Отмена</Button>
|
||||
<input
|
||||
name="title"
|
||||
value={editValue}
|
||||
onChange={(e) => setEditValue(e.target.value)}
|
||||
autoFocus
|
||||
required
|
||||
className="flex-1 px-2 py-1 text-sm"
|
||||
style={{ border: "2px solid var(--foreground)", background: "var(--background)", outline: "none" }}
|
||||
/>
|
||||
<button type="submit" disabled={pending} className="btn-aubade text-xs px-3 py-1">
|
||||
Сохранить
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { setEditing(false); setEditValue(mod.title); }}
|
||||
className="text-xs px-3 py-1"
|
||||
style={{ color: "var(--muted-foreground)" }}
|
||||
>
|
||||
Отмена
|
||||
</button>
|
||||
</form>
|
||||
) : (
|
||||
<>
|
||||
<span className="flex-1 font-medium text-slate-700">{mod.title}</span>
|
||||
<span className="text-sm text-slate-400">{mod._count.lessons} уроков</span>
|
||||
<span className="flex-1 font-medium text-sm">{mod.title}</span>
|
||||
<span className="text-xs" style={{ color: "var(--muted-foreground)" }}>
|
||||
{mod._count.lessons} {mod._count.lessons === 1 ? "урок" : mod._count.lessons < 5 ? "урока" : "уроков"}
|
||||
</span>
|
||||
<Link
|
||||
href={`/admin/courses/${courseId}/modules/${mod.id}`}
|
||||
className="text-xs text-amber-600 hover:underline"
|
||||
className="btn-aubade text-xs px-3 py-1"
|
||||
>
|
||||
Уроки
|
||||
Уроки →
|
||||
</Link>
|
||||
<button type="button" onClick={() => setEditing(true)} className="text-xs text-slate-500 hover:text-slate-700">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing(true)}
|
||||
className="text-xs"
|
||||
style={{ color: "var(--muted-foreground)" }}
|
||||
>
|
||||
Переименовать
|
||||
</button>
|
||||
<button type="button" onClick={handleDelete} disabled={pending} className="text-xs text-red-400 hover:text-red-600">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleDelete}
|
||||
disabled={pending}
|
||||
className="text-xs"
|
||||
style={{ color: "oklch(0.577 0.245 27.325)" }}
|
||||
>
|
||||
Удалить
|
||||
</button>
|
||||
</>
|
||||
@@ -93,7 +128,7 @@ function SortableModule({
|
||||
|
||||
export function SortableModules({ courseId, modules }: { courseId: string; modules: Module[] }) {
|
||||
const [items, setItems] = useState(modules);
|
||||
const [, startTransition] = useTransition();
|
||||
const [creating, startTransition] = useTransition();
|
||||
|
||||
const sensors = useSensors(useSensor(PointerSensor));
|
||||
|
||||
@@ -116,7 +151,7 @@ export function SortableModules({ courseId, modules }: { courseId: string; modul
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-2">
|
||||
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
|
||||
<SortableContext items={items.map((m) => m.id)} strategy={verticalListSortingStrategy}>
|
||||
{items.map((mod) => (
|
||||
@@ -126,12 +161,25 @@ export function SortableModules({ courseId, modules }: { courseId: string; modul
|
||||
</DndContext>
|
||||
|
||||
{items.length === 0 && (
|
||||
<p className="text-sm text-slate-400 py-2">Модулей пока нет. Добавьте первый.</p>
|
||||
<p className="text-sm py-3" style={{ color: "var(--muted-foreground)" }}>
|
||||
Модулей пока нет. Добавьте первый.
|
||||
</p>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleCreate} className="flex gap-2 pt-2">
|
||||
<Input name="title" placeholder="Название нового модуля" required className="max-w-xs" />
|
||||
<Button type="submit">+ Модуль</Button>
|
||||
<form onSubmit={handleCreate} className="flex gap-2 pt-3">
|
||||
<input
|
||||
name="title"
|
||||
placeholder="Название нового модуля"
|
||||
required
|
||||
disabled={creating}
|
||||
className="flex-1 max-w-xs px-3 py-2 text-sm"
|
||||
style={{ border: "2px solid var(--border)", background: "var(--background)", outline: "none" }}
|
||||
onFocus={(e) => (e.currentTarget.style.borderColor = "var(--foreground)")}
|
||||
onBlur={(e) => (e.currentTarget.style.borderColor = "var(--border)")}
|
||||
/>
|
||||
<button type="submit" disabled={creating} className="btn-aubade text-xs px-4 py-2">
|
||||
{creating ? "Создание..." : "+ Модуль"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user