Skip to content

Commit

Permalink
make build error go away
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshCasper committed Nov 26, 2024
1 parent 5c9106f commit 61a91f0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: Set up Dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ else
fi

log "Building the project..."
npm run build >/dev/null
npm run build

log "Uploading frontend build to S3..."
awslocal s3 mb s3://webapp >/dev/null
Expand Down
28 changes: 25 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11"
}
}
77 changes: 39 additions & 38 deletions frontend/src/components/QuizPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useRef, useCallback } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import {
Container,
Expand Down Expand Up @@ -56,47 +56,50 @@ function QuizPage() {
});
}, [quizID, username, navigate]);

const handleSubmit = (timerExceeded = false, submissionAnswers = answers) => {
if (hasSubmittedRef.current) return;
hasSubmittedRef.current = true;
const handleSubmit = useCallback(
(timerExceeded = false, submissionAnswers = answers) => {
if (hasSubmittedRef.current) return;
hasSubmittedRef.current = true;

setIsSubmitting(true);
const submissionData = {
Username: username,
QuizID: quizID,
Answers: submissionAnswers,
};
if (email) {
submissionData.Email = email;
}
if (timerExceeded) {
submissionData.TimerExceeded = true;
}
setIsSubmitting(true);
const submissionData = {
Username: username,
QuizID: quizID,
Answers: submissionAnswers,
};
if (email) {
submissionData.Email = email;
}
if (timerExceeded) {
submissionData.TimerExceeded = true;
}

fetch(`${process.env.REACT_APP_API_ENDPOINT}/submitquiz`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(submissionData),
})
.then((res) => res.json())
.then((data) => {
navigate('/result', {
state: { submissionID: data.SubmissionID, quizID },
});
fetch(`${process.env.REACT_APP_API_ENDPOINT}/submitquiz`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(submissionData),
})
.catch((err) => {
console.error('Error submitting quiz:', err);
alert('Failed to submit quiz. Please try again.');
setIsSubmitting(false);
hasSubmittedRef.current = false;
});
};
.then((res) => res.json())
.then((data) => {
navigate('/result', {
state: { submissionID: data.SubmissionID, quizID },
});
})
.catch((err) => {
console.error('Error submitting quiz:', err);
alert('Failed to submit quiz. Please try again.');
setIsSubmitting(false);
hasSubmittedRef.current = false;
});
},
[answers, email, navigate, quizID, username]
);

const moveToNextQuestion = () => {
const moveToNextQuestion = useCallback(() => {
if (quizData && currentQuestionIndex < quizData.Questions.length - 1) {
setCurrentQuestionIndex((prevIndex) => prevIndex + 1);
}
};
}, [quizData, currentQuestionIndex]);

const handleSkip = () => {
const timeTaken =
Expand Down Expand Up @@ -171,7 +174,7 @@ function QuizPage() {

return () => clearInterval(timerRef.current);
}
}, [currentQuestionIndex, quizData]);
}, [currentQuestionIndex, quizData, moveToNextQuestion, handleSubmit]);

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

0 comments on commit 61a91f0

Please sign in to comment.