From 441eb06071ee573a02cf7102cb05201c00b78210 Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Fernandez Date: Thu, 25 Apr 2024 17:34:50 +0200 Subject: [PATCH 1/7] fix: fixed a bug when sending the custom game. --- .../components/dashboard/CustomGameMenu.jsx | 35 +++++++++---------- webapp/src/components/game/Game.js | 4 +-- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/webapp/src/components/dashboard/CustomGameMenu.jsx b/webapp/src/components/dashboard/CustomGameMenu.jsx index 603566d9..b4f57307 100644 --- a/webapp/src/components/dashboard/CustomGameMenu.jsx +++ b/webapp/src/components/dashboard/CustomGameMenu.jsx @@ -15,7 +15,7 @@ const CustomGameMenu = ({ isOpen, onClose }) => { const [selectedCategories, setSelectedCategories] = useState([]); const [rounds, setRounds] = useState(9); const [time, setTime] = useState(20); - const [categories, setCategories] = useState([]); + const [allCategories, setAllCategories] = useState([]); const { t, i18n } = useTranslation(); useEffect(() => { @@ -29,10 +29,9 @@ const CustomGameMenu = ({ isOpen, onClose }) => { } else { lang = "en"; } - + const categoriesData = (await gameCategories(lang)).data; - const formattedCategories = categoriesData.map(category => category.name); - setCategories(formattedCategories); + setAllCategories(categoriesData.map(category => category)); } catch (error) { console.error("Error fetching game categories:", error); } @@ -41,10 +40,10 @@ const CustomGameMenu = ({ isOpen, onClose }) => { }, [i18n.language]); const manageCategory = (category) => { - if (selectedCategories.includes(category)) { - setSelectedCategories(selectedCategories.filter(item => item !== category)); + if (selectedCategories.includes(category.internal_representation)) { + setSelectedCategories(selectedCategories.filter(item => item !== category.internal_representation)); } else { - setSelectedCategories([...selectedCategories, category]); + setSelectedCategories([...selectedCategories, category.internal_representation]); } }; @@ -59,17 +58,15 @@ const CustomGameMenu = ({ isOpen, onClose }) => { lang = "en"; } + let categoriesCustom = selectedCategories; const gamemode = 'CUSTOM'; - let uppercaseCategories = selectedCategories.map(category => category.toUpperCase()); - if (uppercaseCategories.length === 0) { - uppercaseCategories = ["GEOGRAPHY", "SPORTS", "MUSIC", "ART", "VIDEOGAMES"]; - } - + if (categoriesCustom.length === 0) + categoriesCustom = allCategories.map(category => category.internal_representation); + const customGameDto = { rounds: rounds, - categories: uppercaseCategories, - round_duration: time - + categories: categoriesCustom, + round_duration: time } const newGameResponse = await newGame(lang, gamemode, customGameDto); if (newGameResponse) { @@ -112,16 +109,16 @@ const CustomGameMenu = ({ isOpen, onClose }) => { {t("game.categories")} - {categories.map(category => ( + {allCategories.map(category => ( ))} diff --git a/webapp/src/components/game/Game.js b/webapp/src/components/game/Game.js index 6c70c410..4322de69 100644 --- a/webapp/src/components/game/Game.js +++ b/webapp/src/components/game/Game.js @@ -10,8 +10,8 @@ export async function getCurrentGame() { return await authManager.getAxiosInstance().get(process.env.REACT_APP_API_ENDPOINT + "/games/play"); } -export async function gameCategories() { - return await authManager.getAxiosInstance().get(process.env.REACT_APP_API_ENDPOINT + "/games/question-categories"); +export async function gameCategories(lang) { + return await authManager.getAxiosInstance().get(process.env.REACT_APP_API_ENDPOINT + "/games/question-categories?lang=" + lang); } export async function gameModes() { From 2a2db089cd8eed4fb2969f6976623131a105e084 Mon Sep 17 00:00:00 2001 From: Gonzalo Alonso Fernandez Date: Thu, 25 Apr 2024 18:46:28 +0200 Subject: [PATCH 2/7] fix: removed some repeated code. --- .../components/dashboard/CustomGameMenu.jsx | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/webapp/src/components/dashboard/CustomGameMenu.jsx b/webapp/src/components/dashboard/CustomGameMenu.jsx index b4f57307..6e5079d0 100644 --- a/webapp/src/components/dashboard/CustomGameMenu.jsx +++ b/webapp/src/components/dashboard/CustomGameMenu.jsx @@ -12,24 +12,18 @@ import { newGame, gameCategories } from 'components/game/Game'; const CustomGameMenu = ({ isOpen, onClose }) => { const navigate = useNavigate(); + const [selectedCategories, setSelectedCategories] = useState([]); + const [allCategories, setAllCategories] = useState([]); const [rounds, setRounds] = useState(9); const [time, setTime] = useState(20); - const [allCategories, setAllCategories] = useState([]); + const { t, i18n } = useTranslation(); useEffect(() => { async function fetchCategories() { try { - let lang = i18n.language; - if (lang.includes("en")) { - lang = "en"; - } else if (lang.includes("es")) { - lang = "es" - } else { - lang = "en"; - } - + const lang = getNormalizedLanguage(i18n.language); const categoriesData = (await gameCategories(lang)).data; setAllCategories(categoriesData.map(category => category)); } catch (error) { @@ -39,43 +33,47 @@ const CustomGameMenu = ({ isOpen, onClose }) => { fetchCategories(); }, [i18n.language]); + const getNormalizedLanguage = (language) => { + if (language.includes("en")) + return "en"; + else if (language.includes("es")) + return "es"; + else + return "en"; + }; + const manageCategory = (category) => { - if (selectedCategories.includes(category.internal_representation)) { + if (selectedCategories.includes(category.internal_representation)) setSelectedCategories(selectedCategories.filter(item => item !== category.internal_representation)); - } else { + else setSelectedCategories([...selectedCategories, category.internal_representation]); - } }; const initializeCustomGameMode = async () => { try { - let lang = i18n.language; - if (lang.includes("en")) { - lang = "en"; - } else if (lang.includes("es")) { - lang = "es" - } else { - lang = "en"; - } + const lang = getNormalizedLanguage(i18n.language); - let categoriesCustom = selectedCategories; const gamemode = 'CUSTOM'; + + let categoriesCustom = selectedCategories; if (categoriesCustom.length === 0) categoriesCustom = allCategories.map(category => category.internal_representation); const customGameDto = { rounds: rounds, categories: categoriesCustom, - round_duration: time + round_duration: time } + const newGameResponse = await newGame(lang, gamemode, customGameDto); - if (newGameResponse) { - navigate("/dashboard/game"); - } - } catch (error) { + + if (newGameResponse) + navigate("/dashboard/game"); + + } catch (error) { console.error("Error initializing game:", error); - } - }; + } + }; return ( From 320e15a61f8316c01f2d94eefcd50e94c8dd82de Mon Sep 17 00:00:00 2001 From: Dario Date: Thu, 25 Apr 2024 22:46:05 +0200 Subject: [PATCH 3/7] fix: added force to release.yml --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf5d60ce..c0b85432 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -175,4 +175,4 @@ jobs: echo "SSL_PASSWORD=${{ secrets.SSL_PASSWORD }}" >> .env docker compose --profile prod down docker compose --profile prod up -d --pull always - docker image prune + docker image prune -f From b895315a835f8c5333626469adbf6a0ab2af7d27 Mon Sep 17 00:00:00 2001 From: sergiorodriguezgarcia <113514397+sergiorodriguezgarcia@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:42:02 +0200 Subject: [PATCH 4/7] feat: Adding menu option in the results page --- webapp/src/pages/Results.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/webapp/src/pages/Results.jsx b/webapp/src/pages/Results.jsx index 6ab60e96..3d8b1267 100644 --- a/webapp/src/pages/Results.jsx +++ b/webapp/src/pages/Results.jsx @@ -1,17 +1,27 @@ -import React from "react"; +import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Button, Flex, Box, Heading, Center } from "@chakra-ui/react"; import { useNavigate, useLocation } from "react-router-dom"; import UserStatistics from "../components/statistics/UserStatistics"; +import LateralMenu from '../components/menu/LateralMenu'; +import MenuButton from '../components/menu/MenuButton'; export default function Results() { - const { t } = useTranslation(); + const { t, i18n } = useTranslation(); const location = useLocation(); const navigate = useNavigate(); const correctAnswers = location.state?.correctAnswers || 0; + const [isMenuOpen, setIsMenuOpen] = useState(false); + + const changeLanguage = async (selectedLanguage) => { + await i18n.changeLanguage(selectedLanguage); + }; return (
+ setIsMenuOpen(true)} /> + setIsMenuOpen(false)} changeLanguage={changeLanguage} isDashboard={false}/> + {t("common.results")} {`Correct answers: ${correctAnswers}`} From 7af12ddc33106f2888b558a2d65c428e6b4f8d57 Mon Sep 17 00:00:00 2001 From: sergiorodriguezgarcia <113514397+sergiorodriguezgarcia@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:26:46 +0200 Subject: [PATCH 5/7] feat: Changing goBack button to follow conventions --- webapp/src/components/GoBack.jsx | 4 ++-- webapp/src/pages/Statistics.jsx | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/webapp/src/components/GoBack.jsx b/webapp/src/components/GoBack.jsx index bd90ef0f..856368a5 100644 --- a/webapp/src/components/GoBack.jsx +++ b/webapp/src/components/GoBack.jsx @@ -6,8 +6,8 @@ import { useNavigate } from "react-router"; export default function GoBack() { const {t} = useTranslation(); const navigate = useNavigate(); - return - diff --git a/webapp/src/pages/Statistics.jsx b/webapp/src/pages/Statistics.jsx index 7d20002e..92ace61f 100644 --- a/webapp/src/pages/Statistics.jsx +++ b/webapp/src/pages/Statistics.jsx @@ -1,4 +1,4 @@ -import { Box, Center, Heading, Stack, StackDivider, Table, Tbody, Text, +import { Box, Center, Heading, Stack, Table, Tbody, Text, Td, Th, Thead, Tr, CircularProgress} from "@chakra-ui/react"; import React, {useEffect, useState} from "react"; import { useTranslation } from "react-i18next"; @@ -80,9 +80,7 @@ export default function Statistics() { t={t} errorWhere={"error.statistics.top"}/> {t("common.statistics.title")} - } minH="50vh" - p="1rem" backgroundColor="whiteAlpha.900" shadow="1.25em" - boxShadow="md" rounded="1rem" alignItems={"center"} data-testid={"leaderboard-component"}> + {retrievedData ? @@ -111,8 +109,8 @@ export default function Statistics() { : } + -
); From 5e7d4b4295b364db0efb5db33a2e27457b574180 Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 26 Apr 2024 16:39:45 +0200 Subject: [PATCH 6/7] feat: readded music QuestionCategory --- .../en2b/quizapi/commons/utils/GameModeUtils.java | 12 ++++++------ .../quizapi/questions/question/QuestionCategory.java | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java index 80c294bc..91ae1e54 100644 --- a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java +++ b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java @@ -15,11 +15,11 @@ public static List getQuestionCategoriesForGamemode(GameMode g gamemode = KIWI_QUEST; } return switch (gamemode) { - case KIWI_QUEST -> List.of(QuestionCategory.ART,/* QuestionCategory.MUSIC, */ QuestionCategory.GEOGRAPHY); + case KIWI_QUEST -> List.of(QuestionCategory.ART,QuestionCategory.MUSIC,QuestionCategory.GEOGRAPHY); case FOOTBALL_SHOWDOWN -> List.of(QuestionCategory.SPORTS); case GEO_GENIUS -> List.of(QuestionCategory.GEOGRAPHY); case VIDEOGAME_ADVENTURE -> List.of(QuestionCategory.VIDEOGAMES); - case ANCIENT_ODYSSEY -> List.of(/*QuestionCategory.MUSIC,*/QuestionCategory.ART); + case ANCIENT_ODYSSEY -> List.of(QuestionCategory.MUSIC,QuestionCategory.ART); case RANDOM -> List.of(QuestionCategory.values()); case CUSTOM -> questionCategoriesForCustom; }; @@ -70,12 +70,12 @@ private static List getQuestionCategoriesEn(){ .description("Are you an art expert? Prove it!") .internalRepresentation(QuestionCategory.ART) .build(), - /* + QuestionCategoryDto.builder() .name("Music") .description("Are you a music lover? Prove it!") .internalRepresentation(QuestionCategory.MUSIC) - .build(),*/ + .build(), QuestionCategoryDto.builder() .name("Geography") .description("Are you a geography expert? Prove it!") @@ -101,12 +101,12 @@ private static List getQuestionCategoriesEs(){ .description("¿Eres un experto en arte? ¡Demuéstralo!") .internalRepresentation(QuestionCategory.ART) .build(), - /* + QuestionCategoryDto.builder() .name("Música") .description("¿Eres un melómano? ¡Demuéstralo!") .internalRepresentation(QuestionCategory.MUSIC) - .build(),*/ + .build(), QuestionCategoryDto.builder() .name("Geografía") .description("¿Eres un experto en geografía? ¡Demuéstralo!") diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java index a6f0e741..d97db494 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionCategory.java @@ -2,6 +2,5 @@ public enum QuestionCategory { //HISTORY, GEOGRAPHY, SCIENCE, MATH, LITERATURE, ART, SPORTS, MUSIC, MOVIES, TV, POLITICS, OTHER - GEOGRAPHY, SPORTS, //MUSIC, - ART, VIDEOGAMES + GEOGRAPHY, SPORTS, MUSIC, ART, VIDEOGAMES } From 5cb75812fe102c039d5a85d07bafa642f7a725f6 Mon Sep 17 00:00:00 2001 From: Dario Date: Fri, 26 Apr 2024 16:45:22 +0200 Subject: [PATCH 7/7] feat: removed music from kiwiquest --- .../main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java index 91ae1e54..047df172 100644 --- a/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java +++ b/api/src/main/java/lab/en2b/quizapi/commons/utils/GameModeUtils.java @@ -15,7 +15,7 @@ public static List getQuestionCategoriesForGamemode(GameMode g gamemode = KIWI_QUEST; } return switch (gamemode) { - case KIWI_QUEST -> List.of(QuestionCategory.ART,QuestionCategory.MUSIC,QuestionCategory.GEOGRAPHY); + case KIWI_QUEST -> List.of(QuestionCategory.ART,QuestionCategory.GEOGRAPHY); case FOOTBALL_SHOWDOWN -> List.of(QuestionCategory.SPORTS); case GEO_GENIUS -> List.of(QuestionCategory.GEOGRAPHY); case VIDEOGAME_ADVENTURE -> List.of(QuestionCategory.VIDEOGAMES);