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

back buttons added for quiz page: #351 done #373

Merged
merged 1 commit into from
Oct 29, 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
29 changes: 16 additions & 13 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react-loader-spinner": "^6.1.6",
"react-parallax-tilt": "^1.7.229",
"react-player": "^2.16.0",
"react-router-dom": "^6.23.1",
"react-router-dom": "^6.27.0",
"react-spinners": "^0.14.1",
"react-top-loading-bar": "^2.3.1",
"react-typed": "^2.0.12"
Expand Down
22 changes: 17 additions & 5 deletions src/pages/resources/ChanakyaQuiz.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom'; // Only import useNavigate
import "./../../css/ChanakyaQuiz.css";

const allQuestions = [
Expand Down Expand Up @@ -113,6 +114,8 @@ const getRandomQuestions = (questions, num) => {
};

const ChanakyaQuiz = () => {
const navigate = useNavigate(); // Initialize useNavigate

const [started, setStarted] = useState(false);
const [questions, setQuestions] = useState([]);
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0);
Expand All @@ -133,6 +136,10 @@ const ChanakyaQuiz = () => {
setUserAnswers(newAnswers);
};

const handleBackToHome = () => {
navigate('/'); // Navigate to the home page
};

const handleNext = () => {
if (currentQuestionIndex < questions.length - 1) {
setCurrentQuestionIndex(currentQuestionIndex + 1);
Expand Down Expand Up @@ -170,13 +177,17 @@ const ChanakyaQuiz = () => {
<>
<h1>Ready to attempt Quiz</h1>
<button className="start-button" onClick={startQuiz}>Start Quiz</button>
<button className="start-button" onClick={handleBackToHome}>Back</button>
</>
) : showResult ? (
<Result
score={calculateScore()}
questions={questions}
userAnswers={userAnswers}
/>
<>
<Result
score={calculateScore()}
questions={questions}
userAnswers={userAnswers}
/>
<button className="quizbuttons" onClick={handleBackToHome}>Back</button>
</>
) : (
<div>
<div className="question-number">
Expand All @@ -201,6 +212,7 @@ const ChanakyaQuiz = () => {
<button className="quizbuttons" onClick={finishQuiz}>Finish</button>
)}
<button className="quizbuttons" onClick={handleSkip}>Skip</button>
<button className="quizbuttons" onClick={handleBackToHome}>Back</button>
</div>
</div>
)}
Expand Down