forked from Shiloh/old-remnantchat
* feat(sdk): render iframe in chat-room component * fix(ci): install optional dependencies * feat(sdk): allow subset of attributes * feat(sdk): accept root-domain attribute * feat(sdk): accept custom room name or use sane default * feat(sdk): set allowed features * feat(sdk): add sdk instructions to embed code dialog * fix(sdk): use dynamic rootUrl * fix(sdk): use static defaultRoot * feat(sdk): send config from SDK to chat * fix(sdk): expire poller * fix(sdk): pass parent domain to iframe via query param * refactor(sdk): type message event data * feat(sdk): send user id to chat frame * feat(sdk): handle some attribute updates * chore(package): add build:sdk:watch script * refactor(sdk): move more code to updateIframeAttributes * feat(sdk): support changing rooms * feat(sdk): support more user settings * docs(sdk): add SDK section to README * feat(sdk): render root-url in embed code if necessary * refactor(sdk): use map for chat room attributes * fix(sdk): unbind event listener when chat-room is disconnected * fix(sdk): properly tear down receipt listener * fix(sdk): send config when frame reloads * feat(sdk): listen for config updates * feat(sdk): request config from sdk instead of sending it repeatedly * refactor(sdk): use type guard for config message * fix(sdk): use settings from SDK when there is no preexisting persisted data * fix(sdk): observe all iframe attributes * refactor(sdk): simplify bootup logic * feat(sdk): improve embed code display
159 lines
4.9 KiB
TypeScript
159 lines
4.9 KiB
TypeScript
import { PropsWithChildren, useContext } from 'react'
|
|
import { Link } from 'react-router-dom'
|
|
import { Theme } from '@mui/material/styles'
|
|
import Box from '@mui/material/Box'
|
|
import MuiDrawer from '@mui/material/Drawer'
|
|
import List from '@mui/material/List'
|
|
import MuiLink from '@mui/material/Link'
|
|
import Typography from '@mui/material/Typography'
|
|
import Divider from '@mui/material/Divider'
|
|
import IconButton from '@mui/material/IconButton'
|
|
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'
|
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight'
|
|
import ListItem from '@mui/material/ListItem'
|
|
import ListItemButton from '@mui/material/ListItemButton'
|
|
import ListItemIcon from '@mui/material/ListItemIcon'
|
|
import ListItemText from '@mui/material/ListItemText'
|
|
import Home from '@mui/icons-material/Home'
|
|
import SettingsApplications from '@mui/icons-material/SettingsRounded'
|
|
import QuestionMark from '@mui/icons-material/QuestionMark'
|
|
import Brightness4Icon from '@mui/icons-material/Brightness4'
|
|
import Brightness7Icon from '@mui/icons-material/Brightness7'
|
|
import ReportIcon from '@mui/icons-material/Report'
|
|
import GitInfo from 'react-git-info/macro'
|
|
|
|
import { routes } from 'config/routes'
|
|
import { SettingsContext } from 'contexts/SettingsContext'
|
|
import { ColorMode } from 'models/settings'
|
|
|
|
const { commit } = GitInfo()
|
|
|
|
export const drawerWidth = 240
|
|
|
|
export interface DrawerProps extends PropsWithChildren {
|
|
isDrawerOpen: boolean
|
|
onDrawerClose: () => void
|
|
theme: Theme
|
|
}
|
|
|
|
export const Drawer = ({ isDrawerOpen, onDrawerClose, theme }: DrawerProps) => {
|
|
const settingsContext = useContext(SettingsContext)
|
|
const colorMode = settingsContext.getUserSettings().colorMode
|
|
|
|
const handleColorModeToggleClick = () => {
|
|
const newMode =
|
|
colorMode === ColorMode.LIGHT ? ColorMode.DARK : ColorMode.LIGHT
|
|
settingsContext.updateUserSettings({ colorMode: newMode })
|
|
}
|
|
|
|
return (
|
|
<MuiDrawer
|
|
sx={{
|
|
width: drawerWidth,
|
|
flexShrink: 0,
|
|
'& .MuiDrawer-paper': {
|
|
width: drawerWidth,
|
|
boxSizing: 'border-box',
|
|
},
|
|
}}
|
|
variant="persistent"
|
|
anchor="left"
|
|
open={isDrawerOpen}
|
|
>
|
|
<Box
|
|
sx={theme => ({
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
padding: theme.spacing(0, 1),
|
|
// necessary for drawer content to be pushed below app bar
|
|
...theme.mixins.toolbar,
|
|
justifyContent: 'flex-end',
|
|
})}
|
|
>
|
|
<IconButton onClick={onDrawerClose} aria-label="Close menu">
|
|
{theme.direction === 'ltr' ? (
|
|
<ChevronLeftIcon />
|
|
) : (
|
|
<ChevronRightIcon />
|
|
)}
|
|
</IconButton>
|
|
</Box>
|
|
<Divider />
|
|
<List role="navigation">
|
|
<Link to={routes.ROOT}>
|
|
<ListItem disablePadding>
|
|
<ListItemButton>
|
|
<ListItemIcon>
|
|
<Home />
|
|
</ListItemIcon>
|
|
<ListItemText primary="Home" />
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Link>
|
|
<Link to={routes.SETTINGS}>
|
|
<ListItem disablePadding>
|
|
<ListItemButton>
|
|
<ListItemIcon>
|
|
<SettingsApplications />
|
|
</ListItemIcon>
|
|
<ListItemText primary="Settings" />
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Link>
|
|
<Link to={routes.ABOUT}>
|
|
<ListItem disablePadding>
|
|
<ListItemButton>
|
|
<ListItemIcon>
|
|
<QuestionMark />
|
|
</ListItemIcon>
|
|
<ListItemText primary="About" />
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Link>
|
|
<Link to={routes.DISCLAIMER}>
|
|
<ListItem disablePadding>
|
|
<ListItemButton>
|
|
<ListItemIcon>
|
|
<ReportIcon />
|
|
</ListItemIcon>
|
|
<ListItemText primary="Disclaimer" />
|
|
</ListItemButton>
|
|
</ListItem>
|
|
</Link>
|
|
<ListItem disablePadding>
|
|
<ListItemButton onClick={handleColorModeToggleClick}>
|
|
<ListItemIcon>
|
|
{theme.palette.mode === 'dark' ? (
|
|
<Brightness7Icon />
|
|
) : (
|
|
<Brightness4Icon />
|
|
)}
|
|
</ListItemIcon>
|
|
<ListItemText primary="Change theme" />
|
|
</ListItemButton>
|
|
</ListItem>
|
|
<Divider />
|
|
<ListItem>
|
|
<Typography variant="subtitle2">
|
|
Build signature:{' '}
|
|
<Typography
|
|
sx={{
|
|
fontFamily: 'monospace',
|
|
display: 'inline',
|
|
}}
|
|
>
|
|
<MuiLink
|
|
target="_blank"
|
|
rel="noopener"
|
|
href={`${process.env.REACT_APP_GITHUB_REPO}/commit/${commit.hash}`}
|
|
>
|
|
{commit.shortHash}
|
|
</MuiLink>
|
|
</Typography>
|
|
</Typography>
|
|
</ListItem>
|
|
</List>
|
|
</MuiDrawer>
|
|
)
|
|
}
|