Skip to content

Commit

Permalink
Tested and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 24, 2024
1 parent 59a2b4a commit eecfb76
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit eecfb76

Please sign in to comment.