'use client' import { useState, useEffect } from 'react' import { Navigation } from '@/components/Navigation' import { FlipMemoryTest, VocabChoiceTest, SentenceFillTest, SentenceReorderTest, VocabListeningTest, SentenceListeningTest, SentenceSpeakingTest } from '@/components/review/review-tests' import exampleData from './example-data.json' export default function ReviewTestsPage() { const [logs, setLogs] = useState([]) const [activeTab, setActiveTab] = useState('FlipMemoryTest') const [currentCardIndex, setCurrentCardIndex] = useState(0) // 測驗組件清單 const testComponents = [ { id: 'FlipMemoryTest', name: '翻卡記憶測試', color: 'bg-blue-50' }, { id: 'VocabChoiceTest', name: '詞彙選擇測試', color: 'bg-green-50' }, { id: 'SentenceFillTest', name: '句子填空測試', color: 'bg-yellow-50' }, { id: 'SentenceReorderTest', name: '句子重排測試', color: 'bg-purple-50' }, { id: 'VocabListeningTest', name: '詞彙聽力測試', color: 'bg-red-50' }, { id: 'SentenceListeningTest', name: '句子聽力測試', color: 'bg-indigo-50' }, { id: 'SentenceSpeakingTest', name: '句子口說測試', color: 'bg-pink-50' } ] // 添加日誌函數 const addLog = (message: string) => { const timestamp = new Date().toLocaleTimeString() setLogs(prev => [`[${activeTab}] [${timestamp}] ${message}`, ...prev.slice(0, 9)]) } // 從 API 響應格式獲取當前卡片資料 const flashcardsData = exampleData.data || [] const currentCard = flashcardsData[currentCardIndex] || flashcardsData[0] // 轉換為組件所需格式 const mockCardData = currentCard ? { word: currentCard.word, definition: currentCard.definition, example: currentCard.example, filledQuestionText: currentCard.filledQuestionText, exampleTranslation: currentCard.exampleTranslation, pronunciation: currentCard.pronunciation, difficultyLevel: currentCard.difficultyLevel, translation: currentCard.translation, // 從 flashcardExampleImages 提取圖片URL exampleImage: currentCard.flashcardExampleImages?.[0]?.exampleImage ? `http://localhost:5008/images/examples/${currentCard.flashcardExampleImages[0].exampleImage.relativePath}` : undefined } : { word: "loading...", definition: "Loading...", example: "Loading...", filledQuestionText: undefined, exampleTranslation: "載入中...", pronunciation: "", difficultyLevel: "A1", translation: "載入中", exampleImage: undefined } // 選項題選項 - 從資料中生成 const generateVocabChoiceOptions = () => { if (!currentCard) return ["loading"] const correctAnswer = currentCard.word const otherWords = flashcardsData .filter(card => card.word !== correctAnswer) .slice(0, 3) .map(card => card.word) return [correctAnswer, ...otherWords].sort(() => Math.random() - 0.5) } const vocabChoiceOptions = generateVocabChoiceOptions() // 回調函數 const handleConfidenceSubmit = (level: number) => { addLog(`FlipMemoryTest: 信心等級 ${level}`) } const handleAnswer = (answer: string) => { addLog(`答案提交: ${answer}`) } const handleReportError = () => { addLog('回報錯誤') } const handleImageClick = (image: string) => { addLog(`圖片點擊: ${image}`) } return (
{/* 頁面標題 */}

Review 組件設計

所有 review-tests 組件的 UI 設計頁面

{/* 卡片切換控制 */}
卡片 {currentCardIndex + 1} / {flashcardsData.length} - {currentCard?.word || 'loading'}
{/* Tab 導航 */}
{testComponents.map((component) => ( ))}
{/* 當前測驗組件展示 */}

{activeTab}

{testComponents.find(c => c.id === activeTab)?.name}

{/* 條件渲染當前選中的測驗組件 */} {activeTab === 'FlipMemoryTest' && ( )} {activeTab === 'VocabChoiceTest' && ( )} {activeTab === 'SentenceFillTest' && ( )} {activeTab === 'SentenceReorderTest' && ( )} {activeTab === 'VocabListeningTest' && ( )} {activeTab === 'SentenceListeningTest' && ( )} {activeTab === 'SentenceSpeakingTest' && ( )}
{/* 操作日誌區域 */}

操作日誌

{logs.length === 0 ? (

無操作記錄

) : ( logs.map((log, index) => (
{log}
)) )}
) }