71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
import { create } from 'zustand'
|
|
import { subscribeWithSelector } from 'zustand/middleware'
|
|
|
|
// 會話相關的類型定義
|
|
export interface ExtendedFlashcard {
|
|
id: string
|
|
word: string
|
|
definition: string
|
|
example: string
|
|
translation?: string
|
|
pronunciation?: string
|
|
difficultyLevel?: string
|
|
nextReviewDate?: string
|
|
currentInterval?: number
|
|
isOverdue?: boolean
|
|
overdueDays?: number
|
|
baseMasteryLevel?: number
|
|
lastReviewDate?: string
|
|
synonyms?: string[]
|
|
exampleImage?: string
|
|
}
|
|
|
|
// 會話狀態接口
|
|
interface ReviewSessionState {
|
|
// 核心會話狀態
|
|
mounted: boolean
|
|
isLoading: boolean
|
|
error: string | null
|
|
|
|
// 當前卡片狀態
|
|
currentCard: ExtendedFlashcard | null
|
|
currentCardIndex: number
|
|
|
|
// Actions
|
|
setMounted: (mounted: boolean) => void
|
|
setLoading: (loading: boolean) => void
|
|
setError: (error: string | null) => void
|
|
setCurrentCard: (card: ExtendedFlashcard | null) => void
|
|
setCurrentCardIndex: (index: number) => void
|
|
resetSession: () => void
|
|
}
|
|
|
|
export const useReviewSessionStore = create<ReviewSessionState>()(
|
|
subscribeWithSelector((set) => ({
|
|
// 初始狀態
|
|
mounted: false,
|
|
isLoading: false,
|
|
error: null,
|
|
currentCard: null,
|
|
currentCardIndex: 0,
|
|
|
|
// Actions
|
|
setMounted: (mounted) => set({ mounted }),
|
|
|
|
setLoading: (loading) => set({ isLoading: loading }),
|
|
|
|
setError: (error) => set({ error }),
|
|
|
|
setCurrentCard: (card) => set({ currentCard: card }),
|
|
|
|
setCurrentCardIndex: (index) => set({ currentCardIndex: index }),
|
|
|
|
resetSession: () => set({
|
|
currentCard: null,
|
|
currentCardIndex: 0,
|
|
error: null,
|
|
mounted: false,
|
|
isLoading: false
|
|
})
|
|
}))
|
|
) |