import React, { useEffect, useState } from 'react'
import {
AppBar,
Button,
createMuiTheme, createStyles,
IconButton,
List,
ListItem,
ListItemText, makeStyles,
MuiThemeProvider,
SwipeableDrawer,
Toolbar,
Tooltip,
useMediaQuery,
} from '@material-ui/core'
import { Link } from 'gatsby'
import { Spacer } from './components/spacer'
import { Helmet } from 'react-helmet'
import NightsStayIcon from '@material-ui/icons/NightsStay'
import Brightness7Icon from '@material-ui/icons/Brightness7'
import MenuIcon from '@material-ui/icons/Menu'
import './global.scss'
import { GlobalSearchField } from './components/global-search-field'
import blue from '@material-ui/core/colors/blue'
import { isTouchDevice } from './utils'
const pages = [
{
path: '/',
name: 'About',
regex: /^(?:\/tl|\/)\/?$/
},
{
path: '/types',
name: 'Types',
regex: /^(?:\/tl)?(?:\/mtproto)?\/(class|union|types)(\/|$)/,
},
{
path: '/methods',
name: 'Methods',
regex: /^(?:\/tl)?(?:\/mtproto)?\/methods?(\/|$)/,
},
// {
// path: '/history',
// name: 'History',
// regex: /^\/history(\/|$)/,
// },
]
const drawerWidth = 240
const useStyles = makeStyles((t) => createStyles({
drawer: {
width: drawerWidth,
flexShrink: 0,
},
drawerPaper: {
width: drawerWidth,
},
drawerItem: {
padding: t.spacing(2, 4),
fontSize: 18
}
}))
function MobileNavigation({ path }: { path: string }) {
const [drawer, setDrawer] = useState(false)
const classes = useStyles()
return (
<>
setDrawer(true)}
edge="start"
>
setDrawer(false)}
onOpen={() => setDrawer(true)}
open={drawer}
className={classes.drawer}
classes={{
paper: classes.drawerPaper,
}}
>
{pages.map((page) => (
))}
>
)
}
function DesktopNavigation({ path }: { path: string }) {
return (
<>
{pages.map((page) => (
))}
>
)
}
export default function ({
children,
location,
}: {
children: NonNullable
location: any
}): React.ReactElement {
const [theme, setTheme] = useState<'light' | 'dark'>('light')
const path: string = location.pathname
useEffect(() => {
if (isTouchDevice()) document.documentElement.classList.add('touch')
}, [])
const muiTheme = createMuiTheme({
palette: {
type: theme,
primary:
theme === 'dark'
? {
main: blue[300],
}
: undefined,
secondary: {
main: blue[800],
},
},
})
const isDesktop = useMediaQuery(muiTheme.breakpoints.up('sm'))
return (
<>
<>
{isDesktop ? (
) : (
)}
setTheme(
theme === 'dark' ? 'light' : 'dark'
)
}
>
{theme === 'light' ? (
) : (
)}
{children}
>
>
)
}