From af4502859bcb0751332a3066a09413bc83430d43 Mon Sep 17 00:00:00 2001 From: jeremy bayse Date: Tue, 14 Apr 2026 19:09:58 +0200 Subject: [PATCH] fix: QuizInterface crash on undefined text_content - add null guards and safe optional chaining --- resources/js/Pages/Candidate/QuizInterface.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/resources/js/Pages/Candidate/QuizInterface.vue b/resources/js/Pages/Candidate/QuizInterface.vue index 2502fd5..1876459 100644 --- a/resources/js/Pages/Candidate/QuizInterface.vue +++ b/resources/js/Pages/Candidate/QuizInterface.vue @@ -10,7 +10,7 @@ const props = defineProps({ const currentQuestionIndex = ref(0); const answers = ref({}); -const timeLeft = ref(props.quiz.duration_minutes * 60); +const timeLeft = ref(props.quiz?.duration_minutes ? props.quiz.duration_minutes * 60 : 0); let timer = null; // Initialize answers from existing attempt answers if any @@ -58,8 +58,8 @@ const formatTime = (seconds) => { return `${mins}:${secs.toString().padStart(2, '0')}`; }; -const currentQuestion = computed(() => props.quiz.questions[currentQuestionIndex.value]); -const progress = computed(() => ((currentQuestionIndex.value + 1) / props.quiz.questions.length) * 100); +const currentQuestion = computed(() => props.quiz.questions?.[currentQuestionIndex.value] ?? null); +const progress = computed(() => props.quiz.questions?.length ? ((currentQuestionIndex.value + 1) / props.quiz.questions.length) * 100 : 0); const saveAnswer = async () => { const qid = currentQuestion.value.id; @@ -150,8 +150,11 @@ const finishQuiz = () => {
+ +
Chargement de la question...
+ -
+
@@ -202,7 +205,8 @@ const finishQuiz = () => {