From c8cd19e55f6c5eadc9553b201051b511ab2f8342 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 6 Aug 2025 21:11:29 +0200 Subject: [PATCH] feat: added navigation link in view --- QuizApp/CategorySelectionView.swift | 67 ++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/QuizApp/CategorySelectionView.swift b/QuizApp/CategorySelectionView.swift index 0950639..4b2ccbe 100644 --- a/QuizApp/CategorySelectionView.swift +++ b/QuizApp/CategorySelectionView.swift @@ -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) - - ForEach(viewModel.availableCategories, id: \.self) { category in - Button(action: { - viewModel.loadQuestions(for: category) - selectedCategory = category - }) { - Text(category) - .font(.title2) + 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 + NavigationLink(destination: ContentView(viewModel: viewModel) + .onAppear { + viewModel.loadQuestions(for: 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) } } } +