Update QuizView.swift

Fixed a bug where a user could select another answer after an answer was previously selected.

Removed the Back button. There's no going back now! ;3
This commit is contained in:
Justin Oros
2025-07-03 13:14:43 -07:00
committed by GitHub
parent 5c8820fd6c
commit 4115ff91e7
@@ -23,7 +23,7 @@ struct QuizView: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
if loadError {
Text("Could not load questions for \(testName). Make sure the .json file is included in the app bundle or Documents folder.")
Text("Could not load questions for \(testName).")
.foregroundColor(.red)
.padding()
} else if questions.isEmpty {
@@ -36,6 +36,7 @@ struct QuizView: View {
ForEach(questions[currentIndex].answers, id: \.self) { answer in
Button(action: {
guard selectedAnswer == nil else { return }
selectedAnswer = answer
checkAnswer()
@@ -58,6 +59,7 @@ struct QuizView: View {
.foregroundColor(.white)
}
.buttonStyle(PlainButtonStyle())
.disabled(selectedAnswer != nil)
}
Text(feedbackText)
@@ -92,6 +94,7 @@ struct QuizView: View {
.padding()
.onAppear(perform: syncAndLoadQuestions)
.navigationTitle(testName + " Test")
.navigationBarBackButtonHidden(true)
.alert(isPresented: $showSummaryAlert) {
let percentage = currentIndex > 0 ? Int((Double(score) / Double(currentIndex + 1)) * 100) : 0
return Alert(