From 6b84704b318ed4bf860769743ac2e99ee70ee3b2 Mon Sep 17 00:00:00 2001 From: Anmol Varma Date: Fri, 3 Apr 2020 02:21:52 +0530 Subject: [PATCH] add progress bar and limit questions --- src/components/footer.js | 3 +-- src/components/progress-bar.js | 35 ++++++++++++++++++++++++++ src/components/progress-bar.module.css | 29 +++++++++++++++++++++ src/constants/config.js | 4 ++- src/pages/index.js | 21 ++++++++++------ src/styles/index.module.css | 3 +-- src/utils/style.js | 6 +++++ 7 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 src/components/progress-bar.js create mode 100644 src/components/progress-bar.module.css create mode 100644 src/utils/style.js diff --git a/src/components/footer.js b/src/components/footer.js index 4364b32..ed3dfa2 100644 --- a/src/components/footer.js +++ b/src/components/footer.js @@ -1,4 +1,3 @@ -import PropTypes from "prop-types" import React from "react" const Footer = () => ( @@ -10,7 +9,7 @@ const Footer = () => ( textAlign: `center` }} > - © {new Date().getFullYear()}, Built with Love ♥ + Built with Love ♥ ) diff --git a/src/components/progress-bar.js b/src/components/progress-bar.js new file mode 100644 index 0000000..32acb13 --- /dev/null +++ b/src/components/progress-bar.js @@ -0,0 +1,35 @@ +import PropTypes from "prop-types" +import React from "react" + +import { GetPercentage } from "../utils/style" +import styles from "./progress-bar.module.css" + +const generateCircles = (count, key) => ( + <> + { + [...Array(count).keys()].map(value =>
) + } + +) + +const ProgressBar = ({ current, total }) => { + const length = GetPercentage(current, total); + return ( +
+
{generateCircles(current, 'done')}
+
{generateCircles(total - current, 'left')}
+
+ ) +} + +ProgressBar.propTypes = { + current: PropTypes.number, + total: PropTypes.number +} + +ProgressBar.defaultProps = { + current: 1, + total: 10 +} + +export default ProgressBar diff --git a/src/components/progress-bar.module.css b/src/components/progress-bar.module.css new file mode 100644 index 0000000..bdd0fc4 --- /dev/null +++ b/src/components/progress-bar.module.css @@ -0,0 +1,29 @@ +.barWrapper{ + display: flex; + background: #ddd; + border-radius: 50px; +} + +.bar{ + height: 30px; + border-radius: 50px; + display: flex; + justify-content: space-around; + align-items: center; +} + +.activeBar{ + background: #2b8a9d; + height: 30px; + border-radius: 50px; + display: flex; + justify-content: space-around; + align-items: center; +} + +.quesTrack{ + border-radius: 50%; + height: 10px; + width: 10px; + background: #fff; +} \ No newline at end of file diff --git a/src/constants/config.js b/src/constants/config.js index 92f510e..324d32f 100644 --- a/src/constants/config.js +++ b/src/constants/config.js @@ -1,7 +1,9 @@ const NUMBER_OF_QUESTIONS = 10 const TIME_FOR_EACH_QUESTION = 15 +const TIME_INTERVAL_BETWEEN_QUESTIONS = 1500 export default { NUMBER_OF_QUESTIONS, - TIME_FOR_EACH_QUESTION + TIME_FOR_EACH_QUESTION, + TIME_INTERVAL_BETWEEN_QUESTIONS } \ No newline at end of file diff --git a/src/pages/index.js b/src/pages/index.js index f5a3f4a..c0a93b8 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -2,11 +2,16 @@ import React, { Component } from "react" import { CountdownCircleTimer } from "react-countdown-circle-timer"; import Layout from "../components/layout" +import ProgressBar from "../components/progress-bar" import SEO from "../components/seo" -import styles from "../styles/index.module.css" import Constants from "../constants/config" -import data from "../jsons/transfer.json" +import { GetQuizQuestionIndexes } from "../utils/style" +import list from "../jsons/transfer.json" import logo from "../jsons/team-logo.json" +import styles from "../styles/index.module.css" + +const selectedIndex = GetQuizQuestionIndexes(Constants.NUMBER_OF_QUESTIONS, list.length) +const data = selectedIndex.map(value => list[value]) const renderTime = value => { if (value === 0) { @@ -32,7 +37,7 @@ class Index extends Component {
- +
Who am I? @@ -47,13 +52,17 @@ class Index extends Component { }
[false, 1000]} + onComplete={() => { + setTimeout(() => this.goToNextQuestion(), Constants.TIME_INTERVAL_BETWEEN_QUESTIONS) + return [false, Constants.TIME_INTERVAL_BETWEEN_QUESTIONS] + }} + key={this.state.currentQuestion} />
I am @@ -91,8 +100,6 @@ class Index extends Component { } render() { - console.log(Constants); - return this.renderPage(); } } diff --git a/src/styles/index.module.css b/src/styles/index.module.css index 395fd44..c31ae1a 100644 --- a/src/styles/index.module.css +++ b/src/styles/index.module.css @@ -15,9 +15,8 @@ } .progressWrapper{ - height: 100px; border-bottom: 1px solid #ddd; - padding: 10px 20px; + padding: 20px 40px; } .contentWrapper{ diff --git a/src/utils/style.js b/src/utils/style.js new file mode 100644 index 0000000..2bd0a07 --- /dev/null +++ b/src/utils/style.js @@ -0,0 +1,6 @@ +export const GetPercentage = (current, total) => Math.ceil(((current / total) * 100)); + +export const GetQuizQuestionIndexes = (length, total) => { + const array = [...Array(total).keys()] + return array.sort(() => { return .5 - Math.random() }).slice(0, length) +} \ No newline at end of file