Files
pawol.nu/components/teks/teks-drawer.js
T

225 lines
5.8 KiB
JavaScript
Raw Normal View History

import {useState} from 'react'
import PropTypes from 'prop-types'
import Link from 'next/link'
import {
Grid,
Toolbar,
Typography,
AppBar,
CssBaseline,
Drawer,
Hidden,
IconButton
} from '@material-ui/core'
import KeyboardBackspaceIcon from '@material-ui/icons/KeyboardBackspace'
import MenuIcon from '@material-ui/icons/Menu'
import {makeStyles, useTheme} from '@material-ui/core/styles'
import DrawerBar from './drawer-bar'
import DenyeTeks from './denye-teks'
2020-12-15 08:50:14 +01:00
import VweKouteAchte from './vwe-koute-achte'
const drawerWidth = 240
const useStyles = makeStyles(theme => ({
root: {
display: 'flex'
},
drawer: {
marginTop: '10em',
[theme.breakpoints.up('sm')]: {
width: drawerWidth,
flexShrink: 0
}
},
appBar: {
borderTop: '2px solid #303030',
marginTop: '4.71rem',
[theme.breakpoints.up('sm')]: {
width: `calc(100% - ${drawerWidth}px)`,
marginLeft: drawerWidth
}
},
menuButton: {
[theme.breakpoints.up('sm')]: {
display: 'none'
}
},
toolbar: theme.mixins.toolbar,
drawerPaper: {
borderTop: '2px solid #303030',
marginTop: '4.71rem',
width: drawerWidth
},
content: {
flexGrow: 1,
padding: theme.spacing(3)
},
list: {
marginBottom: '6em'
},
form: {
marginLeft: theme.spacing(1)
},
text: {
marginBottom: '0.5em'
},
gridText: {
border: '1px dashed grey',
borderRadius: '5px',
marginTop: '2em',
marginInline: '2px'
},
grid: {
marginTop: '1em'
2020-12-15 08:50:14 +01:00
},
koute: {
position: 'absolute',
2020-12-17 23:44:01 +01:00
right: '1px',
2020-12-15 08:50:14 +01:00
top: '8px',
[theme.breakpoints.up('sm')]: {
top: '10px'
}
},
vwe: {
position: 'absolute',
2020-12-17 23:44:01 +01:00
right: '60px',
2020-12-15 08:50:14 +01:00
top: '8px',
[theme.breakpoints.up('sm')]: {
top: '10px'
}
}
}))
const formatJsonString = stringToFormat => {
return stringToFormat.split('\n').map((string, index) => <div key={index}>{`${string}`}<br /></div>) // eslint-disable-line react/no-array-index-key
}
2020-12-18 22:08:34 +01:00
export default function TeksDrawer({teks, anTeks}) {
const classes = useStyles()
const theme = useTheme()
2020-12-18 22:21:53 +01:00
const [esMobilOuve, meteEsMobilOuve] = useState(false)
const handleDrawerToggle = () => {
2020-12-18 22:21:53 +01:00
meteEsMobilOuve(!esMobilOuve)
}
const container = typeof window === 'undefined' ? undefined : () => window.document.body
return (
<div className={classes.root}>
<CssBaseline />
<AppBar position='fixed' className={classes.appBar}>
<Toolbar>
<IconButton
color='inherit'
aria-label='open drawer'
edge='start'
className={classes.menuButton}
onClick={handleDrawerToggle}
>
<MenuIcon />
</IconButton>
2020-12-18 22:08:34 +01:00
{anTeks ? (
<>
<Link href='/teks'>
2020-12-17 23:45:22 +01:00
<IconButton aria-label='return' size='medium'>
<KeyboardBackspaceIcon style={{fontSize: '1.5em'}} />
</IconButton>
</Link>
2020-12-18 22:08:34 +01:00
{anTeks.lyen && anTeks.lyen.length > 0 && (
2020-12-15 08:50:14 +01:00
<div className={classes.vwe}>
2020-12-18 22:08:34 +01:00
<VweKouteAchte niVideyo anTeks={anTeks} />
2020-12-15 08:50:14 +01:00
</div>
)}
2020-12-18 22:08:34 +01:00
{anTeks.kouteyAchtey && anTeks.kouteyAchtey.length > 0 && (
2020-12-15 08:50:14 +01:00
<div className={classes.koute}>
2020-12-18 22:08:34 +01:00
<VweKouteAchte niOdyo anTeks={anTeks} />
2020-12-15 08:50:14 +01:00
</div>
)}
</>
) : (
<Typography noWrap variant='h6'>
Dènyé Tèks
</Typography>
)}
</Toolbar>
</AppBar>
<nav className={classes.drawer} aria-label='mailbox folders'>
<Hidden smUp implementation='css'>
<Drawer
container={container}
variant='temporary'
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
2020-12-18 22:21:53 +01:00
open={esMobilOuve}
classes={{
paper: classes.drawerPaper
}}
ModalProps={{
keepMounted: true
}}
onClose={handleDrawerToggle}
>
2020-12-18 22:21:53 +01:00
<DrawerBar meteEsMobilOuve={meteEsMobilOuve} teks={teks} anTeks={anTeks} />
</Drawer>
</Hidden>
<Hidden xsDown implementation='css'>
<Drawer
open
classes={{
paper: classes.drawerPaper
}}
variant='permanent'
>
2020-12-18 22:08:34 +01:00
<DrawerBar teks={teks} anTeks={anTeks} />
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
2020-12-18 22:08:34 +01:00
{anTeks ? (
2020-12-17 23:47:15 +01:00
<>
2020-12-21 09:21:02 +01:00
<Typography noWrap align='center' style={{marginTop: '0.5em'}} variant='h3'>
2020-12-18 22:08:34 +01:00
{anTeks.tit}
2020-12-17 23:47:15 +01:00
</Typography>
<Grid container className={classes.grid} spacing={3}>
<Grid item md className={classes.gridText}>
<Typography align='center' className={classes.text} variant='h4'>
2020-12-17 23:47:15 +01:00
Transcription
</Typography>
<Typography paragraph align='justify' component='span'>
2020-12-18 22:08:34 +01:00
{formatJsonString(anTeks.transkripsyon)}
</Typography>
</Grid>
2020-12-18 22:08:34 +01:00
{anTeks.tradiksyon && (
2020-12-17 23:47:15 +01:00
<Grid item md className={classes.gridText}>
<Typography align='center' className={classes.text} variant='h4'>
Traduction
</Typography>
<Typography paragraph align='justify' component='span'>
2020-12-18 22:08:34 +01:00
{formatJsonString(anTeks.tradiksyon.francais)}
2020-12-17 23:47:15 +01:00
</Typography>
</Grid>
)}
</Grid>
</>
) : (
2020-12-18 22:08:34 +01:00
<DenyeTeks {...teks} />
)}
</main>
</div>
)
}
TeksDrawer.propTypes = {
2020-12-18 22:08:34 +01:00
teks: PropTypes.array.isRequired,
anTeks: PropTypes.object
}
TeksDrawer.defaultProps = {
2020-12-18 22:08:34 +01:00
anTeks: null
}