feat: added navigation link in view

This commit is contained in:
2025-08-06 21:11:29 +02:00
parent ef779cf936
commit c8cd19e55f

View File

@@ -9,31 +9,58 @@ import SwiftUI
struct CategorySelectionView: View {
@ObservedObject var viewModel = ViewModel()
@State private var selectedCategory: String? = nil
var body: some View {
if viewModel.selectedCategory != nil && !viewModel.questions.isEmpty {
ContentView(viewModel: viewModel)
} else {
VStack(spacing: 20) {
Text("Wähle eine Kategorie")
.font(.largeTitle)
NavigationStack {
VStack(spacing: 24) {
// Minimaler Header
Text("Quiz Kategorien")
.font(.title)
.fontWeight(.bold)
.padding(.top)
// Liste der Kategorien
VStack(spacing: 12) {
ForEach(viewModel.availableCategories, id: \.self) { category in
Button(action: {
NavigationLink(destination: ContentView(viewModel: viewModel)
.onAppear {
viewModel.loadQuestions(for: category)
selectedCategory = category
}) {
Text(category)
HStack {
Image(systemName: "play.circle.fill")
.foregroundColor(.blue)
.font(.title2)
Text(category)
.font(.headline)
.foregroundColor(.primary)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.secondary)
.font(.caption)
}
.padding()
.frame(maxWidth: 300)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(12)
}
}
}
.background(
RoundedRectangle(cornerRadius: 12)
.fill(Color(.systemGray6))
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color(.systemGray4), lineWidth: 1)
)
)
}
.buttonStyle(PlainButtonStyle())
}
}
.padding(.horizontal)
Spacer()
}
.background(Color.white)
.navigationBarHidden(true)
}
}
}