Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 7 additions & 11 deletions app/composables/useCurrentStudentProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const useCurrentStudentProgress = () => {

try {
const response = await $fetch<FormSubmission[]>('/api/formSubmission', {
method: 'GET',
query: { student: student.value.id }
})
submissions.value = Array.isArray(response) ? response : []
Expand All @@ -45,8 +46,7 @@ export const useCurrentStudentProgress = () => {
}
}

// Log a new form submission to track progress
const logFormSubmission = async (formId: number) => {
const logFormSubmission = async (formId: number, responses: Record<number, string>) => {
if (!student.value?.id) {
console.error('Cannot log form submission: No student is currently active.')
return null
Expand All @@ -57,7 +57,11 @@ export const useCurrentStudentProgress = () => {
method: 'POST',
body: {
student: student.value.id,
form: formId
form: formId,
Responses: Object.entries(responses).map(([formComponentId, response]) => ({
formComponent: Number(formComponentId),
response
}))
}
})

Expand All @@ -70,20 +74,12 @@ export const useCurrentStudentProgress = () => {
}
}

const logSubmissionResponse = async (submissionID: number, formComponentID: number, response: string) => {
if (!student.value?.id) {
console.error('Cannot log form submission: No student is currently active.')
return null
}
}

return {
submissions,
completedFormIds,
tickets,
isFormGroupCompleted,
loadProgress,
logFormSubmission,
logSubmissionResponse
}
}
10 changes: 6 additions & 4 deletions app/pages/reader/forms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ definePageMeta({ ssr: false })

const { student, settings, updateExp, restoreStudent } = useCurrentStudent()
const { FormGroup, loadActiveFormGroup } = useCurrentFormGroup()
const { tickets, completedFormIds, logFormSubmission, logSubmissionResponse, loadProgress } = useCurrentStudentProgress()
const { tickets, completedFormIds, logFormSubmission, loadProgress } = useCurrentStudentProgress()

const dataLoaded = ref(false)

Expand Down Expand Up @@ -182,11 +182,13 @@ async function submitChallenge() {
const formId = activeForm.value.id

// Persist completion and XP
const submission = await logFormSubmission(formId)
const submission = await logFormSubmission(formId, answers.value)
const submissionID = Number(submission?.id)

await updateExp(100)

// grab newly posted submission ID
const submissionID = Number(submission?.id)


showRaffleReward.value = true
ticketDropped.value = false
Expand Down Expand Up @@ -440,7 +442,7 @@ function getBadgeClass(type: string) {

<!-- Input area -->
<div v-if="['text','mcq'].includes(currentComponent.questionType)" class="mt-6">
<!-- Not yet answered -->
<!-- FRQ -->
<div v-if="!feedbackVisible[currentComponent.id]">
<textarea
v-if="currentComponent.questionType === 'text'"
Expand Down
Loading