import { useState, useEffect } from 'react'; import { Trash2, Loader, AlertCircle, BookOpen, ArrowLeft, Eye, Clock, Layers, } from 'lucide-react'; import * as db from '../../lib/db'; import Card from '../ui/Card'; import Button from '../ui/Button'; import Tag from '../ui/Tag'; // Admin "Learning content" panel. // // The Learn flow stores generated content in the `theme_sessions` PB collection // — one record per (curriculum_version, week_number, theme). The legacy // per-topic `content` collection is no longer fed by the user-facing flow, so // this panel surfaces theme sessions instead. View shows the full session, // Delete removes the record (next visitor to that week will regenerate it). const ContentManager = () => { const [sessions, setSessions] = useState([]); const [loading, setLoading] = useState(true); const [selected, setSelected] = useState(null); const [busyId, setBusyId] = useState(null); const [error, setError] = useState(null); const refresh = async () => { setLoading(true); setError(null); try { const fresh = await db.getAllThemeSessions(); setSessions(fresh); if (selected) { const updated = fresh.find(s => s.id === selected.id); if (updated) setSelected(updated); else setSelected(null); } } catch (e) { setError(e.message); } finally { setLoading(false); } }; useEffect(() => { refresh(); }, []); const handleDelete = async (id) => { if (!confirm('Delete this theme session? The next learner to open this week will regenerate it with the AI.')) return; setBusyId(id); setError(null); try { await db.deleteThemeSession(id); if (selected?.id === id) setSelected(null); await refresh(); } catch (e) { setError(e.message); } finally { setBusyId(null); } }; // ─── Loading ────────────────────────────────────────────── if (loading && sessions.length === 0) { return (
Loading theme sessions…
No theme sessions generated yet.
When a learner opens the Learn page for a week with an active curriculum, its theme session is generated and cached here.
{error && (
{content.intro}