Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion app/pages/reader/forms.vue
Comment thread
irizarrymateo2005 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const hasOwnBook = ref(false)
const currentComponentID = ref(0)
const answers = ref<Record<number,string>>({})
const feedbackVisible = ref<Record<number,boolean>>({})

const isCurrentComponentCorrect = computed(() => {
const q = currentComponent.value
if (!q || !answers.value[q.id]) return true
Expand Down Expand Up @@ -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
Expand All @@ -197,6 +219,7 @@ async function submitChallenge() {
currentComponentID.value = 0
feedbackVisible.value = {}
answers.value = {}
isSubmitting.value = false
}, 500)
}

Expand Down