From eecfb76a5b58d0f995c11640020e1ee3e1d23450 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 20:49:18 +0200 Subject: [PATCH] Tested and fixed --- webapp/src/components/questionView/QuestionView.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/webapp/src/components/questionView/QuestionView.js b/webapp/src/components/questionView/QuestionView.js index 6104772..4a90bc4 100644 --- a/webapp/src/components/questionView/QuestionView.js +++ b/webapp/src/components/questionView/QuestionView.js @@ -14,23 +14,20 @@ import BackButtonToGameMenu from '../fragments/BackButtonToGameMenu'; const creationHistoricalRecord = new CreationHistoricalRecord(); const questionGenerator = new QuestionGenerator(); var points = 0; +var playAsGuestUsername = "Play as Guest" //Wont be ever used as it has spaces +var playAsGuestToken = " " function QuestionView({type= "COMPETITIVE", amount=5}){ const [numQuestion, setnumQuestion] = useState(-1); const [questions, setQuestions] = useState(null); const[t, i18n] = useTranslation("global"); - const cookie = JSON.parse(Cookies.get('user')) + const cookie = JSON.parse(Cookies.get('user')??JSON.stringify({username : playAsGuestUsername, token : playAsGuestToken})) const [audio] = useState(new Audio('/tictac.mp3')); const generateQuestions = async (numQuestion) => { if (numQuestion < 0) { try { - var generatedQuestions; - if(cookie){ - generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); - }else{ - generateQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, null);//playing as guest - } + var generatedQuestions = await questionGenerator.generateQuestions(i18n.language, type, amount, cookie.token); setQuestions(generatedQuestions); setnumQuestion(0); } catch (error) { @@ -114,7 +111,7 @@ function QuestionView({type= "COMPETITIVE", amount=5}){ creationHistoricalRecord.setCompetitive(type === 'COMPETITIVE'); creationHistoricalRecord.setDate(Date.now()); creationHistoricalRecord.setPoints(points); - if(cookie) + if(cookie.username !== playAsGuestUsername) creationHistoricalRecord.sendRecord(cookie.username, cookie.token); } }, 1000);