diff --git a/src/pages/advent-calendar-2024/assets/images/badge.png b/src/pages/advent-calendar-2024/assets/images/badge.png new file mode 100644 index 0000000000..00df6e25f9 Binary files /dev/null and b/src/pages/advent-calendar-2024/assets/images/badge.png differ diff --git a/src/pages/advent-calendar-2024/assets/images/chip.png b/src/pages/advent-calendar-2024/assets/images/chip.png new file mode 100644 index 0000000000..c9dad91020 Binary files /dev/null and b/src/pages/advent-calendar-2024/assets/images/chip.png differ diff --git a/src/pages/advent-calendar-2024/assets/images/naked-card.png b/src/pages/advent-calendar-2024/assets/images/naked-card.png index cae707d6a1..cff67ede18 100644 Binary files a/src/pages/advent-calendar-2024/assets/images/naked-card.png and b/src/pages/advent-calendar-2024/assets/images/naked-card.png differ diff --git a/src/pages/advent-calendar-2024/assets/images/switch.png b/src/pages/advent-calendar-2024/assets/images/switch.png new file mode 100644 index 0000000000..7e21ddd2ce Binary files /dev/null and b/src/pages/advent-calendar-2024/assets/images/switch.png differ diff --git a/src/pages/advent-calendar-2024/assets/images/tooltip.png b/src/pages/advent-calendar-2024/assets/images/tooltip.png new file mode 100644 index 0000000000..abf2f20279 Binary files /dev/null and b/src/pages/advent-calendar-2024/assets/images/tooltip.png differ diff --git a/src/pages/advent-calendar-2024/components/quizzes/guess-component.jsx b/src/pages/advent-calendar-2024/components/quizzes/guess-component.jsx index d4608986ba..abd5efaa51 100644 --- a/src/pages/advent-calendar-2024/components/quizzes/guess-component.jsx +++ b/src/pages/advent-calendar-2024/components/quizzes/guess-component.jsx @@ -17,36 +17,68 @@ import Score from "../score"; import GameBar from "../game-bar"; import MeterSvg from "../../assets/meter"; import NakedCardGuessImg from "../../assets/images/naked-card.png"; +import BadgeGuessImg from "../../assets/images/badge.png"; +import ChipGuessImg from "../../assets/images/chip.png"; +import SwitchGuessImg from "../../assets/images/switch.png"; +import TooltipGuessImg from "../../assets/images/tooltip.png"; import ContentWrapper from "../content-wrapper"; import { UI_LABEL } from "../../utils/constants"; -export const meterGuess = { - id: "meter", - asset: , // Replace with the correct path - answer: "Meter", - options: ["Progress Bar", "Loading Spinner"], - correctAnswer: "This is the Meter component!", -}; - -export const NakedCardGuess = { - id: "nakedCard", - asset: , // Replace with the correct path - answer: "Naked card", - options: ["Data card", "Media card"], - correctAnswer: "This is the Naked card component!", -}; - -const GuessTheComponent = ({ component, onFinish }) => { +export const guessComponentSet1 = [ + { + id: "nakedCard", + asset: , + answer: "Naked card", + options: ["Data card", "Media card"], + correctAnswer: "This is the Naked card component!", + }, + { + id: "meter", + asset: , + answer: "Meter", + options: ["Progress Bar", "Loading Spinner"], + correctAnswer: "This is the Meter component!", + }, + { + id: "chip", + asset: , + answer: "Chip", + options: ["Button", "Tag"], + }, +]; + +export const guessComponentSet2 = [ + { + id: "toltiop", + asset: , + answer: "Tooltip", + options: ["Sheet", "Select"], + }, + { + id: "badge", + asset: , + answer: "Badge", + options: ["Radio button", "Logo"], + }, + { + id: "switch", + asset: , + answer: "Switch", + options: ["Stacking group", "Counter"], + }, +]; + +const GuessTheComponent = ({ questions, onFinish, set }) => { const [currentStep, setCurrentStep] = useState("guessing"); // Steps: 'guessing', 'answer', 'gameOver' + const [currentIndex, setCurrentIndex] = useState(0); const [isCorrect, setIsCorrect] = useState(false); const [score, setScore] = useState(0); - const { id, asset, answer, correctAnswer, options } = component; - const gameName = `Guess The Component ${id}`; + const gameName = `guessComponent${set}`; + const currentQuestion = questions[currentIndex]; + const { asset, answer, correctAnswer, options } = currentQuestion; const shuffledOptions = [...options, answer].sort(() => Math.random() - 0.5); - const { isMobile } = useScreenSize(); - useEffect(() => { const savedGames = JSON.parse(localStorage.getItem("gameScores")) || {}; const savedGame = savedGames[gameName]; @@ -54,18 +86,23 @@ const GuessTheComponent = ({ component, onFinish }) => { if (savedGame?.completed) { setScore(savedGame.score); } - }, []); + }, [gameName]); const handleOptionClick = (option) => { const correct = option === answer; setIsCorrect(correct); - setScore(correct ? 100 : 0); // Fixed score for correct answer + setScore((prevScore) => prevScore + (correct ? 100 : 0)); setCurrentStep("answer"); }; const handleNext = () => { - saveGameData(gameName, score, true); // Save the game state - setCurrentStep("gameOver"); + if (currentIndex < questions.length - 1) { + setCurrentIndex((prevIndex) => prevIndex + 1); + setCurrentStep("guessing"); + } else { + saveGameData(gameName, score, true); // Save the total score for the set + setCurrentStep("gameOver"); + } }; const handleGameEnd = () => { @@ -93,7 +130,7 @@ const GuessTheComponent = ({ component, onFinish }) => { if (currentStep === "gameOver") { return ( - +