2022-09-16 09:46:11 -05:00
|
|
|
import { styled } from '@mui/material/styles'
|
|
|
|
import MuiAppBar, { AppBarProps as MuiAppBarProps } from '@mui/material/AppBar'
|
|
|
|
import Toolbar from '@mui/material/Toolbar'
|
|
|
|
import Typography from '@mui/material/Typography'
|
|
|
|
import StepIcon from '@mui/material/StepIcon'
|
|
|
|
import Tooltip from '@mui/material/Tooltip'
|
|
|
|
import IconButton from '@mui/material/IconButton'
|
|
|
|
import MenuIcon from '@mui/icons-material/Menu'
|
|
|
|
import LinkIcon from '@mui/icons-material/Link'
|
|
|
|
|
|
|
|
import { drawerWidth } from './Drawer'
|
2022-10-05 01:08:38 +11:00
|
|
|
import { peerListWidth } from './PeerList'
|
2022-09-16 09:46:11 -05:00
|
|
|
|
|
|
|
interface AppBarProps extends MuiAppBarProps {
|
2022-10-05 01:08:38 +11:00
|
|
|
isDrawerOpen?: boolean
|
|
|
|
isPeerListOpen?: boolean
|
2022-09-16 09:46:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const AppBar = styled(MuiAppBar, {
|
2022-10-05 01:08:38 +11:00
|
|
|
shouldForwardProp: prop =>
|
|
|
|
prop !== 'isDrawerOpen' && prop !== 'isPeerListOpen',
|
|
|
|
})<AppBarProps>(({ theme, isDrawerOpen, isPeerListOpen }) => ({
|
2022-09-16 09:46:11 -05:00
|
|
|
transition: theme.transitions.create(['margin', 'width'], {
|
|
|
|
easing: theme.transitions.easing.sharp,
|
|
|
|
duration: theme.transitions.duration.leavingScreen,
|
|
|
|
}),
|
2022-10-05 01:08:38 +11:00
|
|
|
...(isDrawerOpen && {
|
2022-09-16 09:46:11 -05:00
|
|
|
width: `calc(100% - ${drawerWidth}px)`,
|
|
|
|
marginLeft: `${drawerWidth}px`,
|
|
|
|
transition: theme.transitions.create(['margin', 'width'], {
|
|
|
|
easing: theme.transitions.easing.easeOut,
|
|
|
|
duration: theme.transitions.duration.enteringScreen,
|
|
|
|
}),
|
|
|
|
}),
|
2022-10-05 01:08:38 +11:00
|
|
|
...(isPeerListOpen && {
|
|
|
|
width: `calc(100% - ${peerListWidth}px)`,
|
|
|
|
marginRight: `${peerListWidth}px`,
|
|
|
|
transition: theme.transitions.create(['margin', 'width'], {
|
|
|
|
easing: theme.transitions.easing.easeOut,
|
|
|
|
duration: theme.transitions.duration.enteringScreen,
|
|
|
|
}),
|
|
|
|
}),
|
2022-09-16 09:46:11 -05:00
|
|
|
}))
|
|
|
|
|
|
|
|
interface ShellAppBarProps {
|
|
|
|
doShowPeers: boolean
|
2022-10-05 01:08:38 +11:00
|
|
|
onDrawerOpen: () => void
|
|
|
|
onLinkButtonClick: () => Promise<void>
|
2022-09-16 09:46:11 -05:00
|
|
|
isDrawerOpen: boolean
|
2022-10-05 01:08:38 +11:00
|
|
|
isPeerListOpen: boolean
|
2022-09-16 09:46:11 -05:00
|
|
|
numberOfPeers: number
|
|
|
|
title: string
|
2022-10-05 01:08:38 +11:00
|
|
|
onPeerListOpen: () => void
|
2022-09-16 09:46:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ShellAppBar = ({
|
|
|
|
doShowPeers,
|
2022-10-05 01:08:38 +11:00
|
|
|
onDrawerOpen,
|
|
|
|
onLinkButtonClick,
|
2022-09-16 09:46:11 -05:00
|
|
|
isDrawerOpen,
|
2022-10-05 01:08:38 +11:00
|
|
|
isPeerListOpen,
|
2022-09-16 09:46:11 -05:00
|
|
|
numberOfPeers,
|
|
|
|
title,
|
2022-10-05 01:08:38 +11:00
|
|
|
onPeerListOpen,
|
2022-09-16 09:46:11 -05:00
|
|
|
}: ShellAppBarProps) => {
|
|
|
|
return (
|
2022-10-05 01:08:38 +11:00
|
|
|
<AppBar
|
|
|
|
position="fixed"
|
|
|
|
isDrawerOpen={isDrawerOpen}
|
|
|
|
isPeerListOpen={isPeerListOpen}
|
|
|
|
>
|
2022-09-16 09:46:11 -05:00
|
|
|
<Toolbar
|
|
|
|
variant="regular"
|
|
|
|
sx={{
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
size="large"
|
|
|
|
edge="start"
|
|
|
|
color="inherit"
|
|
|
|
aria-label="Open menu"
|
|
|
|
sx={{ mr: 2, ...(isDrawerOpen && { display: 'none' }) }}
|
2022-10-05 01:08:38 +11:00
|
|
|
onClick={onDrawerOpen}
|
2022-09-16 09:46:11 -05:00
|
|
|
>
|
|
|
|
<MenuIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Typography
|
|
|
|
variant="h6"
|
|
|
|
noWrap
|
|
|
|
component="div"
|
|
|
|
sx={{ marginRight: 'auto' }}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Typography>
|
|
|
|
<Tooltip title="Copy current URL">
|
|
|
|
<IconButton
|
|
|
|
size="large"
|
|
|
|
edge="start"
|
|
|
|
color="inherit"
|
|
|
|
aria-label="Copy current URL"
|
|
|
|
sx={{ ml: 'auto' }}
|
2022-10-05 01:08:38 +11:00
|
|
|
onClick={onLinkButtonClick}
|
2022-09-16 09:46:11 -05:00
|
|
|
>
|
|
|
|
<LinkIcon />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
{doShowPeers ? (
|
2022-10-05 01:08:38 +11:00
|
|
|
<Tooltip title="Click to show peer list">
|
2022-10-25 21:43:39 -05:00
|
|
|
<IconButton
|
|
|
|
size="large"
|
|
|
|
edge="end"
|
|
|
|
color="inherit"
|
|
|
|
aria-label="Peer list"
|
2022-10-05 01:08:38 +11:00
|
|
|
onClick={onPeerListOpen}
|
2022-10-25 21:43:39 -05:00
|
|
|
>
|
|
|
|
<StepIcon icon={numberOfPeers} />
|
|
|
|
</IconButton>
|
2022-09-16 09:46:11 -05:00
|
|
|
</Tooltip>
|
|
|
|
) : null}
|
|
|
|
</Toolbar>
|
|
|
|
</AppBar>
|
|
|
|
)
|
|
|
|
}
|