Skip to content

Commit 06affcc

Browse files
committed
make build error go away
1 parent 5c9106f commit 06affcc

File tree

4 files changed

+68
-42
lines changed

4 files changed

+68
-42
lines changed

.github/workflows/integration-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Setup Node.js
3737
uses: actions/setup-node@v4
3838
with:
39-
node-version: 20
39+
node-version: 22
4040

4141
- name: Set up Dependencies
4242
run: |

frontend/package-lock.json

+25-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
"last 1 firefox version",
4444
"last 1 safari version"
4545
]
46+
},
47+
"devDependencies": {
48+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
4649
}
4750
}

frontend/src/components/QuizPage.js

+39-38
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useRef } from 'react';
1+
import React, { useState, useEffect, useRef, useCallback } from 'react';
22
import { useLocation, useNavigate } from 'react-router-dom';
33
import {
44
Container,
@@ -56,47 +56,50 @@ function QuizPage() {
5656
});
5757
}, [quizID, username, navigate]);
5858

59-
const handleSubmit = (timerExceeded = false, submissionAnswers = answers) => {
60-
if (hasSubmittedRef.current) return;
61-
hasSubmittedRef.current = true;
59+
const handleSubmit = useCallback(
60+
(timerExceeded = false, submissionAnswers = answers) => {
61+
if (hasSubmittedRef.current) return;
62+
hasSubmittedRef.current = true;
6263

63-
setIsSubmitting(true);
64-
const submissionData = {
65-
Username: username,
66-
QuizID: quizID,
67-
Answers: submissionAnswers,
68-
};
69-
if (email) {
70-
submissionData.Email = email;
71-
}
72-
if (timerExceeded) {
73-
submissionData.TimerExceeded = true;
74-
}
64+
setIsSubmitting(true);
65+
const submissionData = {
66+
Username: username,
67+
QuizID: quizID,
68+
Answers: submissionAnswers,
69+
};
70+
if (email) {
71+
submissionData.Email = email;
72+
}
73+
if (timerExceeded) {
74+
submissionData.TimerExceeded = true;
75+
}
7576

76-
fetch(`${process.env.REACT_APP_API_ENDPOINT}/submitquiz`, {
77-
method: 'POST',
78-
headers: { 'Content-Type': 'application/json' },
79-
body: JSON.stringify(submissionData),
80-
})
81-
.then((res) => res.json())
82-
.then((data) => {
83-
navigate('/result', {
84-
state: { submissionID: data.SubmissionID, quizID },
85-
});
77+
fetch(`${process.env.REACT_APP_API_ENDPOINT}/submitquiz`, {
78+
method: 'POST',
79+
headers: { 'Content-Type': 'application/json' },
80+
body: JSON.stringify(submissionData),
8681
})
87-
.catch((err) => {
88-
console.error('Error submitting quiz:', err);
89-
alert('Failed to submit quiz. Please try again.');
90-
setIsSubmitting(false);
91-
hasSubmittedRef.current = false;
92-
});
93-
};
82+
.then((res) => res.json())
83+
.then((data) => {
84+
navigate('/result', {
85+
state: { submissionID: data.SubmissionID, quizID },
86+
});
87+
})
88+
.catch((err) => {
89+
console.error('Error submitting quiz:', err);
90+
alert('Failed to submit quiz. Please try again.');
91+
setIsSubmitting(false);
92+
hasSubmittedRef.current = false;
93+
});
94+
},
95+
[answers, email, navigate, quizID, username]
96+
);
9497

95-
const moveToNextQuestion = () => {
98+
const moveToNextQuestion = useCallback(() => {
9699
if (quizData && currentQuestionIndex < quizData.Questions.length - 1) {
97100
setCurrentQuestionIndex((prevIndex) => prevIndex + 1);
98101
}
99-
};
102+
}, [quizData, currentQuestionIndex]);
100103

101104
const handleSkip = () => {
102105
const timeTaken =
@@ -171,7 +174,7 @@ function QuizPage() {
171174

172175
return () => clearInterval(timerRef.current);
173176
}
174-
}, [currentQuestionIndex, quizData]);
177+
}, [currentQuestionIndex, quizData, moveToNextQuestion, handleSubmit]);
175178

176179
const handleOptionChange = (e) => {
177180
const selectedOption = e.target.value;
@@ -194,8 +197,6 @@ function QuizPage() {
194197
if (currentQuestionIndex < quizData.Questions.length - 1) {
195198
moveToNextQuestion();
196199
} else {
197-
// Do not auto-submit on the last question
198-
// Start the timer for the last question
199200
if (quizData.EnableTimer) {
200201
setTimeLeft(quizData.TimerSeconds);
201202
questionStartTimeRef.current = Date.now();

0 commit comments

Comments
 (0)