import React, { useState, useEffect } from 'react'; import { RefreshCw, Trash2, CheckCircle, Loader, AlertCircle, HelpCircle, ArrowLeft, Eye, ChevronDown, ChevronUp } from 'lucide-react'; import { forceGenerateTopicQuestions, getTopicQuestionBank, deleteQuestion } from '../../lib/testService'; import * as db from '../../lib/db'; import Card from '../ui/Card'; import Button from '../ui/Button'; import Tag from '../ui/Tag'; import { motion, AnimatePresence } from 'framer-motion'; const TestManager = () => { const [topics, setTopics] = useState([]); const [questionCounts, setQuestionCounts] = useState({}); const [selectedTopic, setSelectedTopic] = useState(null); const [questions, setQuestions] = useState([]); const [loadingTopicId, setLoadingTopicId] = useState(null); const [error, setError] = useState(null); const loadData = async () => { const allTopics = await db.getTopics(); setTopics(allTopics); const counts = {}; await Promise.all(allTopics.map(async t => { const bank = await getTopicQuestionBank(t.id); counts[t.id] = bank.length; })); setQuestionCounts(counts); if (selectedTopic) { setQuestions(await getTopicQuestionBank(selectedTopic.id)); } }; useEffect(() => { loadData(); }, [selectedTopic]); const handleGenerate = async (topic, count = 10) => { setLoadingTopicId(topic.id); setError(null); try { await forceGenerateTopicQuestions(topic, count); loadData(); // refresh list } catch (e) { setError(e.message); } finally { setLoadingTopicId(null); } }; const handleDelete = (topicId, questionId) => { deleteQuestion(topicId, questionId); loadData(); }; // ── Detail view ── if (selectedTopic) { return (
{selectedTopic.description}
No questions generated for this topic yet.
{q.explanation}
No topics available.
{topic.description}