diff --git a/frontend/app/flashcards/[id]/page.tsx b/frontend/app/flashcards/[id]/page.tsx index 9edfcdb..3fd50e4 100644 --- a/frontend/app/flashcards/[id]/page.tsx +++ b/frontend/app/flashcards/[id]/page.tsx @@ -50,7 +50,11 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { cardSet: { name: '基礎詞彙', color: 'bg-blue-500' }, difficultyLevel: 'A1', createdAt: '2025-09-17', - synonyms: ['hi', 'greetings', 'good day'] + synonyms: ['hi', 'greetings', 'good day'], + // 添加圖片欄位 + exampleImages: [], + hasExampleImage: false, + primaryImageUrl: null }, 'mock2': { id: 'mock2', @@ -68,7 +72,11 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { cardSet: { name: '高級詞彙', color: 'bg-purple-500' }, difficultyLevel: 'B2', createdAt: '2025-09-14', - synonyms: ['explain', 'detail', 'expand', 'clarify'] + synonyms: ['explain', 'detail', 'expand', 'clarify'], + // 添加圖片欄位 + exampleImages: [], + hasExampleImage: false, + primaryImageUrl: null } } @@ -86,13 +94,18 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { return } - // 載入真實詞卡 - const result = await flashcardsService.getFlashcard(cardId) + // 載入真實詞卡 - 使用列表 API 然後找到對應詞卡 (因為列表 API 有圖片資訊) + const result = await flashcardsService.getFlashcards() if (result.success && result.data) { - setFlashcard(result.data) - setEditedCard(result.data) + const targetCard = result.data.flashcards.find(card => card.id === cardId) + if (targetCard) { + setFlashcard(targetCard) + setEditedCard(targetCard) + } else { + throw new Error('詞卡不存在') + } } else { - throw new Error(result.error || '詞卡不存在') + throw new Error(result.error || '載入詞卡失敗') } } catch (err) { setError('載入詞卡時發生錯誤') @@ -117,14 +130,34 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) { } } - // 獲取例句圖片 - const getExampleImage = (word: string) => { - const imageMap: {[key: string]: string} = { - 'hello': '/images/examples/bring_up.png', - 'elaborate': '/images/examples/instinct.png', - 'beautiful': '/images/examples/warrant.png' + // 獲取例句圖片 - 使用 API 資料 + const getExampleImage = (card: Flashcard): string | null => { + return card.primaryImageUrl || null + } + + // 檢查詞彙是否有例句圖片 - 使用 API 資料 + const hasExampleImage = (card: Flashcard): boolean => { + return card.hasExampleImage + } + + // 詞性簡寫轉換 + const getPartOfSpeechDisplay = (partOfSpeech: string): string => { + const shortMap: {[key: string]: string} = { + 'noun': 'n.', + 'verb': 'v.', + 'adjective': 'adj.', + 'adverb': 'adv.', + 'preposition': 'prep.', + 'interjection': 'int.', + 'phrase': 'phr.' } - return imageMap[word?.toLowerCase()] || '/images/examples/bring_up.png' + + // 處理複合詞性 (如 "preposition/adverb") + if (partOfSpeech?.includes('/')) { + return partOfSpeech.split('/').map(p => shortMap[p.trim()] || p.trim()).join('/') + } + + return shortMap[partOfSpeech] || partOfSpeech || '' } // 處理收藏切換 @@ -277,7 +310,7 @@ function FlashcardDetailContent({ cardId }: { cardId: string }) {

{flashcard.word}

- {flashcard.partOfSpeech} + {getPartOfSpeechDisplay(flashcard.partOfSpeech)} {flashcard.pronunciation}