Skip to content

Commit

Permalink
Merge pull request #47 from Ditectrev/eduardconstantin-main
Browse files Browse the repository at this point in the history
Eduardconstantin main
  • Loading branch information
danieldanielecki authored Dec 3, 2024
2 parents 2d6481f + 4334d94 commit 1da4f64
Show file tree
Hide file tree
Showing 11 changed files with 1,183 additions and 713 deletions.
4 changes: 2 additions & 2 deletions app/exam/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { NextPage } from "next";
import { gql, useQuery } from "@apollo/client";
import useTimer from "@azure-fundamentals/hooks/useTimer";
import { Button } from "@azure-fundamentals/components/Button";
import QuizExamForm from "@azure-fundamentals/components/QuizExamForm";
import QuizExamForm from "@azure-fundamentals/components/QuizExamFormUF";
import { Question } from "@azure-fundamentals/components/types";
import ExamResult from "@azure-fundamentals/components/ExamResult";
import LoadingIndicator from "@azure-fundamentals/components/LoadingIndicator";
Expand Down Expand Up @@ -129,7 +129,7 @@ const Exam: NextPage<{ searchParams: { url: string; name: string } }> = ({
totalQuestions={data.randomQuestions?.length}
currentQuestionIndex={currentQuestionIndex}
question={currentQuestion?.question ?? ""}
options={currentQuestion?.options}
options={currentQuestion?.options ?? []}
images={currentQuestion?.images}
stopTimer={stopTimer}
revealExam={revealExam}
Expand Down
37 changes: 20 additions & 17 deletions components/QuizExamForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useEffect, useState } from "react";
import { useEffect, useState, type FC } from "react";
import Image from "next/image";
import { Question } from "./types";
import { FieldArray, FormikProvider, Field, useFormik } from "formik";
import { Button } from "./Button";
import useResults from "@azure-fundamentals/hooks/useResults";
import LoadingIndicator from "./LoadingIndicator";

type Props = {
isLoading: boolean;
Expand All @@ -25,7 +24,7 @@ type Props = {
images?: { url: string; alt: string }[];
};

const QuizExamForm: React.FC<Props> = ({
const QuizExamForm: FC<Props> = ({
isLoading,
handleNextQuestion,
handleSkipQuestion,
Expand All @@ -44,7 +43,8 @@ const QuizExamForm: React.FC<Props> = ({
images,
}) => {
const [showCorrectAnswer, setShowCorrectAnswer] = useState<boolean>(false);
const { points, savedAnswers, setSavedAnswers } = useResults(questions);
const [savedAnswers, setSavedAnswers] = useState<any>([]);
const { points, reCount } = useResults();
const [selectedImage, setSelectedImage] = useState<{
url: string;
alt: string;
Expand All @@ -64,7 +64,10 @@ const QuizExamForm: React.FC<Props> = ({
],
},
onSubmit: () => {
saveAnswers(false);
reCount({
questions: questions,
answers: savedAnswers,
});
stopTimer();
},
});
Expand All @@ -85,25 +88,23 @@ const QuizExamForm: React.FC<Props> = ({
}
}, [remainingTime]);

const nextQuestion = (skip: boolean) => {
if (skip === false) {
useEffect(() => {
if (savedAnswers.length > 0) {
let done = true;
for (let x = 0; x < savedAnswers.length; x++) {
if (savedAnswers[x] === null && x !== currentQuestionIndex) {
if (savedAnswers[x] === null) {
done = false;
break;
}
}
if (done === true) {
handleCountAnswered();
formik.submitForm();
return;
} else {
saveAnswers(skip);
}
} else {
saveAnswers(skip);
}
}, [savedAnswers]);

const nextQuestion = (skip: boolean) => {
saveAnswers(skip);
let areAllQuestionsAnswered = false;
let i = currentQuestionIndex + 1;
while (savedAnswers[i] !== null && i < totalQuestions) {
Expand Down Expand Up @@ -187,7 +188,7 @@ const QuizExamForm: React.FC<Props> = ({
setSavedAnswers(saved);
};

if (isLoading) return <LoadingIndicator />;
if (isLoading) return <p>Loading...</p>;

return (
<FormikProvider value={formik}>
Expand Down Expand Up @@ -300,7 +301,9 @@ const QuizExamForm: React.FC<Props> = ({
}`}
>
<svg
className={`border rounded-full absolute h-5 w-5 p-0.5 ${
className={`border ${
noOfAnswers > 1 ? "rounded" : "rounded-full"
} absolute h-5 w-5 p-0.5 ${
showCorrectAnswer &&
formik.values.options[index]?.isAnswer
? "text-emerald-500 border-emerald-600"
Expand All @@ -317,7 +320,7 @@ const QuizExamForm: React.FC<Props> = ({
: "hidden"
}`}
fillRule="evenodd"
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"
d="M 2 0 a 2 2 0 0 0 -2 2 v 12 a 2 2 0 0 0 2 2 h 12 a 2 2 0 0 0 2 -2 V 2 a 2 2 0 0 0 -2 -2 H 2 z z"
clipRule="evenodd"
/>
</svg>
Expand Down
Loading

0 comments on commit 1da4f64

Please sign in to comment.