import { useState, useRef, useEffect } from 'react' import { ConfidenceTestProps, ReviewCardData } from '@/types/review' import { useReviewLogic } from '@/hooks/useReviewLogic' import { CardHeader, AudioSection, ConfidenceButtons, ErrorReportButton } from '@/components/review/shared' // 優化後的 FlipMemoryTest 組件 export const FlipMemoryTestNew: React.FC = ({ cardData, onAnswer, onConfidenceSubmit, onReportError, disabled = false }) => { // 使用共用邏輯 Hook const { confidence, submitConfidence, generateResult } = useReviewLogic({ cardData, testType: 'FlipMemoryTest' }) // 翻卡特定狀態 const [isFlipped, setIsFlipped] = useState(false) const [cardHeight, setCardHeight] = useState(400) const frontRef = useRef(null) const backRef = useRef(null) // 動態計算卡片高度 useEffect(() => { const updateCardHeight = () => { if (backRef.current) { const backHeight = backRef.current.scrollHeight const minHeightByScreen = window.innerWidth <= 480 ? 300 : window.innerWidth <= 768 ? 350 : 400 const finalHeight = Math.max(minHeightByScreen, backHeight) setCardHeight(finalHeight) } } setTimeout(updateCardHeight, 100) window.addEventListener('resize', updateCardHeight) return () => window.removeEventListener('resize', updateCardHeight) }, [cardData]) // 處理信心度提交 const handleConfidenceSubmit = (level: number) => { submitConfidence(level as any) onConfidenceSubmit(level) // 生成並傳遞答案結果 const result = generateResult() onAnswer(`confidence_${level}`) } return (
{/* 翻卡區域 */}
setIsFlipped(!isFlipped)} > {/* 正面 - 單字 */}

{cardData.word}

點擊翻面查看答案

{/* 背面 - 詳細資訊 */}
{/* 例句區域 */}

例句

{cardData.example}

{cardData.exampleTranslation}

{/* 音頻播放 */}

請評估你對這個單字的熟悉程度

{/* 信心度評估 */} {isFlipped && (
)} {/* 翻卡提示 */} {!isFlipped && (

💡 點擊卡片可以翻面查看詳細資訊

)}
) } // 用於向後相容的包裝器 (暫時保留舊介面) interface LegacyFlipMemoryTestProps { word: string definition: string example: string exampleTranslation: string pronunciation?: string synonyms?: string[] difficultyLevel: string onConfidenceSubmit: (level: number) => void onReportError: () => void disabled?: boolean } // 預設匯出使用 Legacy 包裝器以保持向後相容 export const FlipMemoryTest: React.FC = (props) => { const cardData: ReviewCardData = { id: `temp_${props.word}`, word: props.word, definition: props.definition, example: props.example, translation: props.exampleTranslation || '', // 使用 exampleTranslation 作為 translation pronunciation: props.pronunciation, synonyms: props.synonyms || [], difficultyLevel: props.difficultyLevel, exampleTranslation: props.exampleTranslation } return ( {}} onConfidenceSubmit={props.onConfidenceSubmit} onReportError={props.onReportError} disabled={props.disabled} /> ) }