feat(frontend): admin lesson tree CRUD
This commit is contained in:
29
packages/frontend/src/pages/Admin.tsx
Normal file
29
packages/frontend/src/pages/Admin.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { lessonsApi } from '../api/lessons.js';
|
||||
import { useLessons } from '../stores/lessonsStore.js';
|
||||
import { LessonTree } from '../components/LessonTree.js';
|
||||
|
||||
export function AdminPage() {
|
||||
const { tree, refresh, loading } = useLessons();
|
||||
const [newRoot, setNewRoot] = useState('');
|
||||
|
||||
useEffect(() => { refresh(); }, [refresh]);
|
||||
|
||||
async function addRoot() {
|
||||
if (!newRoot.trim()) return;
|
||||
await lessonsApi.create({ name: newRoot.trim(), parentId: null });
|
||||
setNewRoot('');
|
||||
await refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-3xl p-6">
|
||||
<h1 className="mb-4 text-2xl font-semibold">Lessen beheer</h1>
|
||||
<div className="mb-4 flex gap-2">
|
||||
<input className="flex-1 rounded border px-3 py-2 dark:bg-slate-900" placeholder="Nieuwe wortel-les..." value={newRoot} onChange={(e) => setNewRoot(e.target.value)} />
|
||||
<button className="rounded bg-blue-600 px-4 py-2 text-white" onClick={addRoot}>Toevoegen</button>
|
||||
</div>
|
||||
{loading ? <p>Laden...</p> : <LessonTree nodes={tree} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user