dramaling-vocab-learning/frontend/app/review-simple/data.ts

63 lines
1.7 KiB
TypeScript

// 模擬真實API數據結構
import apiSeeds from './components/api_seeds.json'
// API響應接口 (匹配真實API結構 + 同義詞擴展)
export interface ApiFlashcard {
id: string
word: string
translation: string
definition: string
partOfSpeech: string
pronunciation: string
example: string
exampleTranslation: string
isFavorite: boolean
difficultyLevelNumeric: number
cefr: string
createdAt: string
updatedAt: string
hasExampleImage: boolean
primaryImageUrl: string | null
// 添加同義詞支持
synonyms?: string[]
}
export interface ApiResponse {
success: boolean
data: {
flashcards: ApiFlashcard[]
count: number
}
message: string | null
timestamp: string
}
// 模擬API響應數據 (直接使用真實API格式)
export const MOCK_API_RESPONSE: ApiResponse = apiSeeds as ApiResponse
// 為API數據添加同義詞 (模擬完整數據)
const addSynonyms = (flashcards: any[]): ApiFlashcard[] => {
const synonymsMap: Record<string, string[]> = {
'evidence': ['proof', 'testimony', 'documentation'],
'warrants': ['authorizations', 'permits', 'orders'],
'obtained': ['acquired', 'gained', 'secured'],
'prioritize': ['rank', 'organize', 'arrange']
}
return flashcards.map(card => ({
...card,
synonyms: synonymsMap[card.word] || []
}))
}
// 提取詞卡數據 (方便組件使用)
export const SIMPLE_CARDS = addSynonyms(MOCK_API_RESPONSE.data.flashcards)
// 模擬API調用函數 (為未來API集成做準備)
export const mockApiCall = async (): Promise<ApiResponse> => {
// 模擬網路延遲
await new Promise(resolve => setTimeout(resolve, 500))
// 返回模擬數據
return MOCK_API_RESPONSE
}