'use client' import { useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { Navigation } from '@/components/Navigation' export default function LearnPage() { const router = useRouter() const [currentCardIndex, setCurrentCardIndex] = useState(0) const [isFlipped, setIsFlipped] = useState(false) const [mode, setMode] = useState<'flip' | 'quiz' | 'fill' | 'listening' | 'speaking'>('flip') const [score, setScore] = useState({ correct: 0, total: 0 }) const [selectedAnswer, setSelectedAnswer] = useState(null) const [showResult, setShowResult] = useState(false) const [fillAnswer, setFillAnswer] = useState('') const [showHint, setShowHint] = useState(false) const [isRecording, setIsRecording] = useState(false) const [audioPlaying, setAudioPlaying] = useState(false) const [modalImage, setModalImage] = useState(null) const [showReportModal, setShowReportModal] = useState(false) const [reportReason, setReportReason] = useState('') const [reportingCard, setReportingCard] = useState(null) // Mock data with real example images const cards = [ { id: 1, word: 'brought', partOfSpeech: 'verb', pronunciation: '/brɔːt/', translation: '提出、帶來', definition: 'Past tense of bring; to mention or introduce a topic in conversation', example: 'He brought this thing up during our meeting and no one agreed.', exampleTranslation: '他在我們的會議中提出了這件事,但沒有人同意。', exampleImage: '/images/examples/bring_up.png', synonyms: ['mentioned', 'raised', 'introduced'], difficulty: 'B1' }, { id: 2, word: 'instincts', partOfSpeech: 'noun', pronunciation: '/ˈɪnstɪŋkts/', translation: '本能、直覺', definition: 'Natural abilities that help living things survive without learning', example: 'Animals use their instincts to find food and stay safe.', exampleTranslation: '動物利用本能來尋找食物並保持安全。', exampleImage: '/images/examples/instinct.png', synonyms: ['intuition', 'impulse', 'tendency'], difficulty: 'B2' }, { id: 3, word: 'warrants', partOfSpeech: 'noun', pronunciation: '/ˈwɔːrənts/', translation: '搜查令、授權令', definition: 'Official documents that give police permission to do something', example: 'The police obtained warrants to search the building.', exampleTranslation: '警方取得了搜查令來搜查這棟建築物。', exampleImage: '/images/examples/warrant.png', synonyms: ['authorization', 'permit', 'license'], difficulty: 'C1' } ] const currentCard = cards[currentCardIndex] // Quiz mode options - dynamically generate from current cards const quizOptions = [ cards[currentCardIndex].translation, ...cards .filter((_, idx) => idx !== currentCardIndex) .map(card => card.translation) .slice(0, 2), '建議、提議' // additional wrong option ].sort(() => Math.random() - 0.5) // shuffle options const handleFlip = () => { setIsFlipped(!isFlipped) } const handleNext = () => { if (currentCardIndex < cards.length - 1) { setCurrentCardIndex(currentCardIndex + 1) setIsFlipped(false) setSelectedAnswer(null) setShowResult(false) setFillAnswer('') setShowHint(false) } } const handlePrevious = () => { if (currentCardIndex > 0) { setCurrentCardIndex(currentCardIndex - 1) setIsFlipped(false) setSelectedAnswer(null) setShowResult(false) setFillAnswer('') setShowHint(false) } } const handleDifficultyRate = (rating: number) => { // Mock rating logic console.log(`Rated ${rating} for ${currentCard.word}`) handleNext() } const handleQuizAnswer = (answer: string) => { setSelectedAnswer(answer) setShowResult(true) if (answer === currentCard.translation) { setScore({ ...score, correct: score.correct + 1, total: score.total + 1 }) } else { setScore({ ...score, total: score.total + 1 }) } } return (
{/* Navigation */} router.push('/dashboard')} />
{/* Progress Bar */}
進度 {currentCardIndex + 1} / {cards.length}
{/* Mode Toggle */}
{mode === 'flip' ? ( /* Flip Card Mode */
{/* Error Report Button for Flip Mode */}
{/* Front of card */}
{currentCard.word}
{currentCard.partOfSpeech}
{currentCard.pronunciation}
點擊翻轉查看答案
{/* Back of card */}
翻譯
{currentCard.translation}
定義
{currentCard.definition}
例句
{currentCard.example}
{currentCard.exampleTranslation}
同義詞
{currentCard.synonyms.map((syn, idx) => ( {syn} ))}
{/* Difficulty Rating */} {isFlipped && (
這個單字對你來說難度如何?
)}
) : mode === 'quiz' ? ( /* Quiz Mode - 選擇題:英文定義選中文翻譯 */
{/* Error Report Button for Quiz Mode */}
根據定義選擇正確的中文翻譯
{currentCard.definition}
({currentCard.partOfSpeech})
{quizOptions.map((option, idx) => ( ))}
) : mode === 'fill' ? ( /* Fill in the Blank Mode - 填空題 */
{/* Error Report Button for Fill Mode */}
根據例句圖片和句子填入正確的詞彙
{/* Example Image */} {currentCard.exampleImage && (
Example context setModalImage(currentCard.exampleImage)} />
點擊圖片可放大查看
)} {/* Example Sentence with Blank */}
{currentCard.example.split(currentCard.word).map((part, i) => ( {part} {i < currentCard.example.split(currentCard.word).length - 1 && ( )} ))}
{/* Hint Button */} {!showHint && ( )} {/* Definition Hint */} {showHint && (
定義提示: {currentCard.definition}
)}
{/* Answer Input */}
setFillAnswer(e.target.value)} placeholder="輸入答案..." className="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:border-primary focus:outline-none text-lg" onKeyPress={(e) => { if (e.key === 'Enter' && fillAnswer) { setShowResult(true) } }} />
{/* Submit Button */} {!showResult && ( )} {/* Result Display */} {showResult && (
{fillAnswer.toLowerCase() === currentCard.word.toLowerCase() ? '✓ 正確!' : '✗ 錯誤'}
{fillAnswer.toLowerCase() !== currentCard.word.toLowerCase() && (
正確答案:{currentCard.word}
)}
完整例句:
{currentCard.example}
{currentCard.exampleTranslation}
)}
) : mode === 'listening' ? ( /* Listening Test Mode - 聽力測試 */
{/* Error Report Button for Listening Mode */}
聽音頻,選擇正確的單字
{/* Audio Play Button */}
點擊播放按鈕聽發音
{/* Word Options */}
{[currentCard.word, 'determine', 'achieve', 'consider'].map((word) => ( ))}
{/* Result Display */} {showResult && (
單字詳情
{currentCard.word} - {currentCard.translation}
{currentCard.definition}
"{currentCard.example}"
)}
) : mode === 'speaking' ? ( /* Speaking Test Mode - 口說測試 */
{/* Error Report Button for Speaking Mode */}
念出以下例句
{/* Target Sentence */}
{currentCard.example}
{currentCard.exampleTranslation}
{/* Pronunciation Guide */}
重點單字發音:
{currentCard.word} {currentCard.pronunciation}
{/* Recording Button */}
{isRecording ? '錄音中... 點擊停止' : '點擊開始錄音'}
{/* Result Display */} {showResult && (
✓ 完成口說練習!
提示:持續練習可以提高發音準確度和流暢度
)}
) : null} {/* Navigation Buttons */}
{/* Image Modal */} {modalImage && (
setModalImage(null)} >
e.stopPropagation()} > {/* Close Button */} {/* Image */}
Example context enlarged
)} {/* Error Report Modal */} {showReportModal && (
setShowReportModal(false)} >
e.stopPropagation()} >

回報錯誤

詞卡:{reportingCard?.word}
測驗模式:{mode === 'flip' ? '翻卡模式' : mode === 'quiz' ? '選擇題' : mode === 'fill' ? '填空題' : mode === 'listening' ? '聽力測試' : '口說測試'}