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

226 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
}
export default function TeksDrawer({miziks, mizik}) {
const teks = mizik ? mizik[0] : null
const classes = useStyles()
const theme = useTheme()
const [mobileOpen, setMobileOpen] = useState(false)
const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen)
}
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>
{teks ? (
<>
<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-15 08:50:14 +01:00
{teks.liens && teks.liens.length > 0 && (
<div className={classes.vwe}>
<VweKouteAchte isVideo teks={teks} />
</div>
)}
{teks.kouteyAchtey && teks.kouteyAchtey.length > 0 && (
<div className={classes.koute}>
<VweKouteAchte isAudio teks={teks} />
</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'}
open={mobileOpen}
classes={{
paper: classes.drawerPaper
}}
ModalProps={{
keepMounted: true
}}
onClose={handleDrawerToggle}
>
<DrawerBar setMobileOpen={setMobileOpen} miziks={miziks} mizik={mizik} />
</Drawer>
</Hidden>
<Hidden xsDown implementation='css'>
<Drawer
open
classes={{
paper: classes.drawerPaper
}}
variant='permanent'
>
<DrawerBar miziks={miziks} mizik={mizik} />
</Drawer>
</Hidden>
</nav>
<main className={classes.content}>
{teks ? (
2020-12-17 23:47:15 +01:00
<>
<Typography noWrap align='center' style={{marginTop: '1em'}} variant='h6'>
{teks.titre}
</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-17 23:47:15 +01:00
{formatJsonString(teks.transcription)}
</Typography>
</Grid>
2020-12-17 23:47:15 +01:00
{teks.traductions && (
<Grid item md className={classes.gridText}>
<Typography align='center' className={classes.text} variant='h4'>
Traduction
</Typography>
<Typography paragraph align='justify' component='span'>
{formatJsonString(teks.traductions.francais)}
</Typography>
</Grid>
)}
</Grid>
</>
) : (
2020-12-17 09:06:34 +01:00
<DenyeTeks {...miziks} />
)}
</main>
</div>
)
}
TeksDrawer.propTypes = {
miziks: PropTypes.array.isRequired,
mizik: PropTypes.array
}
TeksDrawer.defaultProps = {
mizik: null
}