From 44becd4daeb0a82f2aa2da6da14efd46869060c2 Mon Sep 17 00:00:00 2001 From: Dario Date: Tue, 9 Apr 2024 01:21:41 +0200 Subject: [PATCH] chore: fix warnings --- .github/workflows/release.yml | 42 +---------------------------------- webapp/src/pages/Game.jsx | 32 +++++++++++++------------- 2 files changed, 18 insertions(+), 56 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 036d4a50..5f98e857 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,50 +4,12 @@ on: push: branches: - master + - develop release: types: [published] jobs: - unit-tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - uses: actions/checkout@v4 - - run: npm --prefix webapp ci - - run: npm --prefix webapp test -- --coverage - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - run: mvn clean verify - working-directory: api - env: - DATABASE_USER: ${{ secrets.DATABASE_USER }} - DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} - JWT_SECRET: ${{ secrets.JWT_SECRET }} - - name: Analyze with SonarCloud - uses: sonarsource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - e2e-tests: - needs: [ unit-tests ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: 20 - - run: npm --prefix webapp install - - run: npm --prefix webapp run build - # - run: npm --prefix webapp run test:e2e docker-push-api: runs-on: ubuntu-latest - needs: [ e2e-tests ] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -71,7 +33,6 @@ jobs: permissions: contents: read packages: write - needs: [ e2e-tests ] steps: - uses: actions/checkout@v4 @@ -94,7 +55,6 @@ jobs: REACT_APP_API_ENDPOINT docker-push-question-generator: runs-on: ubuntu-latest - needs: [ e2e-tests ] steps: - uses: actions/checkout@v4 - name: Publish to Registry diff --git a/webapp/src/pages/Game.jsx b/webapp/src/pages/Game.jsx index 22599bb5..da6fb7fe 100644 --- a/webapp/src/pages/Game.jsx +++ b/webapp/src/pages/Game.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useCallback } from "react"; +import React, { useState, useEffect } from "react"; import { Grid, Flex, Heading, Button, Box, Text, Spinner, CircularProgress } from "@chakra-ui/react"; import { Center } from "@chakra-ui/layout"; import { useNavigate } from "react-router-dom"; @@ -43,7 +43,7 @@ export default function Game() { /* Generate new question when the round changes */ - const assignQuestion = useCallback(async (gameId) => { + const assignQuestion = async (gameId) => { try { const result = await getCurrentQuestion(gameId); if (result.status === HttpStatusCode.Ok) { @@ -57,7 +57,7 @@ export default function Game() { console.error("Error fetching question:", error); navigate("/dashboard"); } - }, [navigate]); + } const answerButtonClick = async (optionIndex, answer) => { const selectedOptionIndex = selectedOption === optionIndex ? null : optionIndex; @@ -67,7 +67,7 @@ export default function Game() { setNextDisabled(!anyOptionSelected); }; - const startNewRound = useCallback(async (gameId) => { + const startNewRound = async (gameId) => { try{ console.log("pepe"); const result = await startRound(gameId); @@ -88,7 +88,7 @@ export default function Game() { } - }, [roundNumber, correctAnswers, assignQuestion, navigate]); + } /* Initialize game when loading the page @@ -122,9 +122,7 @@ export default function Game() { } }; - initializeGame(); - - const nextRound = useCallback(async () => { + const nextRound = async () => { if (roundNumber + 1 > maxRoundNumber) navigate("/dashboard/game/results", { state: { correctAnswers: correctAnswers } }); else { @@ -134,10 +132,9 @@ export default function Game() { await startNewRound(gameId); } - }, [gameId, maxRoundNumber, roundNumber, startNewRound, - correctAnswers, navigate]); + } - const nextButtonClick = useCallback(async () => { + const nextButtonClick = async () => { try { const result = await answerQuestion(gameId, answer.id); let isCorrect = result.data.was_correct; @@ -152,11 +149,15 @@ export default function Game() { if(error.response.status === 400){ setTimeout(nextButtonClick, 2000) }else{ - console.log('xd'+error.status) + console.log('xd'+error.response.status) } } - }, [gameId, answer.id, nextRound, correctAnswers]); - + }; + useEffect(() => { + // Empty dependency array [] ensures this effect runs only once after initial render + initializeGame(); + // eslint-disable-next-line + }, []); useEffect(() => { let timeout; if (showConfetti) @@ -177,7 +178,8 @@ export default function Game() { }, 1000); } return () => clearTimeout(timeout); - }, [timeElapsed, nextRound, timeStartRound, roundDuration]); + // eslint-disable-next-line + }, [timeElapsed, timeStartRound, roundDuration]); return (