94ef6ad84a
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
import SwiftUI
|
|
|
|
struct WordListView: View {
|
|
let category: WordCategory
|
|
let onRoute: (AppRoute) -> Void
|
|
|
|
var body: some View {
|
|
List(category.words) { word in
|
|
NavigationLink(value: AppRoute.word(word)) {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(word.word)
|
|
.font(.headline)
|
|
Text(word.meaning)
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.padding(.vertical, 2)
|
|
}
|
|
}
|
|
.contentMargins(.top, 8, for: .scrollContent)
|
|
.navigationTitle(category.name)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .primaryAction) {
|
|
Menu {
|
|
Button("英选汉") { startQuiz(.enToZh) }
|
|
Button("汉选英") { startQuiz(.zhToEn) }
|
|
Button("拼写") { startQuiz(.spelling) }
|
|
} label: {
|
|
Text("测验")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func startQuiz(_ mode: QuizMode) {
|
|
if category.words.count <= 10 {
|
|
onRoute(.quiz(QuizConfig(mode: mode, words: category.words)))
|
|
} else {
|
|
onRoute(.quizSetup(QuizSetupRequest(mode: mode, words: category.words)))
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationStack {
|
|
WordListView(category: WordCategory(id: "colors", name: "颜色", icon: "paintpalette.fill", words: [
|
|
Word(word: "red", phonetic: "/red/", meaning: "红色", example: "The apple is red.", exampleMeaning: "苹果是红色的。")
|
|
])) { _ in }
|
|
}
|
|
}
|