From ea95af368427e7cabe3cbc2dc13a7501f7c4f581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20R=C3=A5dberg?= Date: Wed, 30 Aug 2023 20:30:55 +0200 Subject: [PATCH] move hook --- src/App.tsx | 26 +++++++++++++++----------- src/Components/Misc/SupportMe.tsx | 2 +- src/{Data => Hooks}/useAnalytics.ts | 0 3 files changed, 16 insertions(+), 12 deletions(-) rename src/{Data => Hooks}/useAnalytics.ts (100%) diff --git a/src/App.tsx b/src/App.tsx index 6e6a81f..6e8a2d6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,7 +7,7 @@ import { Player } from './Types/Player'; import { ThemeProvider } from '@mui/material'; import { theme } from './Data/theme'; -import { useAnalytics } from './Data/useAnalytics'; +import { useAnalytics } from './Hooks/useAnalytics'; const GlobalStyles = createGlobalStyle` html, @@ -19,12 +19,12 @@ const GlobalStyles = createGlobalStyle` } `; -const RootWrapper2 = styled.div` +const StartWrapper = styled.div` max-width: fit-content; max-height: fit-content; `; -const RootWrapper = styled.div` +const PlayWrapper = styled.div` max-width: fit-content; max-height: fit-content; @media (orientation: portrait) { @@ -32,6 +32,12 @@ const RootWrapper = styled.div` } `; +const removeLocalStorage = async () => { + localStorage.removeItem('initialGameSettings'); + localStorage.removeItem('players'); + localStorage.removeItem('playing'); +}; + const App = () => { const analytics = useAnalytics(); const savedPlayers = localStorage.getItem('players'); @@ -61,18 +67,16 @@ const App = () => { setPlayers(updatedPlayers); }; - const resetCurrentGame = () => { + const resetCurrentGame = async () => { const currentPlayers = localStorage.getItem('players'); if (currentPlayers) { analytics.trackEvent('go_to_start', { playersBeforeReset: currentPlayers, }); } + await removeLocalStorage(); setPlayers([]); - localStorage.removeItem('players'); - localStorage.removeItem('playing'); - localStorage.removeItem('initialGameSettings'); }; return ( @@ -80,22 +84,22 @@ const App = () => { {players.length > 0 && initialGameSettings ? ( - + - + ) : ( - + - + )} ); diff --git a/src/Components/Misc/SupportMe.tsx b/src/Components/Misc/SupportMe.tsx index 38e5564..1332a74 100644 --- a/src/Components/Misc/SupportMe.tsx +++ b/src/Components/Misc/SupportMe.tsx @@ -5,7 +5,7 @@ import { theme } from '../../Data/theme'; import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support'; import { Paragraph } from './TextComponents'; import LittleGuy from '../../Icons/generated/LittleGuy'; -import { useAnalytics } from '../../Data/useAnalytics'; +import { useAnalytics } from '../../Hooks/useAnalytics'; // import { ButtonBase } from '@mui/material'; diff --git a/src/Data/useAnalytics.ts b/src/Hooks/useAnalytics.ts similarity index 100% rename from src/Data/useAnalytics.ts rename to src/Hooks/useAnalytics.ts