diff --git a/src/components/admin/TestManager.jsx b/src/components/admin/TestManager.jsx index 5cb3482..c0ff053 100644 --- a/src/components/admin/TestManager.jsx +++ b/src/components/admin/TestManager.jsx @@ -9,17 +9,25 @@ 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 = () => { - const allTopics = storage.get('kb:topics', []); + 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(getTopicQuestionBank(selectedTopic.id)); + setQuestions(await getTopicQuestionBank(selectedTopic.id)); } }; @@ -157,8 +165,7 @@ const TestManager = () => { )} {topics.map(topic => { - const bank = getTopicQuestionBank(topic.id); - const count = bank.length; + const count = questionCounts[topic.id] || 0; const isLoading = loadingTopicId === topic.id; return ( diff --git a/src/pages/Leren.jsx b/src/pages/Leren.jsx index 9454da7..87c9376 100644 --- a/src/pages/Leren.jsx +++ b/src/pages/Leren.jsx @@ -91,7 +91,7 @@ const Leren = () => { setError(null); try { const newTopic = await generateCustomTopic(customTopicQuery); - setAllTopics(storage.get('kb:topics', [])); + setAllTopics(await db.getTopics()); setCustomTopicQuery(''); handleOpenTopic(newTopic); } catch (e) {