From 878cd555ffbc18edab57024ed3aa335799641fdf Mon Sep 17 00:00:00 2001 From: Anastasia Diseth Date: Thu, 28 Mar 2024 12:03:44 +0200 Subject: [PATCH] check for undefined user_answers --- src/components/PdfDownload/PdfGenerator.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/PdfDownload/PdfGenerator.tsx b/src/components/PdfDownload/PdfGenerator.tsx index 3ced911..aedd3ae 100644 --- a/src/components/PdfDownload/PdfGenerator.tsx +++ b/src/components/PdfDownload/PdfGenerator.tsx @@ -292,8 +292,9 @@ const MyDoc: React.FC> = (props) .flatMap((exercise) => { return exercise.exercise_tasks.flatMap((task) => { const grading = task.grading as CustomViewExerciseTaskGrading - const answer = (task.user_answer as CustomViewExerciseTaskSubmission[])[0] - .data_json as UserAnswer + const answer = + !!task.user_answer && + ((task.user_answer as CustomViewExerciseTaskSubmission[])[0].data_json as UserAnswer) const pubSpec = task.public_spec as PublicSpec const gradingFeedback = grading.feedback_json ? (grading.feedback_json as ExerciseFeedback) @@ -346,13 +347,15 @@ const MyDoc: React.FC> = (props) gradingFeedback={exercise.gradingFeedback} userVariables={user_vars} > - + {exercise.answer && ( + + )} ) })}