v0.3.0 — Phase β-2 Study-Loop
Voller Lern-Flow mit Web-Parität: fällige Karten via /reviews/due laden, flip + rate (4 Buttons + Haptic), Grades via Offline-Queue ans Server-FSRS schicken. - Card/Review/DueReview DTOs mit snake_case + camelCase-deckId- Sonderfall im embedded card-Subobjekt - CardType-Enum (alle 7 Typen), Rating-Enum mit deutschen Labels - Cloze-Helper 1:1-Port aus cards-domain (extractClusterIds, subIndexCount, clusterId, renderPrompt/Answer, hint) - CardsAPI.dueReviews(deckId:) + gradeReview(cardId,subIndex,rating,reviewedAt) - PendingGrade SwiftData-Model + GradeQueue (FIFO-Drain, originaler Timestamp bleibt, bei Netzfehler in Queue, Retry beim nächsten Drain) - StudySession @Observable State-Machine - CardRenderer für basic, basic-reverse, cloze; Placeholder für image-occlusion/audio-front/typing/multiple-choice (β-3/β-4) - RatingBar mit UIImpactFeedbackGenerator (medium/heavy) - StudySessionView per NavigationLink aus DeckListView - 9 neue Tests (Cloze: 8, Review-Decoding: 3), insgesamt 17 grün Server-authoritative FSRS bleibt — kein ts-fsrs-Port. Endurance-Test auf realem Gerät steht aus (siehe PLAN.md). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f664a00b64
commit
3b861af3fb
15 changed files with 1013 additions and 23 deletions
92
Sources/Features/Study/StudySession.swift
Normal file
92
Sources/Features/Study/StudySession.swift
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import Foundation
|
||||
import ManaCore
|
||||
import Observation
|
||||
import SwiftData
|
||||
|
||||
/// State-Machine für eine Lern-Session. Lädt Due-Reviews beim Start,
|
||||
/// rendert eine Karte nach der anderen, schickt Grades via GradeQueue ab.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class StudySession {
|
||||
enum Phase: Sendable {
|
||||
case loading
|
||||
case studying
|
||||
case finished
|
||||
case failed(String)
|
||||
}
|
||||
|
||||
private(set) var phase: Phase = .loading
|
||||
private(set) var queue: [DueReview] = []
|
||||
private(set) var currentIndex: Int = 0
|
||||
private(set) var isFlipped: Bool = false
|
||||
private(set) var totalGraded: Int = 0
|
||||
|
||||
let deckId: String
|
||||
let deckName: String
|
||||
|
||||
private let api: CardsAPI
|
||||
private let gradeQueue: GradeQueue
|
||||
|
||||
init(deckId: String, deckName: String, auth: AuthClient, context: ModelContext) {
|
||||
self.deckId = deckId
|
||||
self.deckName = deckName
|
||||
api = CardsAPI(auth: auth)
|
||||
gradeQueue = GradeQueue(api: api, context: context)
|
||||
}
|
||||
|
||||
var current: DueReview? {
|
||||
guard queue.indices.contains(currentIndex) else { return nil }
|
||||
return queue[currentIndex]
|
||||
}
|
||||
|
||||
var remaining: Int {
|
||||
max(0, queue.count - currentIndex)
|
||||
}
|
||||
|
||||
func start() async {
|
||||
phase = .loading
|
||||
do {
|
||||
queue = try await api.dueReviews(deckId: deckId, limit: 500)
|
||||
currentIndex = 0
|
||||
isFlipped = false
|
||||
totalGraded = 0
|
||||
if queue.isEmpty {
|
||||
phase = .finished
|
||||
} else {
|
||||
phase = .studying
|
||||
}
|
||||
Log.study.info("Session start — \(self.queue.count, privacy: .public) due in deck \(self.deckId, privacy: .public)")
|
||||
} catch {
|
||||
let msg = (error as? LocalizedError)?.errorDescription ?? String(describing: error)
|
||||
phase = .failed(msg)
|
||||
Log.study.error("Session start failed: \(msg, privacy: .public)")
|
||||
}
|
||||
}
|
||||
|
||||
func flip() {
|
||||
guard case .studying = phase else { return }
|
||||
isFlipped.toggle()
|
||||
}
|
||||
|
||||
func grade(_ rating: Rating) async {
|
||||
guard case .studying = phase, let card = current else { return }
|
||||
let reviewedAt = Date.now
|
||||
await gradeQueue.submit(
|
||||
cardId: card.review.cardId,
|
||||
subIndex: card.review.subIndex,
|
||||
rating: rating,
|
||||
reviewedAt: reviewedAt
|
||||
)
|
||||
totalGraded += 1
|
||||
advance()
|
||||
}
|
||||
|
||||
private func advance() {
|
||||
currentIndex += 1
|
||||
isFlipped = false
|
||||
if currentIndex >= queue.count {
|
||||
phase = .finished
|
||||
Log.study.info("Session finished — graded \(self.totalGraded, privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue