import { useState, useRef, useEffect, memo, useCallback } from 'react' import AudioPlayer from '@/components/media/AudioPlayer' import { ErrorReportButton, TestHeader, ConfidenceLevel } from '@/components/review/shared' import { ConfidenceTestProps } from '@/types/review' interface FlipMemoryTestProps extends ConfidenceTestProps {} const FlipMemoryTestComponent: React.FC = ({ cardData, onConfidenceSubmit, onReportError, disabled = false }) => { const [isFlipped, setIsFlipped] = useState(false) const [selectedConfidence, setSelectedConfidence] = useState(null) const [cardHeight, setCardHeight] = useState(400) const frontRef = useRef(null) const backRef = useRef(null) // 判斷是否已答題(選擇了信心等級) const hasAnswered = selectedConfidence !== 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) } } // 延遲執行以確保內容已渲染 const timer = setTimeout(updateCardHeight, 100) window.addEventListener('resize', updateCardHeight) return () => { clearTimeout(timer) window.removeEventListener('resize', updateCardHeight) } }, [cardData.word, cardData.definition, cardData.example, cardData.synonyms]) const handleFlip = useCallback(() => { if (!disabled) setIsFlipped(!isFlipped) }, [disabled, isFlipped]) const handleConfidenceSelect = useCallback((level: number) => { if (disabled || hasAnswered) return setSelectedConfidence(level) onConfidenceSubmit(level) }, [disabled, hasAnswered, onConfidenceSubmit]) return (
{/* 翻卡容器 */}
{/* 正面 */}

點擊卡片翻面,根據你對單字的熟悉程度進行自我評估:

{cardData.word}

{cardData.pronunciation && ( {cardData.pronunciation} )}
e.stopPropagation()}>
{/* 背面 */}
{/* 定義區塊 */}

定義

{cardData.definition}

{/* 例句區塊 */}

例句

{cardData.example}

e.stopPropagation()}>

{cardData.exampleTranslation}

{/* 同義詞區塊 */} {cardData.synonyms && cardData.synonyms.length > 0 && (

同義詞

{cardData.synonyms.map((synonym, index) => ( {synonym} ))}
)}
{/* 信心等級評估區 - 使用新元件 */}
) } export const FlipMemoryTest = memo(FlipMemoryTestComponent) FlipMemoryTest.displayName = 'FlipMemoryTest'