diff --git a/client/src/hooks/useGame.tsx b/client/src/hooks/useGame.tsx index 552b5f4..56a91d2 100644 --- a/client/src/hooks/useGame.tsx +++ b/client/src/hooks/useGame.tsx @@ -1,10 +1,9 @@ import { useDojo } from "@/dojo/useDojo"; -import { useEffect, useMemo } from "react"; +import { useMemo } from "react"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { useComponentValue } from "@dojoengine/react"; import { Entity } from "@dojoengine/recs"; import useDeepMemo from "./useDeepMemo"; -import { consoleTSLog } from "@/utils/logger"; export const useGame = ({ gameId, diff --git a/client/src/ui/components/BackgroundBoard.tsx b/client/src/ui/components/BackgroundBoard.tsx index 2983e69..b91cfcd 100644 --- a/client/src/ui/components/BackgroundBoard.tsx +++ b/client/src/ui/components/BackgroundBoard.tsx @@ -1,8 +1,6 @@ -import { ReactNode } from "react"; import { motion, MotionProps } from "framer-motion"; interface BackgroundImageProps { - children: ReactNode; imageBackground: string; animate?: MotionProps["animate"]; initial?: MotionProps["initial"]; @@ -10,23 +8,19 @@ interface BackgroundImageProps { } const BackgroundBoard: React.FC = ({ - children, imageBackground, animate, initial, transition, }) => { return ( -
- - {children} -
+ ); }; diff --git a/client/src/ui/components/GameBoard.tsx b/client/src/ui/components/GameBoard.tsx index 3bb0068..1bd39ea 100644 --- a/client/src/ui/components/GameBoard.tsx +++ b/client/src/ui/components/GameBoard.tsx @@ -1,11 +1,4 @@ -import React, { - useState, - useCallback, - useEffect, - useMemo, - useRef, - useLayoutEffect, -} from "react"; +import React, { useState, useCallback, useEffect, useMemo } from "react"; import { Card } from "@/ui/elements/card"; import { useDojo } from "@/dojo/useDojo"; import { GameBonus } from "../containers/GameBonus"; @@ -195,10 +188,13 @@ const GameBoard: React.FC = ({ useEffect(() => { // Reset the isTxProcessing state and the bonus state when the grid changes // meaning the tx as been processed, and the client state updated + consoleTSLog("success", "Game board is trigger"); setBonus(BonusType.None); setBonusDescription(""); }, [initialGrid]); + consoleTSLog("info", "Rendering GameBoard component"); + const memoizedInitialData = useMemo(() => { consoleTSLog("success", "Transforming data in gameboard"); return transformDataContractIntoBlock(initialGrid); diff --git a/client/src/ui/screens/Home.tsx b/client/src/ui/screens/Home.tsx index b9005c8..e90bdef 100644 --- a/client/src/ui/screens/Home.tsx +++ b/client/src/ui/screens/Home.tsx @@ -80,6 +80,8 @@ export const Home = () => { // State variables for modals const [isTournamentsOpen, setIsTournamentsOpen] = useState(false); + const gameIsOver = game?.isOver(); + const composeTweet = useCallback(() => { setLevel(player?.points ? Level.fromPoints(player?.points).value : ""); setScore(game?.score); @@ -87,7 +89,7 @@ export const Home = () => { }, [game?.score, player?.points]); useEffect(() => { - if (game?.over) { + if (gameIsOver) { if (gameGrid.current !== null) { toPng(gameGrid.current, { cacheBust: true }) .then((dataUrl) => { @@ -100,7 +102,7 @@ export const Home = () => { } setIsGameOn("isOver"); } - }, [composeTweet, game?.over]); + }, [composeTweet, gameIsOver]); useEffect(() => { // Check if game is defined and not over @@ -111,7 +113,7 @@ export const Home = () => { setIsGameOn("isOver"); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [game?.over]); + }, [gameIsOver]); const imageTotemTheme = theme === "dark" ? imgAssets.imageTotemDark : imgAssets.imageTotemLight; @@ -135,27 +137,23 @@ export const Home = () => { const [chestIsOpen, setChestIsOpen] = useState(false); const [isGameOverOpen, setIsGameOverOpen] = useState(false); - const prevGameOverRef = useRef(game?.over); + const prevGameOverRef = useRef(gameIsOver); useEffect(() => { if (prevGameOverRef.current !== undefined) { // Check if game.over transitioned from false to true - if (!prevGameOverRef.current && game?.over) { + if (!prevGameOverRef.current && gameIsOver) { setIsGameOverOpen(true); } } // Update the ref with the current value of game.over - prevGameOverRef.current = game?.over; - }, [game?.over]); + prevGameOverRef.current = gameIsOver; + }, [gameIsOver]); useEffect(() => { consoleTSLog("danger", "=============== Grid is changing ==============="); }, [grid]); - /*useEffect(() => { - console.log("==================> Grid is changing"); - }, [grid]);*/ - // Define render functions const renderDesktopView = () => ( <> @@ -246,7 +244,10 @@ export const Home = () => { /> {/* Main Content */} - +
{ repeatType: "reverse", ease: "easeInOut", }} - > -
-
- {!isSigning && } - {(!game || (!!game && isGameOn === "isOver")) && ( - <> - {isMdOrLarger - ? renderDesktopView() - : isTournamentsOpen - ? renderTournamentsView() - : renderMobileView()} - - )} - {game && ( - setIsGameOverOpen(false)} - game={game} - /> - )} - {!!game && isGameOn === "isOver" && !isTournamentsOpen && ( - <> -
-
-

Game Over

- -
-
- {game.score} - -
-
- {game.combo} - -
-
- {game.max_combo} - -
+ /> +
+
+ {!isSigning && } + {(!game || (!!game && isGameOn === "isOver")) && ( + <> + {isMdOrLarger + ? renderDesktopView() + : isTournamentsOpen + ? renderTournamentsView() + : renderMobileView()} + + )} + {game && ( + setIsGameOverOpen(false)} + game={game} + /> + )} + {!!game && isGameOn === "isOver" && !isTournamentsOpen && ( + <> +
+
+

Game Over

+ +
+
+ {game.score} + +
+
+ {game.combo} + +
+
+ {game.max_combo} +
- - {!isTournamentsOpen && ( - - - - - - - - Feedback - -
- -
-
-
- )} - - )} - {!!game && isGameOn === "isOn" && ( -
-
- -
- {isMdOrLarger && ( -
- -
- )}
- )} -
-
- - - {!animationDone && ( - <> - - + + {!isTournamentsOpen && ( + + + + + + + + Feedback + +
+ +
+
+
+ )} )} -
- - + {!!game && isGameOn === "isOn" && ( +
+
+ +
+ {isMdOrLarger && ( +
+ +
+ )} +
+ )} +
+
+ + + {!animationDone && ( + <> + + + + )} + +
);