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