Files
QuizApp/QuizApp/CategorySelectionView.swift
2025-08-06 22:07:41 +02:00

112 lines
4.2 KiB
Swift

//
// CategorySelectionView.swift
// QuizApp
//
// Created by Paul on 06.08.25.
//
import SwiftUI
struct CategorySelectionView: View {
@ObservedObject var viewModel = ViewModel()
@AppStorage("globalScore") var globalScore: Int = 0
var body: some View {
NavigationStack {
VStack(spacing: 24) {
// Willkommensnachricht
VStack(spacing: 8) {
Text("Willkommen!")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.primary)
Text("Wähle eine Kategorie und teste dein Wissen")
.font(.subheadline)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
}
.padding(.top)
// Punktestand
HStack {
VStack(alignment: .leading, spacing: 4) {
Text("Deine Punkte")
.font(.caption)
.foregroundColor(.secondary)
Text("\(globalScore)")
.font(.title2)
.fontWeight(.bold)
.foregroundColor(.blue)
}
Spacer()
Image(systemName: "star.fill")
.foregroundColor(.orange)
.font(.title2)
}
.padding()
.background(
RoundedRectangle(cornerRadius: 12)
.fill(Color(.systemGray6))
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color(.systemGray4), lineWidth: 1)
)
)
.padding(.horizontal)
// Kategorien Header
Text("Verfügbare Quiz")
.font(.title2)
.fontWeight(.semibold)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
// 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()
.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)
.navigationTitle("Quiz-Auswahl")
}
}
}