diff --git a/package-lock.json b/package-lock.json index 290c65f6..737d6d39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "@material-ui/icons": "^4.11.3", "asciidoctor-emoji": "^0.5.0", "i18n": "^0.15.1", + "react-countdown": "^2.3.5", "react-router-dom": "^6.22.1" } }, @@ -663,6 +664,18 @@ "node": ">=0.10.0" } }, + "node_modules/react-countdown": { + "version": "2.3.5", + "resolved": "https://registry.npmjs.org/react-countdown/-/react-countdown-2.3.5.tgz", + "integrity": "sha512-K26ENYEesMfPxhRRtm1r+Pf70SErrvW3g4CArLi/x6MPFjgfDFYePT4UghEj8p2nI0cqVV7/JjDgjyr//U60Og==", + "dependencies": { + "prop-types": "^15.7.2" + }, + "peerDependencies": { + "react": ">= 15", + "react-dom": ">= 15" + } + }, "node_modules/react-dom": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz", diff --git a/package.json b/package.json index a508ec7e..37679c9a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "@material-ui/icons": "^4.11.3", "asciidoctor-emoji": "^0.5.0", "i18n": "^0.15.1", + "react-countdown": "^2.3.5", "react-router-dom": "^6.22.1" } } diff --git a/webapp/src/components/GameMenu/GameMenu.css b/webapp/src/components/GameMenu/GameMenu.css index db52042c..f56fd2d4 100644 --- a/webapp/src/components/GameMenu/GameMenu.css +++ b/webapp/src/components/GameMenu/GameMenu.css @@ -11,8 +11,19 @@ color: white; font-weight: 700; margin: 0.5em; + text-align: center; } +.countdown { + font-weight: 500; + margin: 3em; +} + +.topPanel{ + display: flex; + flex-direction: row; + align-items: center; +} .divMenu { display: flex; flex-direction: column; diff --git a/webapp/src/components/GameMenu/GameMenu.js b/webapp/src/components/GameMenu/GameMenu.js index c5b1169d..25f43792 100644 --- a/webapp/src/components/GameMenu/GameMenu.js +++ b/webapp/src/components/GameMenu/GameMenu.js @@ -1,29 +1,32 @@ import './GameMenu.css'; import { Link } from "react-router-dom"; -import QuestionView from '../questionView/QuestionView'; +import {useTranslation} from "react-i18next"; + export default function GameMenu() { + const[t, i18n] = useTranslation("global"); + return (
-

Game Menu

- - +

{t("gameMenu.title")}

+ +
); } - function ButtonHistoricalData() { + function ButtonHistoricalData({ t }) { function handleClick() { //ir a la vista de historical data alert("Historical Data"); } - return ; + return ; } - function ButtonNewGame() { + function ButtonNewGame({t}) { return ( <> - +

{t("gameMenu.new_game_button")}

); diff --git a/webapp/src/components/questionView/QuestionView.js b/webapp/src/components/questionView/QuestionView.js index e116f32b..cd69d9ba 100644 --- a/webapp/src/components/questionView/QuestionView.js +++ b/webapp/src/components/questionView/QuestionView.js @@ -2,12 +2,15 @@ import Question from './Question'; import QuestionGenerator from './QuestionGenerator'; import { useEffect, useState } from 'react'; import './QuestionView.css'; - +import React from "react"; +import Countdown from "react-countdown"; +import {useTranslation} from "react-i18next"; function QuestionView(){ const questionGenerator = new QuestionGenerator(); const [numQuestion, setnumQuestion] = useState(-1); const [questions, setQuestions] = useState([]); + const[t, i18n] = useTranslation("global"); const generateQuestions = async (numQuestion) => { if (numQuestion < 0) { @@ -33,23 +36,36 @@ function QuestionView(){
{/*Nav*/} {numQuestion >= 0 ? - : + :

Please Wait a bit...

} - -
); } -function QuestionComponent({questions, numQuestion, handleClick}){ +function QuestionComponent({questions, numQuestion, handleClick, t}){ + const renderer = ({seconds, completed }) => { + if (completed) { + + return {t("questionView.end_countdown")}; // Rendered when countdown completes + } else { + return {seconds} {t("questionView.seconds")}; // Render countdown + } + }; + return ( <> +

{questions[numQuestion].getQuestion()}

-
- {questions[numQuestion].getAnswers().map((item, index) => ( - - ))} -

Question counter: {numQuestion}

+
+
+
+
+ {questions[numQuestion].getAnswers().map((item, index) => ( + + ))} + +
+

{t("questionView.question_counter")} {numQuestion}

); } diff --git a/webapp/src/locales/en/messages_en.properties b/webapp/src/locales/en/messages_en.properties index 103b5e56..970112c4 100644 --- a/webapp/src/locales/en/messages_en.properties +++ b/webapp/src/locales/en/messages_en.properties @@ -16,4 +16,3 @@ timeLimit=Time Limit: timeLimitDescription=Some game modes may have a time limit for answering each question. Be quick and accurate to maximize your score. haveFun=Have Fun!: haveFunDescription=Enjoy the game and test your knowledge. Good luck! - diff --git a/webapp/src/translations/en/global.json b/webapp/src/translations/en/global.json index 30b70e9b..b7f7248d 100644 --- a/webapp/src/translations/en/global.json +++ b/webapp/src/translations/en/global.json @@ -41,6 +41,16 @@ "repeat_password_placeholder": "Repeat password", "register_button": "Register", "login_link": "Do you have an account? Login here." + }, + "gameMenu":{ + "history_button":"View Historical Data", + "new_game_button":"Create New Game", + "title":"Game Menu" + }, + "questionView":{ + "seconds":"seconds", + "question_counter":"Question counter :", + "end_countdown":"Time's up!" } } diff --git a/webapp/src/translations/es/global.json b/webapp/src/translations/es/global.json index d43e113f..3277d13a 100644 --- a/webapp/src/translations/es/global.json +++ b/webapp/src/translations/es/global.json @@ -45,6 +45,15 @@ "repeat_password_placeholder": "Repetir contraseña", "register_button": "Registrarse", "login_link": "¿Ya tienes una cuenta? Inicia sesión aquí." + }, + "gameMenu":{ + "history_button":"Ver Historial", + "new_game_button":"Crear nuevo juego", + "title":"Menú del Juego" + },"questionView":{ + "seconds":"segundos", + "question_counter":"Número de pregunta : ", + "end_countdown":"¡Se acabó el tiempo!" }