move hook

This commit is contained in:
Viktor Rådberg
2023-08-30 20:30:55 +02:00
parent 3d9b8fdff6
commit ea95af3684
3 changed files with 16 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ import { Player } from './Types/Player';
import { ThemeProvider } from '@mui/material'; import { ThemeProvider } from '@mui/material';
import { theme } from './Data/theme'; import { theme } from './Data/theme';
import { useAnalytics } from './Data/useAnalytics'; import { useAnalytics } from './Hooks/useAnalytics';
const GlobalStyles = createGlobalStyle` const GlobalStyles = createGlobalStyle`
html, html,
@@ -19,12 +19,12 @@ const GlobalStyles = createGlobalStyle`
} }
`; `;
const RootWrapper2 = styled.div` const StartWrapper = styled.div`
max-width: fit-content; max-width: fit-content;
max-height: fit-content; max-height: fit-content;
`; `;
const RootWrapper = styled.div` const PlayWrapper = styled.div`
max-width: fit-content; max-width: fit-content;
max-height: fit-content; max-height: fit-content;
@media (orientation: portrait) { @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 App = () => {
const analytics = useAnalytics(); const analytics = useAnalytics();
const savedPlayers = localStorage.getItem('players'); const savedPlayers = localStorage.getItem('players');
@@ -61,18 +67,16 @@ const App = () => {
setPlayers(updatedPlayers); setPlayers(updatedPlayers);
}; };
const resetCurrentGame = () => { const resetCurrentGame = async () => {
const currentPlayers = localStorage.getItem('players'); const currentPlayers = localStorage.getItem('players');
if (currentPlayers) { if (currentPlayers) {
analytics.trackEvent('go_to_start', { analytics.trackEvent('go_to_start', {
playersBeforeReset: currentPlayers, playersBeforeReset: currentPlayers,
}); });
} }
await removeLocalStorage();
setPlayers([]); setPlayers([]);
localStorage.removeItem('players');
localStorage.removeItem('playing');
localStorage.removeItem('initialGameSettings');
}; };
return ( return (
@@ -80,22 +84,22 @@ const App = () => {
<GlobalStyles /> <GlobalStyles />
{players.length > 0 && initialGameSettings ? ( {players.length > 0 && initialGameSettings ? (
<RootWrapper> <PlayWrapper>
<Play <Play
players={players} players={players}
onPlayerChange={handlePlayerChange} onPlayerChange={handlePlayerChange}
gridAreas={initialGameSettings?.gridAreas} gridAreas={initialGameSettings?.gridAreas}
resetCurrentGame={resetCurrentGame} resetCurrentGame={resetCurrentGame}
/> />
</RootWrapper> </PlayWrapper>
) : ( ) : (
<RootWrapper2> <StartWrapper>
<StartMenu <StartMenu
initialGameSettings={initialGameSettings} initialGameSettings={initialGameSettings}
setInitialGameSettings={setInitialGameSettings} setInitialGameSettings={setInitialGameSettings}
setPlayers={setPlayers} setPlayers={setPlayers}
/> />
</RootWrapper2> </StartWrapper>
)} )}
</ThemeProvider> </ThemeProvider>
); );

View File

@@ -5,7 +5,7 @@ import { theme } from '../../Data/theme';
import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support'; import { BuyMeCoffee, KoFi } from '../../Icons/generated/Support';
import { Paragraph } from './TextComponents'; import { Paragraph } from './TextComponents';
import LittleGuy from '../../Icons/generated/LittleGuy'; import LittleGuy from '../../Icons/generated/LittleGuy';
import { useAnalytics } from '../../Data/useAnalytics'; import { useAnalytics } from '../../Hooks/useAnalytics';
// import { ButtonBase } from '@mui/material'; // import { ButtonBase } from '@mui/material';