diff --git a/src/pages/advent-calendar-2024/components/calendar-card.jsx b/src/pages/advent-calendar-2024/components/calendar-card.jsx index 63b0a2ad35..cd126464d0 100644 --- a/src/pages/advent-calendar-2024/components/calendar-card.jsx +++ b/src/pages/advent-calendar-2024/components/calendar-card.jsx @@ -8,7 +8,7 @@ import { Text, Text5, } from "@telefonica/mistica"; -import { useRef, useState, useEffect } from "react"; +import { useRef, useState, useEffect, useCallback } from "react"; import { IconCompleted, IconLockOpen } from "../assets/icons/icons"; import { CARD_STATES } from "../utils/constants"; import styles from "./calendar-card.module.css"; @@ -27,6 +27,7 @@ const CalendarCard = ({ }) => { const [isHovered, setIsHovered] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); + const [showDismiss, setShowDismiss] = useState(true); const dialogRef = useRef(null); const day = new Date(DateString).getDate(); const today = new Date().getDate(); @@ -34,7 +35,7 @@ const CalendarCard = ({ const handleClick = () => { if (status === CARD_STATES.AVAILABLE || isRepeatable) { - setIsModalOpen((prev) => !prev); // Toggle modal state + setIsModalOpen(true); // Toggle modal state } }; @@ -52,13 +53,26 @@ const CalendarCard = ({ const handleCloseModal = () => { dialogRef.current.close(); // Close the modal + setIsModalOpen(false); // Update the state onEndDay(); // Notify the parent to update the state }; const handleDismiss = () => { dialogRef.current.close(); + setIsModalOpen(false); }; + const renderContent = useCallback( + ({ closeModal, hideDismiss }) => + typeof content === "function" + ? content({ + closeModal, + hideDismiss: () => setShowDismiss(false), // Wrap the function to avoid immediate state updates + }) + : content, + [content] // Dependencies for memoization + ); + let cardStatusStyles; switch (status) { @@ -236,6 +250,7 @@ const CalendarCard = ({ + {isModalOpen && ( setShowDismiss(false), // Wrapped to avoid direct state updates + })} onClose={handleEndDay} onCancel={repeatable ? handleEndDay : handleDismiss} + showDismiss={showDismiss} /> )} diff --git a/src/pages/advent-calendar-2024/components/games/candy.jsx b/src/pages/advent-calendar-2024/components/games/candy.jsx index 1c473aa7ac..0d6aabc480 100644 --- a/src/pages/advent-calendar-2024/components/games/candy.jsx +++ b/src/pages/advent-calendar-2024/components/games/candy.jsx @@ -13,7 +13,7 @@ import "./candy.css"; const candyColors = [movistar, tu, vivo, blau, telefonica, o2]; -const CandyCrush = ({ onFinish }) => { +const CandyCrush = ({ onFinish, onFinalScreen }) => { const gameName = "candyCrush"; const { isMobile } = useScreenSize(); const width = 8; @@ -38,6 +38,7 @@ const CandyCrush = ({ onFinish }) => { setTimeout(() => { document.querySelector(".grid").classList.add("locked"); setStatus("gameover"); + onFinalScreen(); }, 750); // Wait 750ms before showing the gameover state } }, [movesRemaining]); diff --git a/src/pages/advent-calendar-2024/components/games/higher-or-lower.jsx b/src/pages/advent-calendar-2024/components/games/higher-or-lower.jsx index 0cf9b8eeb7..038613396d 100644 --- a/src/pages/advent-calendar-2024/components/games/higher-or-lower.jsx +++ b/src/pages/advent-calendar-2024/components/games/higher-or-lower.jsx @@ -44,7 +44,7 @@ export const HigherLowerdataSet2 = [ { label: "Teams using the design system", value: 108 }, ]; -const HigherOrLower = ({ set, data, onFinish }) => { +const HigherOrLower = ({ set, data, onFinish, onFinalScreen }) => { const [index, setIndex] = useState(0); const [score, setScore] = useState(0); const [message, setMessage] = useState(""); @@ -98,6 +98,7 @@ const HigherOrLower = ({ set, data, onFinish }) => { } else { setStatus("final"); saveGameData(`higherOrLower${set}`, score, true); + onFinalScreen(); // Notify the parent component } }; diff --git a/src/pages/advent-calendar-2024/components/games/memory.jsx b/src/pages/advent-calendar-2024/components/games/memory.jsx index 4762927f30..1d59b8854e 100644 --- a/src/pages/advent-calendar-2024/components/games/memory.jsx +++ b/src/pages/advent-calendar-2024/components/games/memory.jsx @@ -42,7 +42,7 @@ const initialCards = [ IconBusFilled, ]; -const MemoryGame = ({ onFinish }) => { +const MemoryGame = ({ onFinish, onFinalScreen }) => { const gameName = "memoryGame"; // Unique identifier for this game const timeLimit = 60; // Time in seconds @@ -79,6 +79,7 @@ const MemoryGame = ({ onFinish }) => { if (savedGame?.completed) { setScore(savedGame.score); setGameEnded(true); + onFinalScreen(); // Notify the parent component setStatus("completed"); } else { setCards(shuffle([...initialCards])); @@ -94,6 +95,7 @@ const MemoryGame = ({ onFinish }) => { return () => clearInterval(timerId); } else if (timeRemaining === 0 && !gameEnded) { setGameEnded(true); + onFinalScreen(); // Notify the parent component setStatus("completed"); } }, [timerStarted, timeRemaining, gameEnded]); @@ -146,6 +148,7 @@ const MemoryGame = ({ onFinish }) => { // Check if all pairs are matched if (matchedPairs + 1 === cards.length / 2) { setGameEnded(true); + onFinalScreen(); // Notify the parent component setStatus("completed"); } }; diff --git a/src/pages/advent-calendar-2024/components/games/movie-emoji.jsx b/src/pages/advent-calendar-2024/components/games/movie-emoji.jsx index c52733e545..fd87e4794b 100644 --- a/src/pages/advent-calendar-2024/components/games/movie-emoji.jsx +++ b/src/pages/advent-calendar-2024/components/games/movie-emoji.jsx @@ -85,7 +85,7 @@ export const set2Movies = [ }, ]; -const EmojiMovies = ({ set, movies, onFinish }) => { +const EmojiMovies = ({ set, movies, onFinish, onFinalScreen }) => { const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0); const [showResult, setShowResult] = useState(false); const [isCorrect, setIsCorrect] = useState(false); @@ -131,6 +131,7 @@ const EmojiMovies = ({ set, movies, onFinish }) => { }; if (gameOver) { + onFinalScreen(); // Notify the parent component return (
diff --git a/src/pages/advent-calendar-2024/components/games/simon.jsx b/src/pages/advent-calendar-2024/components/games/simon.jsx index 88e13b01e4..07543b49d1 100644 --- a/src/pages/advent-calendar-2024/components/games/simon.jsx +++ b/src/pages/advent-calendar-2024/components/games/simon.jsx @@ -56,7 +56,7 @@ const UnmuteIcon = () => ( ); -const SimonSays = ({ onFinish }) => { +const SimonSays = ({ onFinish, onFinalScreen }) => { const [sequence, setSequence] = useState([]); const [playerSequence, setPlayerSequence] = useState([]); const [isPlaying, setIsPlaying] = useState(false); @@ -154,6 +154,7 @@ const SimonSays = ({ onFinish }) => { }, 1000); } else { setIsGameOver(true); + onFinalScreen(); setStatus("completed"); setIsPlayerTurn(false); saveGameData(gameName, score, isGameOver); @@ -198,7 +199,9 @@ const SimonSays = ({ onFinish }) => { newSequence[newSequence.length - 1] !== sequence[newSequence.length - 1] ) { setIsGameOver(true); + onFinalScreen(); setStatus("completed"); + setIsPlaying(false); setIsPlayerTurn(false); saveGameData(gameName, score, isGameOver); @@ -279,8 +282,7 @@ const SimonSays = ({ onFinish }) => { ) : ( - - Your final score + Congratulations! You completed the game! diff --git a/src/pages/advent-calendar-2024/components/games/wordle.jsx b/src/pages/advent-calendar-2024/components/games/wordle.jsx index 56907bfbda..11bdd4df2b 100644 --- a/src/pages/advent-calendar-2024/components/games/wordle.jsx +++ b/src/pages/advent-calendar-2024/components/games/wordle.jsx @@ -17,7 +17,7 @@ import { IconCompleted, IconWrong } from "../../assets/icons/icons"; const words = ["tokens"]; const chosenWord = words[0].toLowerCase(); -const WordleGame = ({ onFinish }) => { +const WordleGame = ({ onFinish, onFinalScreen }) => { const [currentAttempt, setCurrentAttempt] = useState([]); const [attempts, setAttempts] = useState([]); const [message, setMessage] = useState(""); @@ -75,6 +75,7 @@ const WordleGame = ({ onFinish }) => { if (input === chosenWord) { setScore(calculateScore(attempts.length + 1)); setMessage(`Amazing! The word was ${chosenWord.toUpperCase()}.`); + onFinalScreen(); setGameStatus("completed"); } else if (attempts.length + 1 === maxAttempts) { setMessage( diff --git a/src/pages/advent-calendar-2024/components/modal-view.jsx b/src/pages/advent-calendar-2024/components/modal-view.jsx index 3f507631c0..6fa29ae4dc 100644 --- a/src/pages/advent-calendar-2024/components/modal-view.jsx +++ b/src/pages/advent-calendar-2024/components/modal-view.jsx @@ -12,7 +12,7 @@ import { DecorationSnake } from "../assets/decorations/decorations"; const ModalView = forwardRef( ( - { title, day, dayOfWeek, description, content, onCancel, repeatable }, + { title, day, dayOfWeek, description, content, onCancel, showDismiss }, ref ) => { const { isMobile, isLargeDesktop } = useScreenSize(); @@ -30,7 +30,7 @@ const ModalView = forwardRef( border: "none", }} > - {isMobile && onCancel !== null && ( + {isMobile && showDismiss && (
@@ -104,8 +104,7 @@ const ModalView = forwardRef( }} > {content} - {} - {!isMobile && onCancel !== null && ( + {!isMobile && showDismiss && (
{ +const GuessTheComponent = ({ questions, onFinish, onFinalScreen, set }) => { const [currentStep, setCurrentStep] = useState("guessing"); // Steps: 'guessing', 'answer', 'gameOver' const [currentIndex, setCurrentIndex] = useState(0); const [isCorrect, setIsCorrect] = useState(false); @@ -100,6 +100,7 @@ const GuessTheComponent = ({ questions, onFinish, set }) => { } else { saveGameData(gameName, score, true); // Save the total score for the set setCurrentStep("gameOver"); + onFinalScreen(); // Notify the parent component } }; diff --git a/src/pages/advent-calendar-2024/index.jsx b/src/pages/advent-calendar-2024/index.jsx index 6bca5ac0ed..358bc0e01d 100644 --- a/src/pages/advent-calendar-2024/index.jsx +++ b/src/pages/advent-calendar-2024/index.jsx @@ -45,7 +45,7 @@ const AdventCalendar2024 = () => { - + ); } diff --git a/src/pages/advent-calendar-2024/pages/coming-soon.jsx b/src/pages/advent-calendar-2024/pages/coming-soon.jsx index e79a7eae7a..7825816881 100644 --- a/src/pages/advent-calendar-2024/pages/coming-soon.jsx +++ b/src/pages/advent-calendar-2024/pages/coming-soon.jsx @@ -13,8 +13,8 @@ import DecorationSnake from "../assets/decorations/decoration-snake"; import CornerLayout from "../components/corner-layout.jsx"; import Snow from "../components/snow.tsx"; -const ComingSoonPage = () => { - const defaultTargetDate = "2024-12-02"; +const ComingSoonPage = ({ targetDate }) => { + const defaultTargetDate = targetDate; const endTimestamp = new Date(defaultTargetDate).getTime(); const [isSnackbarOpen, setSnackbarOpen] = useState(false); diff --git a/src/pages/advent-calendar-2024/pages/progress-view.jsx b/src/pages/advent-calendar-2024/pages/progress-view.jsx index c0e514e585..51216c2da4 100644 --- a/src/pages/advent-calendar-2024/pages/progress-view.jsx +++ b/src/pages/advent-calendar-2024/pages/progress-view.jsx @@ -26,7 +26,6 @@ import { achievementsConfig, getAchievementFromLocalStorage, } from "../utils/achievement-config"; -import { TOTAL_CALENDAR_DAYS } from "../utils/constants"; import { calendarDays } from "../utils/calendar-config.jsx"; const ProgressView = () => { @@ -168,7 +167,7 @@ const ProgressView = () => { Total progress{" "} {Math.round( ((completedDays.length + completedAchievementsCount) / - (TOTAL_CALENDAR_DAYS + totalAchievements)) * + (calendarDays.length + totalAchievements)) * 100 )} % @@ -208,7 +207,7 @@ const ProgressView = () => { > of {" "} - {TOTAL_CALENDAR_DAYS} + {calendarDays.length} @@ -216,7 +215,7 @@ const ProgressView = () => { Total progress{" "} {Math.round( ((completedDays.length + completedAchievementsCount) / - (TOTAL_CALENDAR_DAYS + totalAchievements)) * + (calendarDays.length + totalAchievements)) * 100 )} % @@ -271,7 +270,7 @@ const ProgressView = () => { diff --git a/src/pages/advent-calendar-2024/utils/content-config.jsx b/src/pages/advent-calendar-2024/utils/content-config.jsx index 77954103e9..8859a88e05 100644 --- a/src/pages/advent-calendar-2024/utils/content-config.jsx +++ b/src/pages/advent-calendar-2024/utils/content-config.jsx @@ -54,7 +54,9 @@ const contentByDate = { "2024-12-02": { repeatable: false, Illustration: Illustration02, - content: ({ closeModal }) => , + content: ({ closeModal, hideDismiss }) => ( + + ), title: "“Brandy” crush", description: "Try to match Telefónica brands of the same type in a row or column of 3. You have 10 moves. Can you score the highest with the fewest moves?", @@ -62,8 +64,13 @@ const contentByDate = { "2024-12-03": { repeatable: false, Illustration: Illustration03, - content: ({ closeModal }) => ( - + content: ({ closeModal, hideDismiss }) => ( + ), title: "Emoji movie", description: @@ -81,7 +88,9 @@ const contentByDate = { }, "2024-12-05": { repeatable: false, - content: ({ closeModal }) => , + content: ({ closeModal, hideDismiss }) => ( + + ), Illustration: Illustration05, title: "Wordle", description: ( @@ -170,8 +179,12 @@ const contentByDate = { "2024-12-10": { repeatable: false, Illustration: Illustration10, - content: ({ closeModal }) => ( - + content: ({ closeModal, hideDismiss }) => ( + ), title: "What Mística component is?", description: @@ -180,8 +193,13 @@ const contentByDate = { "2024-12-11": { repeatable: false, Illustration: Illustration11, - content: ({ closeModal }) => ( - + content: ({ closeModal, hideDismiss }) => ( + ), title: "Higher or Lower", description: @@ -198,7 +216,9 @@ const contentByDate = { "2024-12-13": { repeatable: false, Illustration: Illustration13, - content: ({ closeModal }) => , + content: ({ closeModal, hideDismiss }) => ( + + ), title: "Memory cards", description: ( @@ -215,8 +235,13 @@ const contentByDate = { "2024-12-16": { repeatable: false, Illustration: Illustration16, - content: ({ closeModal }) => ( - + content: ({ closeModal, hideDismiss }) => ( + ), title: "Emoji movie", description: @@ -225,8 +250,13 @@ const contentByDate = { "2024-12-17": { repeatable: false, Illustration: Illustration17, - content: ({ closeModal }) => ( - + content: ({ closeModal, hideDismiss }) => ( + ), title: "Higher or Lower", description: @@ -235,11 +265,12 @@ const contentByDate = { "2024-12-18": { repeatable: false, Illustration: Illustration18, - content: ({ closeModal }) => ( + content: ({ closeModal, hideDismiss }) => ( ), title: "What Mística component is?", @@ -256,7 +287,9 @@ const contentByDate = { "2024-12-20": { repeatable: false, Illustration: Illustration20, - content: ({ closeModal }) => , + content: ({ closeModal, hideDismiss }) => ( + + ), title: "Simon says", description: ( <>