From 7224145e2b1104cf69fe1083fc3687a9c89fde52 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sat, 17 Sep 2022 11:08:05 -0500 Subject: [PATCH] refactor: move notification area to its own component file --- src/components/Shell/NotificationArea.tsx | 37 +++++++++++++++++++++++ src/components/Shell/Shell.tsx | 32 +++++--------------- 2 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 src/components/Shell/NotificationArea.tsx diff --git a/src/components/Shell/NotificationArea.tsx b/src/components/Shell/NotificationArea.tsx new file mode 100644 index 0000000..01135b7 --- /dev/null +++ b/src/components/Shell/NotificationArea.tsx @@ -0,0 +1,37 @@ +import { forwardRef } from 'react' +import Snackbar from '@mui/material/Snackbar' +import MuiAlert, { AlertProps, AlertColor } from '@mui/material/Alert' + +const Alert = forwardRef(function Alert( + props, + ref +) { + return +}) + +interface NotificationAreaProps { + alertSeverity: AlertColor + alertText: string + isAlertShowing: boolean + onAlertClose: () => void +} + +export const NotificationArea = ({ + alertSeverity, + alertText, + isAlertShowing, + onAlertClose, +}: NotificationAreaProps) => { + return ( + + + {alertText} + + + ) +} diff --git a/src/components/Shell/Shell.tsx b/src/components/Shell/Shell.tsx index 910cebc..c350c56 100644 --- a/src/components/Shell/Shell.tsx +++ b/src/components/Shell/Shell.tsx @@ -1,7 +1,6 @@ import { PropsWithChildren, SyntheticEvent, - forwardRef, useCallback, useContext, useEffect, @@ -11,8 +10,7 @@ import { import CssBaseline from '@mui/material/CssBaseline' import { ThemeProvider, createTheme, styled } from '@mui/material/styles' import Box from '@mui/material/Box' -import Snackbar from '@mui/material/Snackbar' -import MuiAlert, { AlertProps, AlertColor } from '@mui/material/Alert' +import { AlertColor } from '@mui/material/Alert' import { ShellContext } from 'contexts/ShellContext' import { SettingsContext } from 'contexts/SettingsContext' @@ -22,13 +20,7 @@ import { Drawer, drawerWidth } from './Drawer' import { UpgradeDialog } from './UpgradeDialog' import { DrawerHeader } from './DrawerHeader' import { ShellAppBar } from './ShellAppBar' - -const Alert = forwardRef(function Alert( - props, - ref -) { - return -}) +import { NotificationArea } from './NotificationArea' const Main = styled('main', { shouldForwardProp: prop => prop !== 'open' })<{ open?: boolean @@ -140,20 +132,12 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => { display: 'flex', }} > - - - {alertText} - - +