From fb2a5144a2cb9f6efc1f179623da38311f5cc871 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Wed, 31 Aug 2022 22:05:24 -0500 Subject: [PATCH] refactor: simplify index.tsx --- src/Bootstrap.test.tsx | 11 +- src/Bootstrap.tsx | 34 ++++--- src/components/Shell/Shell.tsx | 181 +++++++++++++++++---------------- src/index.tsx | 18 +--- 4 files changed, 118 insertions(+), 126 deletions(-) diff --git a/src/Bootstrap.test.tsx b/src/Bootstrap.test.tsx index c5702a3..19381e8 100644 --- a/src/Bootstrap.test.tsx +++ b/src/Bootstrap.test.tsx @@ -1,5 +1,4 @@ import { act, render } from '@testing-library/react' -import { MemoryRouter as Router } from 'react-router-dom' import localforage from 'localforage' import { PersistedStorageKeys } from 'models/storage' @@ -26,12 +25,10 @@ const renderBootstrap = async (overrides: BootstrapProps = {}) => { }) render( - - - + ) // https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning#an-alternative-waiting-for-the-mocked-promise diff --git a/src/Bootstrap.tsx b/src/Bootstrap.tsx index df80149..4984159 100644 --- a/src/Bootstrap.tsx +++ b/src/Bootstrap.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { Routes, Route } from 'react-router-dom' +import { BrowserRouter as Router, Routes, Route } from 'react-router-dom' import { v4 as uuid } from 'uuid' import localforage from 'localforage' @@ -48,21 +48,23 @@ function Bootstrap({ }, [hasLoadedSettings, persistedStorage, settings, userId]) return ( - - {hasLoadedSettings ? ( - - {['/', '/index.html'].map(path => ( - } /> - ))} - } - /> - - ) : ( - <> - )} - + + + {hasLoadedSettings ? ( + + {['/', '/index.html'].map(path => ( + } /> + ))} + } + /> + + ) : ( + <> + )} + + ) } diff --git a/src/components/Shell/Shell.tsx b/src/components/Shell/Shell.tsx index 17845b0..9f48cf5 100644 --- a/src/components/Shell/Shell.tsx +++ b/src/components/Shell/Shell.tsx @@ -11,6 +11,7 @@ import { Link } from 'react-router-dom' import CssBaseline from '@mui/material/CssBaseline' import { styled, useTheme } from '@mui/material/styles' import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar' +import { ThemeProvider, createTheme } from '@mui/material/styles' import Drawer from '@mui/material/Drawer' import Toolbar from '@mui/material/Toolbar' import Box from '@mui/material/Box' @@ -94,6 +95,12 @@ const DrawerHeader = styled('div')(({ theme }) => ({ justifyContent: 'flex-end', })) +const darkTheme = createTheme({ + palette: { + mode: 'dark', + }, +}) + export const Shell = ({ children }: ShellProps) => { const theme = useTheme() const [isAlertShowing, setIsAlertShowing] = useState(false) @@ -141,95 +148,97 @@ export const Shell = ({ children }: ShellProps) => { return ( - - - - - {alertText} - - - - - - - - - {title} - - - - - - - + + - - - {theme.direction === 'ltr' ? ( - - ) : ( - - )} - - - - - - - - - - - - - - - - - -
{children}
-
+ + + {alertText} + + + + + + + + + {title} + + + + + + + + + + {theme.direction === 'ltr' ? ( + + ) : ( + + )} + + + + + + + + + + + + + + + + + +
{children}
+ +
) } diff --git a/src/index.tsx b/src/index.tsx index d3f52cf..317255a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,4 @@ import ReactDOM from 'react-dom/client' -import { BrowserRouter as Router } from 'react-router-dom' -import { ThemeProvider, createTheme } from '@mui/material/styles' -import CssBaseline from '@mui/material/CssBaseline' import 'typeface-roboto' import * as serviceWorkerRegistration from 'serviceWorkerRegistration' @@ -9,21 +6,8 @@ import 'index.sass' import Bootstrap from 'Bootstrap' import reportWebVitals from 'reportWebVitals' -const darkTheme = createTheme({ - palette: { - mode: 'dark', - }, -}) - const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement) -root.render( - - - - - - -) +root.render() // If you want to start measuring performance in your app, pass a function // to log results (for example: reportWebVitals(console.log))