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 quiz-new version updated #495

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
65 changes: 39 additions & 26 deletions src/components/Resources/Quiz/Categories/Categories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import {
} from "../CategoriesData";
import CategoriesButtons from "./CategoriesButtons";
import RenderProgressIndicator from "../../../../utils/components/RenderProgressIndicator";
import QuizStartSection from "../QuizStartSection";

export default function Categories() {
const [currentQuestion, setCurrentQuestion] = useState(0);
const [quizStart, setQuizStart] = useState(false);
const [showScore, setShowScore] = useState(false);
const [score, setScore] = useState(0);
const [scoreList, setScoreList] = useState(0);
Expand Down Expand Up @@ -96,33 +98,44 @@ export default function Categories() {
showDropdown={showDropdown}
/>
<QuizSection>
{showScore ? (
<ScoreSection>
<ScoreInfo>
You scored {score} out of {questions.length}
</ScoreInfo>
<ResetButton onClick={() => handleResetButton(score)}>Start again</ResetButton>
</ScoreSection>
{quizStart ? (
<>
{showScore ? (
<ScoreSection>
<ScoreInfo>
You scored {score} out of {questions.length}
</ScoreInfo>
<ResetButton onClick={() => handleResetButton(score)}>Start again</ResetButton>
</ScoreSection>
) : (
<QuizBody>
<QuestionSection>
<QuestionCount>
<RenderProgressIndicator
length={questions.length}
currentQuestion={currentQuestion}
/>
<span>Question {currentQuestion + 1}</span>
</QuestionCount>
<QuestionText>{questions[currentQuestion].questionText}</QuestionText>
</QuestionSection>
<AnswerSection>
{questions[currentQuestion].answerOptions.map((answerOption, i) => (
<QuestionButton
key={i}
onClick={() =>
handleAnswerButtonClick(answerOption.isCorrect, questions.length)
}
>
{answerOption.answerText}
</QuestionButton>
))}
</AnswerSection>
</QuizBody>
)}
</>
) : (
<QuizBody>
<QuestionSection>
<QuestionCount>
<RenderProgressIndicator questionsArray={questions} currentQuestion={currentQuestion} />
<span>Question {currentQuestion + 1}</span>
</QuestionCount>
<QuestionText>{questions[currentQuestion].questionText}</QuestionText>
</QuestionSection>
<AnswerSection>
{questions[currentQuestion].answerOptions.map((answerOption, i) => (
<QuestionButton
key={i}
onClick={() => handleAnswerButtonClick(answerOption.isCorrect, questions.length)}
>
{answerOption.answerText}
</QuestionButton>
))}
</AnswerSection>
</QuizBody>
<QuizStartSection setQuizStart={setQuizStart} />
)}
</QuizSection>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function CategoriesButtons({
const styles = {
background: data.type === categoryToShow ? "white" : "",
color: data.type === categoryToShow ? "black" : "",
borderBottom: data.type === categoryToShow ? "3px solid #22D400" : "",
borderBottom: data.type === categoryToShow ? "3px solid #ff6b07" : "",
};

return (
Expand Down
26 changes: 17 additions & 9 deletions src/components/Resources/Quiz/Categories/CategoriesElements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,20 @@ export const QuizProgressIndicator = styled.div`
gap: 4rem;
`;

export const IndicatorDot = styled.div`
border-radius: 50%;
height: 7px;
width: 7px;
background-color: ${(props) => (props.questionCompleted ? "white" : "rgba(62, 62, 62, 0.76)")};
transition: 0.5s ease;
export const ProgressBar = styled.progress`
-webkit-appearance: none;
width: 100%;
height: 10px;
grid-column: 1 / -1;

::-webkit-progress-bar {
background-color: #fff;
border-radius: 100px;
}
::-webkit-progress-value {
background-color: #ff6b07;
border-radius: 100px;
}
`;

export const QuestionCount = styled.div`
Expand Down Expand Up @@ -118,7 +126,7 @@ export const QuestionButton = styled.button`
transition: 0.1s ease;

&:hover {
background-color: rgb(95, 232, 49);
background-color: #ff6b07;
color: #000000;
}

Expand Down Expand Up @@ -151,7 +159,7 @@ export const CategoriesSection = styled.section`
export const MobileCategories = styled(CategoriesSection)`
background-color: #1a1c1d;
border-radius: 1rem;
box-shadow: 0 0 3px 1px rgba(44, 222, 76, 0.56);
box-shadow: 0 0 3px 1px #ff6b07;
flex-direction: column;
justify-content: start;
max-width: fit-content;
Expand Down Expand Up @@ -181,7 +189,7 @@ export const CategoriesButton = styled.button`
transition: 0.3s ease;

&:hover {
background-color: rgb(95, 232, 49);
background-color: #ff6b07;
color: #000000;
}

Expand Down
57 changes: 57 additions & 0 deletions src/components/Resources/Quiz/QuizStartSection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Logo from "../../../assets/images/Thecyberworld_logo_outlined.png";
import { ResetButton } from "./Categories/CategoriesElements";
import React from "react";
import styled from "styled-components";

const StartSection = styled.div`
display: flex;
flex-direction: column;
width: 50%;
margin: auto;
justify-content: center;
align-items: center;

h1 {
font-size: 2rem;
}

img {
width: 70%;
}

button {
margin-top: 2rem;
padding: 1rem 7rem;
font-family: "Poppins", sans-serif;
border-radius: 10px;
}

button:hover {
background-color: #ff6b07;
color: #000000;
}
@media screen and (max-width: 768px) {
h1 {
font-size: 1.5rem;
}

img {
width: 100%;
}

button {
padding: 1rem 3rem;
}
}
`;

const QuizStartSection = ({ setQuizStart }) => {
return (
<StartSection>
<h1>Quiz Section</h1>
<img src={Logo} alt="" />
<ResetButton onClick={() => setQuizStart(true)}>Start now</ResetButton>
</StartSection>
);
};
export default QuizStartSection;
14 changes: 3 additions & 11 deletions src/utils/components/RenderProgressIndicator.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import React from "react";
import { QuizProgressIndicator, IndicatorDot } from "../../components/Resources/Quiz/Categories/CategoriesElements";
import { QuizProgressIndicator, ProgressBar } from "../../components/Resources/Quiz/Categories/CategoriesElements";

export default function RenderProgressIndicator({ questionsArray, currentQuestion }) {
export default function RenderProgressIndicator({ currentQuestion, length }) {
return (
<QuizProgressIndicator>
{questionsArray.map((e, i) => {
return (
<IndicatorDot
key={i + "key"}
id={i}
questionCompleted={currentQuestion === i || currentQuestion > i}
/>
);
})}
<ProgressBar max={length} value={currentQuestion} />
</QuizProgressIndicator>
);
}