/** * Question Bank Page - View all questions */ import React, { useState, useEffect } from 'react' import { questionAPI } from '../api/client' import Layout from '../components/Layout' import Pagination from '../components/Pagination' import { FileText, Loader, Search } from 'lucide-react' import toast from 'react-hot-toast' import { getQuestionTypeText, formatRelativeTime } from '../utils/helpers' export const QuestionBank = () => { const [questions, setQuestions] = useState([]) const [loading, setLoading] = useState(true) const [expandedId, setExpandedId] = useState(null) // Pagination const [page, setPage] = useState(1) const [limit, setLimit] = useState(10) const [total, setTotal] = useState(0) useEffect(() => { loadQuestions() }, [page, limit]) const loadQuestions = async () => { try { setLoading(true) const skip = (page - 1) * limit const response = await questionAPI.getAll(skip, limit) setQuestions(response.data.questions) setTotal(response.data.total) } catch (error) { console.error('Failed to load questions:', error) toast.error('加载题库失败') } finally { setLoading(false) } } const toggleExpand = (id) => { setExpandedId(expandedId === id ? null : id) } if (loading && questions.length === 0) { return (
) } return (
{/* Header */}

全站题库

共 {total} 道题目

{/* List */}
{questions.map((q) => { const isExpanded = expandedId === q.id return (
toggleExpand(q.id)} >
{getQuestionTypeText(q.type)} ID: {q.id} {formatRelativeTime(q.created_at)}

{q.content}

{isExpanded && (
{/* Options */} {q.options && q.options.length > 0 && (
{q.options.map((opt, i) => (
{opt}
))}
)} {/* Answer */}

正确答案

{q.answer}

{/* Analysis */} {q.analysis && (

解析

{q.analysis}

)}
)}
) })}
{/* Pagination */} { setLimit(newLimit) setPage(1) }} />
) } export default QuestionBank