Skip to content

Commit

Permalink
Merge pull request #293 from Arquisoft/develop
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
Toto-hitori authored Apr 26, 2024
2 parents 678d505 + 5cb7581 commit 6f754bf
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public static List<QuestionCategory> 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);
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;
};
Expand Down Expand Up @@ -70,12 +70,12 @@ private static List<QuestionCategoryDto> 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!")
Expand All @@ -101,12 +101,12 @@ private static List<QuestionCategoryDto> 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!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions webapp/src/components/GoBack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { useNavigate } from "react-router";
export default function GoBack() {
const {t} = useTranslation();
const navigate = useNavigate();
return <Flex direction="row" justifyContent="center" alignItems="center">
<Button data-testid={"GoBack"} type="submit" colorScheme="pigment_green" margin={"10px"} className={"custom-button effect1"} onClick={() => navigate("/dashboard")} w="100%">
return <Flex justify={"center"}>
<Button size={"lg"} fontSize={"2xl"} flex={1} data-testid={"GoBack"} type="submit" colorScheme="pigment_green" margin={"0.5rem"} className={"custom-button effect1"} onClick={() => navigate("/dashboard")}>
{t("common.goBack")}
</Button>
</Flex>
Expand Down
79 changes: 37 additions & 42 deletions webapp/src/components/dashboard/CustomGameMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,68 @@ 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 [categories, setCategories] = 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;
const formattedCategories = categoriesData.map(category => category.name);
setCategories(formattedCategories);
setAllCategories(categoriesData.map(category => category));
} catch (error) {
console.error("Error fetching game categories:", error);
}
}
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)) {
setSelectedCategories(selectedCategories.filter(item => item !== category));
} else {
setSelectedCategories([...selectedCategories, category]);
}
if (selectedCategories.includes(category.internal_representation))
setSelectedCategories(selectedCategories.filter(item => item !== category.internal_representation));
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);

const gamemode = 'CUSTOM';
let uppercaseCategories = selectedCategories.map(category => category.toUpperCase());
if (uppercaseCategories.length === 0) {
uppercaseCategories = ["GEOGRAPHY", "SPORTS", "MUSIC", "ART", "VIDEOGAMES"];
}


let categoriesCustom = selectedCategories;
if (categoriesCustom.length === 0)
categoriesCustom = allCategories.map(category => category.internal_representation);
const customGameDto = {
rounds: rounds,
categories: uppercaseCategories,
categories: categoriesCustom,
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 (
<Drawer isOpen={isOpen} placement="right" onClose={onClose}>
Expand Down Expand Up @@ -112,16 +107,16 @@ const CustomGameMenu = ({ isOpen, onClose }) => {
<Box marginTop="2em">
<Text color={"forest_green.500"}>{t("game.categories")}</Text>
<Flex direction="column">
{categories.map(category => (
{allCategories.map(category => (
<Button
key={category}
key={category.name}
className={"custom-button effect2"}
variant={selectedCategories.includes(category) ? "solid" : "outline"}
variant={selectedCategories.includes(category.internal_representation) ? "solid" : "outline"}
colorScheme="green"
margin={"10px"}
onClick={() => manageCategory(category)}
>
{category}
{category.name}
</Button>
))}
</Flex>
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/game/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 12 additions & 2 deletions webapp/src/pages/Results.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<Center display="flex" flexDirection="column" w="100wh" h="100vh" justifyContent="center" alignItems="center" bgImage={'/background.svg'}>
<MenuButton onClick={() => setIsMenuOpen(true)} />
<LateralMenu isOpen={isMenuOpen} onClose={() => setIsMenuOpen(false)} changeLanguage={changeLanguage} isDashboard={false}/>

<Heading as="h2">{t("common.results")}</Heading>
<Box bg="white" p={4} borderRadius="md" boxShadow="md" mt={4} mb={4} w="fit-content" shadow="2xl" rounded="1rem">
<Heading textAlign={"center"} as="h3" color="green.400" fontSize="xl">{`Correct answers: ${correctAnswers}`}</Heading>
Expand Down
8 changes: 3 additions & 5 deletions webapp/src/pages/Statistics.jsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -80,9 +80,7 @@ export default function Statistics() {
t={t} errorWhere={"error.statistics.top"}/>
<FaChartBar style={{ fontSize: '2.5rem', color: 'green' }} />
<Heading as="h1">{t("common.statistics.title")}</Heading>
<Stack spacing={4} divider={<StackDivider />} minH="50vh"
p="1rem" backgroundColor="whiteAlpha.900" shadow="1.25em"
boxShadow="md" rounded="1rem" alignItems={"center"} data-testid={"leaderboard-component"}>
<Stack spacing={4} p="1rem" backgroundColor="whiteAlpha.900" boxShadow="md" rounded="1rem" data-testid={"leaderboard-component"}>
{retrievedData ?
<Box display={"flex"} flexDirection={"column"} justifyContent={"center"} alignItems={"center"}>
<Heading as="h2" fontSize={"1.75em"}>
Expand Down Expand Up @@ -111,8 +109,8 @@ export default function Statistics() {
: <CircularProgress data-testid="leaderboard-spinner" isIndeterminate color={"green"} />
}
<UserStatistics />
<GoBack />
</Stack>
<GoBack />
</Stack>
</Center>
);
Expand Down

0 comments on commit 6f754bf

Please sign in to comment.