From 132d251af2d59ef7ae6815321fb79a600937963f Mon Sep 17 00:00:00 2001 From: Daniele Guido Date: Mon, 8 Jan 2024 16:33:00 +0100 Subject: [PATCH] fix re render of the App --- src/App.jsx | 23 ++++------------------- src/components/MapButton.jsx | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/components/MapButton.jsx diff --git a/src/App.jsx b/src/App.jsx index b2726cd..039a4fe 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,8 +1,8 @@ -import { useCallback, useEffect, useState } from 'react' +import { useCallback, useEffect } from 'react' import Header from './components/Header' import Vignette from './components/Vignette' import World from './components/World' -import { Route, Link } from 'react-router-dom' +import { Route } from 'react-router-dom' import AppRoutes from './AppRoutes' import About from './pages/About' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' @@ -16,24 +16,18 @@ import GameControls from './components/GameControls' import Credits from './components/Credits' import GlitchingBooks from './components/GlitchingBooks' import Endings from './components/Endings' -import RoundButton from './components/RoundButton' -import MapIcon from './components/Svg/MapIcon' import { Gameplay, usePlayerStore } from './store/index.js' import { MenuClosed, MenuOpen, useMenuStore } from './store' import ChaptersPage from './pages/Chapters' import MapPage from './pages/Map' +import MapButton from './components/MapButton.jsx' const queryClient = new QueryClient() function App() { - const [active, setActive] = useState(true) const setGameControlsStatus = useMenuStore((state) => state.setGameControlsStatus) const scene = usePlayerStore.getState().scene - const deactivateMapBtn = () => { - setActive(false) - } - useEffect(() => { setGameControlsStatus(MenuOpen) if (scene === Gameplay) { @@ -77,16 +71,7 @@ function App() { -
- - - -
+
diff --git a/src/components/MapButton.jsx b/src/components/MapButton.jsx new file mode 100644 index 0000000..d2844b3 --- /dev/null +++ b/src/components/MapButton.jsx @@ -0,0 +1,24 @@ +import { useState } from 'react' +import { Link, useLocation } from 'react-router-dom' +import RoundButton from './RoundButton' +import MapIcon from './Svg/MapIcon' + +const MapButton = ({ isMobile = false }) => { + const [active, setIsActive] = useState(true) + const { pathname } = useLocation() + + return ( +
+ + setIsActive(false)} + Icon={MapIcon} + margin={isMobile ? '1rem' : '2rem'} + > + +
+ ) +} + +export default MapButton