diff --git a/package-lock.json b/package-lock.json index 57ce7dd..01dded0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,7 @@ "node": "^17.7.2", "node-sass": "^7.0.1", "react": "^17.0.1", + "react-circular-progressbar": "^2.0.4", "react-countdown-circle-timer": "^3.0.9", "react-dom": "^17.0.1", "react-router": "^5.2.0", @@ -13121,6 +13122,14 @@ "node": ">=14" } }, + "node_modules/react-circular-progressbar": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/react-circular-progressbar/-/react-circular-progressbar-2.0.4.tgz", + "integrity": "sha512-OfX0ThSxRYEVGaQSt0DlXfyl5w4DbXHsXetyeivmoQrh9xA9bzVPHNf8aAhOIiwiaxX2WYWpLDB3gcpsDJ9oww==", + "peerDependencies": { + "react": "^0.14.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" + } + }, "node_modules/react-countdown-circle-timer": { "version": "3.0.9", "resolved": "https://registry.npmjs.org/react-countdown-circle-timer/-/react-countdown-circle-timer-3.0.9.tgz", @@ -26126,6 +26135,12 @@ "whatwg-fetch": "^3.6.2" } }, + "react-circular-progressbar": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/react-circular-progressbar/-/react-circular-progressbar-2.0.4.tgz", + "integrity": "sha512-OfX0ThSxRYEVGaQSt0DlXfyl5w4DbXHsXetyeivmoQrh9xA9bzVPHNf8aAhOIiwiaxX2WYWpLDB3gcpsDJ9oww==", + "requires": {} + }, "react-countdown-circle-timer": { "version": "3.0.9", "resolved": "https://registry.npmjs.org/react-countdown-circle-timer/-/react-countdown-circle-timer-3.0.9.tgz", diff --git a/package.json b/package.json index d86147d..355e0a5 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "node": "^17.7.2", "node-sass": "^7.0.1", "react": "^17.0.1", + "react-circular-progressbar": "^2.0.4", "react-countdown-circle-timer": "^3.0.9", "react-dom": "^17.0.1", "react-router": "^5.2.0", diff --git a/src/mockData/QuizDetails.ts b/src/mockData/QuizDetails.ts index 50c329d..1c1c612 100644 --- a/src/mockData/QuizDetails.ts +++ b/src/mockData/QuizDetails.ts @@ -11,7 +11,7 @@ const QUIZ_DETAILS: QuizDetails[] = [ ], answer: ["System.out.println('Hello, how are you?');"], result: false, - timeLimit: 10, + timeLimit: 5, type: "singleSelect" }, { @@ -24,7 +24,7 @@ const QUIZ_DETAILS: QuizDetails[] = [ ], answer: ["alert('Hello World');"], result: false, - timeLimit: 20, + timeLimit: 10, type: "singleSelect" }, @@ -38,7 +38,7 @@ const QUIZ_DETAILS: QuizDetails[] = [ ], answer: ["B", "C"], result: false, - timeLimit: 35, + timeLimit: 15, type: "multiSelect" }, { diff --git a/src/pages/quiz/Question.module.scss b/src/pages/quiz/Question.module.scss index 611b4fe..88f7ef5 100644 --- a/src/pages/quiz/Question.module.scss +++ b/src/pages/quiz/Question.module.scss @@ -28,6 +28,10 @@ section { .time { font-size: 1.4rem; } + .progressBar{ + width: 5.5rem; + height: 5.5rem; + } } } } \ No newline at end of file diff --git a/src/pages/quiz/Question.tsx b/src/pages/quiz/Question.tsx index 43aa1fb..3bc5c72 100644 --- a/src/pages/quiz/Question.tsx +++ b/src/pages/quiz/Question.tsx @@ -1,7 +1,8 @@ import { useEffect, useState } from "react"; import styles from "./Question.module.scss"; -import { CountdownCircleTimer } from 'react-countdown-circle-timer'; import { secondsToMinutes } from "date-fns"; +import { CircularProgressbar, buildStyles } from 'react-circular-progressbar'; +import 'react-circular-progressbar/dist/styles.css'; interface OwnProp { questionNumber: number; @@ -15,6 +16,9 @@ const Question: React.FC = (props) => { const [seconds, setSeconds] = useState(props.timeLimit); const [duration, setDuration] = useState(props.timeLimit); const displaySeconds = seconds % 60; + const percentage = Math.round(seconds / props.timeLimit * 100); + const time = `${secondsToMinutes(seconds).toString().padStart(2, '0')}:${displaySeconds.toString().padStart(2, '0')}` + useEffect(() => { setSeconds(props.timeLimit); @@ -35,19 +39,6 @@ const Question: React.FC = (props) => { }, [seconds]); - console.log("seconds", seconds); - - - const renderTime = () => { - return ( -
- { - `${secondsToMinutes(seconds).toString().padStart(2, '0')}: - ${displaySeconds.toString().padStart(2, '0')}` - } -
- ); - } return (
@@ -60,20 +51,18 @@ const Question: React.FC = (props) => {
- - { - return { shouldRepeat: true, delay: 1.5 } - }} - strokeWidth={5} > - - {renderTime} - - +
+ ; +