diff --git a/app/pages/reader/forms.vue b/app/pages/reader/forms.vue index 055f781..df0930e 100644 --- a/app/pages/reader/forms.vue +++ b/app/pages/reader/forms.vue @@ -109,7 +109,6 @@ const hasOwnBook = ref(false) const currentComponentID = ref(0) const answers = ref>({}) const feedbackVisible = ref>({}) - const isCurrentComponentCorrect = computed(() => { const q = currentComponent.value if (!q || !answers.value[q.id]) return true @@ -169,16 +168,39 @@ function checkAnswer() { if (q) feedbackVisible.value[q.id] = true } +const isProcessingNext = ref(false) + function nextStep() { + if (isProcessingNext.value) return + isProcessingNext.value = true + const qs = currentFormComponents.value + const q = qs[currentComponentID.value] + + if (q && ['text', 'mcq'].includes(q.questionType)) { + const ans = answers.value[q.id] + if (ans === undefined || ans === null || String(ans).trim() === '') { + isProcessingNext.value = false + return + } + } + if (currentComponentID.value < qs.length - 1) { currentComponentID.value++ } else { submitChallenge() } + + setTimeout(() => { + isProcessingNext.value = false + }, 100) } +const isSubmitting = ref(false) + async function submitChallenge() { + if (isSubmitting.value) return + isSubmitting.value = true const formId = activeForm.value.id // Persist completion and XP @@ -197,6 +219,7 @@ async function submitChallenge() { currentComponentID.value = 0 feedbackVisible.value = {} answers.value = {} + isSubmitting.value = false }, 500) }