diff --git a/gatsby-config.js b/gatsby-config.js index 5a6c085..b033a8a 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -25,7 +25,7 @@ module.exports = { background_color: `#663399`, theme_color: `#663399`, display: `minimal-ui`, - icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site. + icon: `src/images/favicon.png`, // This path is relative to the root of the site. }, }, // this (optional) plugin enables Progressive Web App + Offline functionality diff --git a/package-lock.json b/package-lock.json index 5e3e8de..0c9a23f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3471,6 +3471,11 @@ } } }, + "classnames": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz", + "integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==" + }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -9937,6 +9942,29 @@ "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=" }, + "jsonp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/jsonp/-/jsonp-0.2.1.tgz", + "integrity": "sha1-pltPoPEL2nGaBUQep7lMVfPhW64=", + "requires": { + "debug": "^2.1.3" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -13303,6 +13331,15 @@ "scheduler": "^0.18.0" } }, + "react-share": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/react-share/-/react-share-4.1.0.tgz", + "integrity": "sha512-4/XqVBC+hreniU08zkzAkOGC3FPdJhcLzt1QCdybsZPd5ieUS++iChEEptvNoksiJ5NxbI2VRoDY9ovLAGl7GQ==", + "requires": { + "classnames": "^2.2.5", + "jsonp": "^0.2.1" + } + }, "react-side-effect": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/react-side-effect/-/react-side-effect-1.1.5.tgz", diff --git a/package.json b/package.json index 70f4202..0a35edc 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "react-countdown-circle-timer": "^1.1.1", "react-dom": "^16.12.0", "react-helmet": "^5.2.1", - "react-particles-js": "^2.7.1" + "react-particles-js": "^2.7.1", + "react-share": "^4.1.0" }, "devDependencies": { "axios": "^0.19.2", diff --git a/src/components/progress-bar.js b/src/components/progress-bar.js index 32acb13..bad4cfb 100644 --- a/src/components/progress-bar.js +++ b/src/components/progress-bar.js @@ -2,7 +2,7 @@ import PropTypes from "prop-types" import React from "react" import { GetPercentage } from "../utils/style" -import styles from "./progress-bar.module.css" +import styles from "../styles/progress-bar.module.css" const generateCircles = (count, key) => ( <> diff --git a/src/components/result.js b/src/components/result.js new file mode 100644 index 0000000..09679bd --- /dev/null +++ b/src/components/result.js @@ -0,0 +1,134 @@ +import React, { Component } from "react" +import { + WhatsappShareButton, + WhatsappIcon, + TelegramShareButton, + TelegramIcon, + FacebookShareButton, + FacebookIcon, + // FacebookMessengerShareButton, + // FacebookMessengerIcon +} from "react-share" + +import tick from "../images/tick.svg" +import cross from "../images/cross.svg" +import Constants from "../constants/config" +import logo from "../jsons/team-logo.json" +import styles from "../styles/template.module.css" +import styles2 from "../styles/result.module.css" + +class ResultPage extends Component { + state = { + correct: 0 + } + componentDidMount() { + this.setState(() => { + return { + correct: this.props.result.filter( + ({ player_name, answer }) => player_name.toLowerCase() === answer.toLowerCase() + ).length + } + }) + } + + renderPage = (result) => ( +
+
+ You got {`${this.state.correct} / ${result.length}`} +
+
+ { + result.map(quesObj => { + return ( +
+
+ { + quesObj.teams.map((name, index) => ( +
+ { + index !== 0 && + <> +
+
+ + } + {`${name} +
+ )) + } +
+
+
+ Your answer: {quesObj.answer} + { + quesObj.player_name.toLowerCase() === quesObj.answer + ? Correct answer + : Wrong answer + } +
+ { + quesObj.player_name.toLowerCase() !== quesObj.answer && +
+ Correct answer: {quesObj.player_name} +
+ } +
+
+ ) + }) + } +
+
+
window.location.reload()} + onKeyPress={()=> window.location.reload()} + > + Play again +
+
+ Share it with your friends +
+ + + + {/* + + */} + + + + + + +
+
+
+
+ ) + + render() { + return this.renderPage(this.props.result); + } +} + +export default ResultPage diff --git a/src/components/seo.js b/src/components/seo.js index e15f599..d4617a6 100644 --- a/src/components/seo.js +++ b/src/components/seo.js @@ -33,7 +33,7 @@ function SEO({ description, lang, meta, title }) { lang, }} title={title} - titleTemplate={`%s | ${site.siteMetadata.title}`} + titleTemplate={site.siteMetadata.title} meta={[ { name: `description`, diff --git a/src/components/template.js b/src/components/template.js new file mode 100644 index 0000000..05e0886 --- /dev/null +++ b/src/components/template.js @@ -0,0 +1,137 @@ +import React, { Component } from "react" +import { CountdownCircleTimer } from "react-countdown-circle-timer"; + +import Layout from "./layout" +import ProgressBar from "./progress-bar" +import SEO from "./seo" +import Result from "./result" +import Constants from "../constants/config" +import { GetQuizQuestionIndexes } from "../utils/style" +import list from "../jsons/transfer.json" +import logo from "../jsons/team-logo.json" +import styles from "../styles/template.module.css" + +const selectedIndex = GetQuizQuestionIndexes(Constants.NUMBER_OF_QUESTIONS, list.length) +const data = selectedIndex.map(value => list[value]) + +const renderTime = value => { + if (value === 0) { + return
Too late...
; + } + + return ( +
+
Remaining
+
{value}
+
seconds
+
+ ); +}; + +class Template extends Component { + state = { + currentQuestion: 0, + currentAnswer: "" + } + + renderPage = () => ( + + +
+ { + this.state.currentQuestion < Constants.NUMBER_OF_QUESTIONS && + <> +
+ +
+
+ Who am I? +
+ { + data[this.state.currentQuestion].teams.map((name, index) => ( +
+ {index !== 0 && <>
} + {`${name} +
+ )) + } +
+ { + this.input.disabled = true + setTimeout(() => this.goToNextQuestion(), Constants.TIME_INTERVAL_BETWEEN_QUESTIONS) + return [false, Constants.TIME_INTERVAL_BETWEEN_QUESTIONS] + }} + key={this.state.currentQuestion} + /> +
+ I am + { this.input = input; return input && input.focus() }} + className={styles.input} + type="text" + value={this.state.currentAnswer} + onChange={(evt) => { + this.saveInput(evt.target.value) + }} + /> + + { + data.map(({ player_name }) => +
+
+ Next +
+
+ + } + { + this.state.currentQuestion === Constants.NUMBER_OF_QUESTIONS && + + } +
+ + ) + + goToNextQuestion = () => { + const { currentAnswer, currentQuestion } = this.state + data[currentQuestion].answer = currentAnswer + this.input.disabled = false + this.setState((prevState) => { + return { + currentQuestion: prevState.currentQuestion + 1, + currentAnswer: "" + }; + }) + } + + saveInput = (value) => { + this.setState(() => { + return { + currentAnswer: value + } + }) + } + + render() { + return this.renderPage(); + } +} + +export default Template diff --git a/src/constants/config.js b/src/constants/config.js index 324d32f..f0ecb80 100644 --- a/src/constants/config.js +++ b/src/constants/config.js @@ -1,9 +1,13 @@ const NUMBER_OF_QUESTIONS = 10 const TIME_FOR_EACH_QUESTION = 15 const TIME_INTERVAL_BETWEEN_QUESTIONS = 1500 +const SHARE_LINK_TITLE = "Play football player transfer quiz at" +const APP_ID = "2893375807395705" export default { NUMBER_OF_QUESTIONS, TIME_FOR_EACH_QUESTION, - TIME_INTERVAL_BETWEEN_QUESTIONS + TIME_INTERVAL_BETWEEN_QUESTIONS, + SHARE_LINK_TITLE, + APP_ID } \ No newline at end of file diff --git a/src/images/cross.svg b/src/images/cross.svg new file mode 100644 index 0000000..141139c --- /dev/null +++ b/src/images/cross.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/images/favicon.png b/src/images/favicon.png new file mode 100644 index 0000000..90119f7 Binary files /dev/null and b/src/images/favicon.png differ diff --git a/src/images/gatsby-astronaut.png b/src/images/gatsby-astronaut.png deleted file mode 100644 index da58ece..0000000 Binary files a/src/images/gatsby-astronaut.png and /dev/null differ diff --git a/src/images/gatsby-icon.png b/src/images/gatsby-icon.png deleted file mode 100644 index 908bc78..0000000 Binary files a/src/images/gatsby-icon.png and /dev/null differ diff --git a/src/images/tick.svg b/src/images/tick.svg new file mode 100644 index 0000000..06691a1 --- /dev/null +++ b/src/images/tick.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/pages/index.js b/src/pages/index.js index c0a93b8..cf8eb56 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -1,104 +1,12 @@ 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 Constants from "../constants/config" -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) { - return
Too late...
; - } - - return ( -
-
Remaining
-
{value}
-
seconds
-
- ); -}; +import Template from "../components/template" class Index extends Component { - state = { - currentQuestion: 0 - } renderPage = () => ( - - -
-
- -
-
- Who am I? -
- { - data[this.state.currentQuestion].teams.map((name, index) => ( -
- {index !== 0 && <>
} - {`${name} -
- )) - } -
- { - setTimeout(() => this.goToNextQuestion(), Constants.TIME_INTERVAL_BETWEEN_QUESTIONS) - return [false, Constants.TIME_INTERVAL_BETWEEN_QUESTIONS] - }} - key={this.state.currentQuestion} - /> -
- I am - input && input.focus()} - className={styles.input} type="text" - /> - - { - data.map(({ player_name }) => -
-
- Next -
-
-
- +