Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clue words given at the completion of each quiz #597

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const Dashboard = () => {

const data = await response.response;
if (data && data.points !== undefined) {
console.log(data.points);
setTeamPoints(data.points);
}
} catch (error) {
Expand Down
4 changes: 0 additions & 4 deletions src/pages/public/Companion/components/dataverse/Quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ const QuizDashboard = ({
);

setQuestions(response.response.scannedQRs || []);
console.log(response.response.scannedQRs);
} catch (error) {
console.error("Error fetching completed questions:", error);
}
Expand Down Expand Up @@ -364,19 +363,16 @@ const QuizDashboard = ({
setSelectedRoom={setSelectedRoom}
completed={areAllQuestionsInArray(1, questions)}
roomNumber={1}
letters={"NSCC"}
/>
<QuizCard
setSelectedRoom={setSelectedRoom}
completed={areAllQuestionsInArray(2, questions)}
roomNumber={2}
letters="winner"
/>
<QuizCard
setSelectedRoom={setSelectedRoom}
completed={areAllQuestionsInArray(3, questions)}
roomNumber={3}
letters="2024"
/>
</div>
</div>
Expand Down
70 changes: 58 additions & 12 deletions src/pages/public/Companion/components/dataverse/QuizRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,43 @@ import {
Grid,
Card,
CardContent,
Dialog,
DialogTitle,
DialogContent,
DialogActions,
} from "@material-ui/core";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import {
fetchBackend
} from "utils";

const QuizRoom = ({
roomNumber, goBack, userRegistration, setQuestions, quizData
roomNumber,
goBack,
userRegistration,
setQuestions,
quizData,
}) => {
const [answers, setAnswers] = useState(Array(5).fill(""));
const [selectedOptions, setSelectedOptions] = useState(Array(5).fill(null));
const [completedQuestions, setCompletedQuestions] = useState([]);
const [answerStatus, setAnswerStatus] = useState(Array(5).fill(null)); // To track the current status of answers
const [openPopup, setOpenPopup] = useState(false); // State to control popup visibility

const popupContent = {
1: {
title: "🏆 Room 1 Complete!",
message: "Great job! Your string is: NSCC",
},
2: {
title: "🎯 Room 2 Mastered!",
message: "Fantastic! Your string is: winner",
},
3: {
title: "🚀 Room 3 Achieved!",
message: "Outstanding! Your string is: 2024",
},
};

useEffect(() => {
const fetchCompletedQuestions = async () => {
Expand All @@ -49,7 +73,10 @@ const QuizRoom = ({
}, [userRegistration.id]);

const handleAnswerChange = (index, value) => {
if (completedQuestions.includes(quizData[roomNumber].questions[index]) || answerStatus[index] === "correct") {
if (
completedQuestions.includes(quizData[roomNumber].questions[index]) ||
answerStatus[index] === "correct"
) {
alert("This question has already been answered correctly!");
return;
}
Expand All @@ -60,7 +87,10 @@ const QuizRoom = ({
};

const handleMultipleChoiceAnswer = (index, option) => {
if (completedQuestions.includes(quizData[roomNumber].questions[index]) || answerStatus[index] === "correct") {
if (
completedQuestions.includes(quizData[roomNumber].questions[index]) ||
answerStatus[index] === "correct"
) {
alert("This question has already been answered correctly!");
return;
}
Expand All @@ -74,7 +104,6 @@ const QuizRoom = ({
setAnswers(newAnswers);
};


const checkAnswers = async () => {
const {
correctAnswers, questions
Expand All @@ -88,7 +117,8 @@ const QuizRoom = ({
answers.forEach((answer, index) => {
const question = questions[index];
const isCorrect =
answer.trim().toLowerCase() === correctAnswers[index].trim().toLowerCase();
answer.trim().toLowerCase() ===
correctAnswers[index].trim().toLowerCase();

if (isCorrect) {
newAnswerStatus[index] = "correct";
Expand Down Expand Up @@ -131,20 +161,21 @@ const QuizRoom = ({
setCompletedQuestions((prev) => [...prev, ...newlyScannedQuestions]);
}

const allGreen = questions.every((question, index) =>
completedQuestions.includes(question) || newAnswerStatus[index] === "correct"
const allGreen = questions.every(
(question, index) =>
completedQuestions.includes(question) ||
newAnswerStatus[index] === "correct"
);

if (allGreen) {
alert("Congratulations! All questions are marked correct!");
setOpenPopup(true);
}
} catch (error) {
console.error("Error updating team points:", error);
alert("Failed to update team points. Please try again.");
}
};


const renderQuiz = () => {
const {
questions, questionType, options
Expand Down Expand Up @@ -197,8 +228,11 @@ const QuizRoom = ({
height: "75px",
fontSize: "16px",
backgroundColor:
selectedOptions[index] === option ? "white" : "transparent",
color: selectedOptions[index] === option ? "black" : "white",
selectedOptions[index] === option
? "white"
: "transparent",
color:
selectedOptions[index] === option ? "black" : "white",
border: "2px solid white",
}}
>
Expand Down Expand Up @@ -248,7 +282,7 @@ const QuizRoom = ({
position: "absolute",
top: "10px",
left: "10px",
color: "#fff"
color: "#fff",
}}
onClick={goBack}
>
Expand Down Expand Up @@ -276,6 +310,18 @@ const QuizRoom = ({
>
Check Answers
</Button>

<Dialog open={openPopup} onClose={() => setOpenPopup(false)}>
<DialogTitle>{popupContent[roomNumber]?.title}</DialogTitle>
<DialogContent>
<Typography>{popupContent[roomNumber]?.message}</Typography>
</DialogContent>
<DialogActions>
<Button onClick={() => setOpenPopup(false)} color="primary">
Close
</Button>
</DialogActions>
</Dialog>
</div>
);
};
Expand Down
Loading