From c9428ea01ef5bf9f7921a6d471db3f6ee2f86683 Mon Sep 17 00:00:00 2001 From: Hasith Yaggahavita Date: Mon, 9 Oct 2023 22:00:43 +0530 Subject: [PATCH] bug fizes --- public/favicon.ico | Bin 0 -> 4286 bytes src/app/components/Header.js | 4 +- src/app/components/quizcomponent.js | 85 +++++++++++++++++++--------- 3 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 public/favicon.ico diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..ba4114aa5c8d35d924924052368da1fcd9340837 GIT binary patch literal 4286 zcmeH}VPut27{|}urcE+w*JM(+HJQouA<0Z-n65M6}m{17O(tq|{Ga zb!#U_2K4wb(y^_`w=L8rM~laQc_AO!@LNC6pAOJ#t*y?EX&k;)E|&gAa1q3u?ROHN zQ;we;kALTfPo?uC<{CH-5|+OQeVvO%9|Bs}m~0vw`VmkOwv*xh+e~{sxZvegOz0y& z|H0mDx!#~FHt^!|*Gy|O;?@BDij94Veh_@h#wOEqPPaZC^yj<}v^DmO2JzVWA60H_I=4z3za;JMV)9y^C-7!z(2vh^1WnEuO{7(SLGNbx zJ{Dsfg}I@@&KP53diXW4Ue$UAQDxiR3^ z?(p*k1uR_mk*)msRWiK<9bAY~Uu) zJ-Y(P?%)4=7vR_Whu&2X=?oIop*DWq^~BQ zKd)c=@(E}M(?DygI*tIXQy0+LHLX0zDQ|3Jw8L*eKc}zbt1&zRZN5EUr#}W-n2+kc z50v>nv~`#61)bmosPp>^={D|kA)lq}V{fYlhnJFLvE1 - SLASSCOM + by SLASSCOM @@ -42,7 +42,7 @@ export default function Header() {
- SLASSCOM + by SLASSCOM
diff --git a/src/app/components/quizcomponent.js b/src/app/components/quizcomponent.js index 5c73137..f7af4a9 100644 --- a/src/app/components/quizcomponent.js +++ b/src/app/components/quizcomponent.js @@ -2,19 +2,21 @@ import React, { useState, useEffect } from "react"; import quizData from "./questions"; import "./quiz.css"; -import { v4 as uuid } from 'uuid'; +import { v4 as uuid } from "uuid"; export default function Quiz() { const [session, setSession] = useState(generateSessionId()); const [currentQuestion, setCurrentQuestion] = useState(0); - const [userAnswers, setUserAnswers] = useState(Array(quizData.Questions.length).fill(null)); + const [userAnswers, setUserAnswers] = useState( + Array(quizData.Questions.length).fill(null) + ); const [recommendedCareers, setRecommendedCareers] = useState([]); const [showLog, setShowLog] = useState(false); const resultCount = 10; // Function to generate a unique sessionId function generateSessionId() { - return uuid() ; + return uuid(); } useEffect(() => { @@ -28,44 +30,68 @@ export default function Quiz() { try { const response = await fetch(url); - if (response.ok) { - // API call was successful, handle the response if needed - } else { - // Handle errors if the API call fails + if (!response.ok) { + console.error( + "error: ", + response.status, + response.statusText, + response.url, + " -" + ); } } catch (error) { - // Handle network errors + console.error(error); } } // Function to call the second API async function callInsertRecommendationsAPI(recommendations) { - const url = `https://script.google.com/macros/s/AKfycbyQ8ARQKdHGnvMj8DW4R1UKTVlRpgFOSGpfkLot7AcB-uyn9DEuYmfrvzh6hAf7Xor3hA/exec?action=insertRecommendations&sessionId=${session}&recommendation=${recommendations.join('&recommendation=')}`; + const url = `https://script.google.com/macros/s/AKfycbyQ8ARQKdHGnvMj8DW4R1UKTVlRpgFOSGpfkLot7AcB-uyn9DEuYmfrvzh6hAf7Xor3hA/exec?action=insertRecommendations&sessionId=${session}&recommendation=${recommendations.join( + "&recommendation=" + )}`; try { const response = await fetch(url); - if (response.ok) { - // API call was successful, handle the response if needed - } else { - // Handle errors if the API call fails + if (!response.ok) { + console.error( + "error: ", + response.status, + response.statusText, + response.url, + " -" + ); } } catch (error) { - // Handle network errors + console.error(error); } } + // function handleNextButtonClick() { + // if (currentQuestion < quizData.Questions.length -1) { + // if (userAnswers[currentQuestion] !== null) { + // const question = quizData.Questions[currentQuestion].Caption; + // const answer = quizData.Questions[currentQuestion].Answers[userAnswers[currentQuestion]].Caption; + // callInsertAnswerAPI(question, answer); + // setCurrentQuestion(currentQuestion + 1); + // } else { + // // Handle the case where the user hasn't selected an answer + // } + // } else if (currentQuestion === quizData.Questions.length - 1) { + // calculateResults(); + // } + // } + function handleNextButtonClick() { - if (currentQuestion < quizData.Questions.length - 1) { - if (userAnswers[currentQuestion] !== null) { - const question = quizData.Questions[currentQuestion].Caption; - const answer = quizData.Questions[currentQuestion].Answers[userAnswers[currentQuestion]].Caption; - callInsertAnswerAPI(question, answer); - setCurrentQuestion(currentQuestion + 1); - } else { - // Handle the case where the user hasn't selected an answer - } - } else if (currentQuestion === quizData.Questions.length - 1) { + const question = quizData.Questions[currentQuestion].Caption; + const answer = + quizData.Questions[currentQuestion].Answers[userAnswers[currentQuestion]] + .Caption; + callInsertAnswerAPI(question, answer); + + if (currentQuestion === quizData.Questions.length - 1) { calculateResults(); + } else { + setCurrentQuestion(currentQuestion + 1); } } @@ -112,17 +138,20 @@ export default function Quiz() { const showBackButton = currentQuestion > 0; const isNextButtonDisabled = userAnswers[currentQuestion] === null; - return (
{!recommendedCareers.length > 0 && ( -

Which tech job is best for my personality?

+

+ Which tech job is best for my personality? +

)}
{recommendedCareers.length === 0 ? (
-

Question {questionNumber} of {totalQuestions}

+

+ Question {questionNumber} of {totalQuestions} +

{questionData.Caption}

{questionData.Answers.map((answer, index) => (
@@ -169,7 +198,7 @@ export default function Quiz() {
    {recommendedCareers.map((career, index) => (
  1. - {career} + {career}
  2. ))}