fix: 修復詞卡頁面 TypeScript 錯誤並清理冗餘代碼
🔧 TypeScript 錯誤修復: - 移除循環引用:刪除 `type Flashcard = Flashcard` 重複定義 - 清理 import 衝突:直接使用從 flashcards.ts 導入的 Flashcard 型別 - 移除未使用變數:刪除 mockFlashcards 假資料定義 - 清理冗餘型別:移除不需要的 CardSet 型別定義 🧹 代碼清理: - 完全移除假資料依賴,現在純粹使用真實 API - 簡化型別結構,避免不必要的型別重複定義 - 提升代碼可維護性和類型安全性 現在詞卡頁面沒有 TypeScript 錯誤,所有功能正常運作。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
70bf3f8fed
commit
989e92ce85
|
|
@ -9,15 +9,7 @@ import { useToast } from '@/components/Toast'
|
|||
// import { flashcardsService, type CardSet, type Flashcard } from '@/lib/services/flashcards'
|
||||
import { flashcardsService, type Flashcard } from '@/lib/services/flashcards'
|
||||
|
||||
// 暫時為了兼容性定義 CardSet 類型
|
||||
type CardSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
// 使用簡化的 Flashcard 類型
|
||||
type Flashcard = Flashcard
|
||||
// 移除不需要的型別定義,直接使用 import 的 Flashcard 型別
|
||||
import { useRouter } from 'next/navigation'
|
||||
|
||||
function FlashcardsContent() {
|
||||
|
|
@ -77,15 +69,7 @@ function FlashcardsContent() {
|
|||
const [showForm, setShowForm] = useState(false)
|
||||
const [editingCard, setEditingCard] = useState<Flashcard | null>(null)
|
||||
|
||||
// 添加假資料用於展示CEFR效果 (更新為 Flashcard 格式)
|
||||
const mockFlashcards: Flashcard[] = [
|
||||
{ id: 'mock1', word: 'hello', translation: '你好', partOfSpeech: 'interjection', pronunciation: '/həˈloʊ/', masteryLevel: 95, timesReviewed: 15, isFavorite: true, nextReviewDate: '2025-09-21', difficultyLevel: 'A1', definition: 'A greeting word', example: 'Hello, how are you?', createdAt: '2025-09-17', updatedAt: '2025-09-17' },
|
||||
{ id: 'mock2', word: 'beautiful', translation: '美麗的', partOfSpeech: 'adjective', pronunciation: '/ˈbjuːtɪfəl/', masteryLevel: 78, timesReviewed: 8, isFavorite: false, nextReviewDate: '2025-09-22', difficultyLevel: 'A2', definition: 'Pleasing to look at', example: 'The beautiful sunset', createdAt: '2025-09-16', updatedAt: '2025-09-16' },
|
||||
{ id: 'mock3', word: 'understand', translation: '理解', partOfSpeech: 'verb', pronunciation: '/ˌʌndərˈstænd/', masteryLevel: 65, timesReviewed: 12, isFavorite: true, nextReviewDate: '2025-09-20', difficultyLevel: 'B1', definition: 'To comprehend', example: 'I understand the concept', createdAt: '2025-09-15', updatedAt: '2025-09-15' },
|
||||
{ id: 'mock4', word: 'elaborate', translation: '詳細說明', partOfSpeech: 'verb', pronunciation: '/ɪˈlæbərət/', masteryLevel: 45, timesReviewed: 5, isFavorite: false, nextReviewDate: '2025-09-19', difficultyLevel: 'B2', definition: 'To explain in detail', example: 'Please elaborate on your idea', createdAt: '2025-09-14', updatedAt: '2025-09-14' },
|
||||
{ id: 'mock5', word: 'sophisticated', translation: '精密的', partOfSpeech: 'adjective', pronunciation: '/səˈfɪstɪkeɪtɪd/', masteryLevel: 30, timesReviewed: 3, isFavorite: true, nextReviewDate: '2025-09-18', difficultyLevel: 'C1', definition: 'Highly developed', example: 'A sophisticated system', createdAt: '2025-09-13', updatedAt: '2025-09-13' },
|
||||
{ id: 'mock6', word: 'ubiquitous', translation: '無處不在的', partOfSpeech: 'adjective', pronunciation: '/juːˈbɪkwɪtəs/', masteryLevel: 15, timesReviewed: 1, isFavorite: false, nextReviewDate: '2025-09-17', difficultyLevel: 'C2', definition: 'Present everywhere', example: 'Smartphones are ubiquitous', createdAt: '2025-09-12', updatedAt: '2025-09-12' }
|
||||
]
|
||||
// 移除假資料,現在完全使用真實 API 資料
|
||||
|
||||
// 載入總數統計
|
||||
const loadTotalCounts = async () => {
|
||||
|
|
@ -233,7 +217,6 @@ function FlashcardsContent() {
|
|||
|
||||
|
||||
// 由於後端已處理篩選,直接使用 API 回傳的結果
|
||||
const allCards = [...flashcards, ...mockFlashcards] // 保留模擬資料用於展示
|
||||
const filteredCards = flashcards // 直接使用從 API 取得的已篩選結果
|
||||
|
||||
// 清除所有篩選
|
||||
|
|
|
|||
Loading…
Reference in New Issue