regenerate something when the sentences changed

This commit is contained in:
2026-10-03 21:12:12 +08:00
parent d5609c5c42
commit 4fd0fd36a4
11 changed files with 245 additions and 13 deletions

View File

@@ -45,6 +45,10 @@ final class CatalogViewModel: ObservableObject {
do {
let document = try await SentenceBoundaryAPI.fetch(videoHash: video.videoHash)
boundaryDocuments[document.videoHash] = document
SentenceExplanationStore.shared.sync(
mediaId: document.videoHash,
sentences: document.sentences
)
updatedVideos[index] = video.copy(
durationMs: document.durationMs,
sentenceCount: document.sentences.count
@@ -75,6 +79,10 @@ final class CatalogViewModel: ObservableObject {
return
}
if let document = boundaryDocuments[video.videoHash] {
SentenceExplanationStore.shared.sync(
mediaId: document.videoHash,
sentences: document.sentences
)
let item = TrainingMediaItem(
id: video.videoHash,
title: video.title,
@@ -98,6 +106,10 @@ final class CatalogViewModel: ObservableObject {
return
}
boundaryDocuments[document.videoHash] = document
SentenceExplanationStore.shared.sync(
mediaId: document.videoHash,
sentences: document.sentences
)
controller.updateBoundaries(document.sentences)
controller.boundaryState = .loaded(count: document.sentences.count)
controller.showTransientMessage("课程已就绪:\(document.sentences.count) 句")
@@ -142,6 +154,10 @@ final class CatalogViewModel: ObservableObject {
guard activeVideoHash == hash else {
return
}
SentenceExplanationStore.shared.sync(
mediaId: document.videoHash,
sentences: document.sentences
)
controller.updateBoundaries(document.sentences)
controller.boundaryState = .loaded(count: document.sentences.count)
controller.showTransientMessage("句子边界已加载:\(document.sentences.count) 句")

View File

@@ -29,7 +29,8 @@ struct FullscreenPlayerView: View {
SentenceExplanationSheet(
mediaId: controller.currentItem?.id ?? "",
courseTitle: controller.currentItem?.title ?? "口语训练课程",
sentence: sentence
sentence: sentence,
sentences: controller.currentItem?.sentences ?? []
)
}
}

View File

@@ -27,7 +27,8 @@ struct PlayerSectionView: View {
SentenceExplanationSheet(
mediaId: controller.currentItem?.id ?? "",
courseTitle: controller.currentItem?.title ?? "口语训练课程",
sentence: sentence
sentence: sentence,
sentences: controller.currentItem?.sentences ?? []
)
}
}
@@ -273,6 +274,7 @@ struct SentenceExplanationSheet: View {
let mediaId: String
let courseTitle: String
let sentence: SentenceBoundary
var sentences: [SentenceBoundary] = []
@Environment(\.dismiss) private var dismiss
@State private var explanation = ""
@@ -327,6 +329,7 @@ struct SentenceExplanationSheet: View {
}
}
.task {
SentenceExplanationStore.shared.sync(mediaId: mediaId, sentences: sentences)
if let cached = SentenceExplanationStore.shared.load(
mediaId: mediaId,
sentenceIndex: sentence.index