From fbfe066365c4099f6c9ae865c8e67b97f6779e52 Mon Sep 17 00:00:00 2001 From: Vinay Anand Lodhi Date: Tue, 29 Oct 2024 16:06:39 +0530 Subject: [PATCH] back buttons added for quiz page --- package-lock.json | 29 +++++++++++++++------------- package.json | 2 +- src/pages/resources/ChanakyaQuiz.jsx | 22 ++++++++++++++++----- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index d4a467e..17ec463 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,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" @@ -1416,9 +1416,10 @@ } }, "node_modules/@remix-run/router": { - "version": "1.16.1", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.16.1.tgz", - "integrity": "sha512-es2g3dq6Nb07iFxGk5GuHN20RwBZOsuDQN7izWIisUcv9r+d2C5jQxqmgkdebXgReWfiyUabcki6Fg77mSNrig==", + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.20.0.tgz", + "integrity": "sha512-mUnk8rPJBI9loFDZ+YzPGdeniYK+FTmRD1TMCz7ev2SNIozyKKpnGgsxO34u6Z4z/t0ITuu7voi/AshfsGsgFg==", + "license": "MIT", "engines": { "node": ">=14.0.0" } @@ -4521,11 +4522,12 @@ } }, "node_modules/react-router": { - "version": "6.23.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.23.1.tgz", - "integrity": "sha512-fzcOaRF69uvqbbM7OhvQyBTFDVrrGlsFdS3AL+1KfIBtGETibHzi3FkoTRyiDJnWNc2VxrfvR+657ROHjaNjqQ==", + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.27.0.tgz", + "integrity": "sha512-YA+HGZXz4jaAkVoYBE98VQl+nVzI+cVI2Oj/06F5ZM+0u3TgedN9Y9kmMRo2mnkSK2nCpNQn0DVob4HCsY/WLw==", + "license": "MIT", "dependencies": { - "@remix-run/router": "1.16.1" + "@remix-run/router": "1.20.0" }, "engines": { "node": ">=14.0.0" @@ -4535,12 +4537,13 @@ } }, "node_modules/react-router-dom": { - "version": "6.23.1", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.23.1.tgz", - "integrity": "sha512-utP+K+aSTtEdbWpC+4gxhdlPFwuEfDKq8ZrPFU65bbRJY+l706qjR7yaidBpo3MSeA/fzwbXWbKBI6ftOnP3OQ==", + "version": "6.27.0", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.27.0.tgz", + "integrity": "sha512-+bvtFWMC0DgAFrfKXKG9Fc+BcXWRUO1aJIihbB79xaeq0v5UzfvnM5houGUm1Y461WVRcgAQ+Clh5rdb1eCx4g==", + "license": "MIT", "dependencies": { - "@remix-run/router": "1.16.1", - "react-router": "6.23.1" + "@remix-run/router": "1.20.0", + "react-router": "6.27.0" }, "engines": { "node": ">=14.0.0" diff --git a/package.json b/package.json index 0d983a4..5a93626 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/pages/resources/ChanakyaQuiz.jsx b/src/pages/resources/ChanakyaQuiz.jsx index 8dc1777..bb06464 100644 --- a/src/pages/resources/ChanakyaQuiz.jsx +++ b/src/pages/resources/ChanakyaQuiz.jsx @@ -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 = [ @@ -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); @@ -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); @@ -170,13 +177,17 @@ const ChanakyaQuiz = () => { <>

Ready to attempt Quiz

+ ) : showResult ? ( - + <> + + + ) : (
@@ -201,6 +212,7 @@ const ChanakyaQuiz = () => { )} +
)}