diff --git a/Conjuga/Conjuga/Views/Course/CourseQuizView.swift b/Conjuga/Conjuga/Views/Course/CourseQuizView.swift index 0f4bcb3..830122a 100644 --- a/Conjuga/Conjuga/Views/Course/CourseQuizView.swift +++ b/Conjuga/Conjuga/Views/Course/CourseQuizView.swift @@ -18,6 +18,7 @@ struct CourseQuizView: View { @State private var currentIndex = 0 @State private var correctCount = 0 @State private var missedItems: [MissedCourseItem] = [] + @State private var isAdvancing = false // Per-question state @State private var userAnswer = "" @@ -311,16 +312,13 @@ struct CourseQuizView: View { // Nav arrows HStack { Button { - guard currentIndex > 0 else { return } - currentIndex -= 1 - resetQuestion() - prepareQuestion() + goBack() } label: { Label("Previous", systemImage: "chevron.left") .font(.subheadline) } .tint(.secondary) - .disabled(currentIndex == 0) + .disabled(currentIndex == 0 || isAdvancing) Spacer() @@ -332,6 +330,7 @@ struct CourseQuizView: View { .labelStyle(.titleAndIcon) } .tint(.blue) + .disabled(isAdvancing) } .padding(.horizontal) } @@ -498,6 +497,8 @@ struct CourseQuizView: View { } private func advance() { + guard !isAdvancing else { return } + isAdvancing = true currentIndex += 1 if isComplete { saveResult() @@ -505,6 +506,20 @@ struct CourseQuizView: View { resetQuestion() prepareQuestion() } + DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) { + isAdvancing = false + } + } + + private func goBack() { + guard !isAdvancing, currentIndex > 0 else { return } + isAdvancing = true + currentIndex -= 1 + resetQuestion() + prepareQuestion() + DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) { + isAdvancing = false + } } private func saveResult() {