diff --git a/frontend/app/flashcards/page.tsx b/frontend/app/flashcards/page.tsx index 07db553..e990cc8 100644 --- a/frontend/app/flashcards/page.tsx +++ b/frontend/app/flashcards/page.tsx @@ -23,6 +23,38 @@ function FlashcardsContent() { // 使用新的搜尋Hook const [searchState, searchActions] = useFlashcardSearch(activeTab) + // 例句圖片邏輯 + const getExampleImage = (word: string): string => { + const availableImages = [ + '/images/examples/bring_up.png', + '/images/examples/instinct.png', + '/images/examples/warrant.png' + ] + + const imageMap: {[key: string]: string} = { + 'brought': '/images/examples/bring_up.png', + 'instincts': '/images/examples/instinct.png', + 'warrants': '/images/examples/warrant.png', + 'hello': '/images/examples/bring_up.png', + 'beautiful': '/images/examples/instinct.png', + 'understand': '/images/examples/warrant.png', + 'elaborate': '/images/examples/bring_up.png', + 'sophisticated': '/images/examples/instinct.png', + 'ubiquitous': '/images/examples/warrant.png' + } + + // 根據詞彙返回對應圖片,如果沒有則根據字母分配 + const mappedImage = imageMap[word?.toLowerCase()] + if (mappedImage) return mappedImage + + // 根據首字母分配圖片 + const firstChar = (word || 'a')[0].toLowerCase() + const charCode = firstChar.charCodeAt(0) - 97 // a=0, b=1, c=2... + const imageIndex = charCode % availableImages.length + + return availableImages[imageIndex] + } + // 初始化數據載入 useEffect(() => { loadTotalCounts() @@ -213,6 +245,7 @@ function FlashcardsContent() { onToggleFavorite={handleToggleFavorite} getCEFRColor={getCEFRColor} highlightSearchTerm={highlightSearchTerm} + getExampleImage={getExampleImage} router={router} /> @@ -427,6 +460,7 @@ interface SearchResultsProps { onToggleFavorite: (card: Flashcard) => void getCEFRColor: (level: string) => string highlightSearchTerm: (text: string, term: string) => React.ReactNode + getExampleImage: (word: string) => string router: any } @@ -438,6 +472,7 @@ function SearchResults({ onToggleFavorite, getCEFRColor, highlightSearchTerm, + getExampleImage, router }: SearchResultsProps) { if (searchState.flashcards.length === 0) { @@ -476,6 +511,7 @@ function SearchResults({ onToggleFavorite={() => onToggleFavorite(card)} getCEFRColor={getCEFRColor} highlightSearchTerm={highlightSearchTerm} + getExampleImage={getExampleImage} router={router} /> ))} @@ -492,10 +528,11 @@ interface FlashcardItemProps { onToggleFavorite: () => void getCEFRColor: (level: string) => string highlightSearchTerm: (text: string, term: string) => React.ReactNode + getExampleImage: (word: string) => string router: any } -function FlashcardItem({ card, searchTerm, onEdit, onDelete, onToggleFavorite, getCEFRColor, highlightSearchTerm, router }: FlashcardItemProps) { +function FlashcardItem({ card, searchTerm, onEdit, onDelete, onToggleFavorite, getCEFRColor, highlightSearchTerm, getExampleImage, router }: FlashcardItemProps) { return (