Files

164 lines
4.8 KiB
JavaScript
Raw Permalink Normal View History

2023-07-22 13:53:31 +04:00
'use client'
import {useState, useEffect, forwardRef} from 'react'
import Link from 'next/link'
import {useParams} from 'next/navigation'
2022-05-22 22:18:43 +04:00
import PropTypes from 'prop-types'
import AppBar from '@mui/material/AppBar'
import Box from '@mui/material/Box'
import CssBaseline from '@mui/material/CssBaseline'
import Drawer from '@mui/material/Drawer'
import IconButton from '@mui/material/IconButton'
import MenuIcon from '@mui/icons-material/Menu'
import Toolbar from '@mui/material/Toolbar'
2023-07-22 13:53:31 +04:00
import MuiAlert from '@mui/material/Alert'
import Snackbar from '@mui/material/Snackbar'
2022-01-19 07:06:26 +04:00
import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace'
2022-05-22 22:18:43 +04:00
import VweKouteAchte from './vwe-koute-achte'
2023-07-22 13:53:31 +04:00
2022-05-23 03:19:46 +04:00
import DrawerBar from './drawer-bar'
2023-07-22 13:53:31 +04:00
import Pataje from './pataje'
2022-05-22 22:18:43 +04:00
const drawerWidth = 240
2021-06-02 02:24:19 +02:00
2023-07-22 13:53:31 +04:00
const Alert = forwardRef(function Alert(props, ref) {
return <MuiAlert ref={ref} elevation={6} variant='filled' {...props} />
})
2022-01-19 06:35:04 +04:00
2023-07-22 13:53:31 +04:00
export default function TeksDrawer({paroles}) {
const {slug} = useParams()
2022-05-22 22:18:43 +04:00
const [mobileOpen, setMobileOpen] = useState(false)
2023-07-22 13:53:31 +04:00
const [open, setOpen] = useState(false)
const [error, setError] = useState('')
2021-06-02 02:24:19 +02:00
const [success, setSuccess] = useState('')
2026-04-21 19:16:11 +04:00
const parole = paroles.find((parole) => parole.slug === slug)
2021-06-02 02:24:19 +02:00
useEffect(() => {
if (error || success) {
setOpen(true)
}
}, [error, success, setOpen])
2022-05-22 22:18:43 +04:00
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return
}
setOpen(false)
setSuccess('')
setError('')
}
2023-07-22 13:53:31 +04:00
const handleOpenDrawer = async () => {
setMobileOpen(true)
}
const handleCloseDrawer = () => {
setMobileOpen(false)
}
return (
2022-05-22 22:18:43 +04:00
<Box sx={{display: 'flex'}}>
<CssBaseline />
2022-05-22 22:18:43 +04:00
<AppBar
position='fixed'
sx={{
width: {sm: `calc(100% - ${drawerWidth}px)`},
ml: {sm: `${drawerWidth}px`},
borderTop: '2px solid #303030',
marginTop: '3rem',
zIndex: 1
}}
>
<Toolbar>
2023-07-22 13:53:31 +04:00
<Box sx={{display: 'flex', alignContent: 'center'}}>
<IconButton
color='inherit'
aria-label='open drawer'
edge='start'
sx={{display: {sm: 'none'}}}
onClick={handleOpenDrawer}
>
<MenuIcon />
</IconButton>
{parole && (
2022-03-13 01:38:45 +04:00
<Link passHref href='/paroles'>
2020-12-17 23:45:22 +01:00
<IconButton aria-label='return' size='medium'>
<KeyboardBackspaceIcon style={{fontSize: '1.5em'}} />
</IconButton>
</Link>
2023-07-22 13:53:31 +04:00
)}
</Box>
{parole && (
<Box sx={{display: 'flex', position: 'relative', top: '-20px'}}>
<Box>
2026-04-21 19:16:11 +04:00
<Pataje parole={parole} setError={setError} setSuccess={setSuccess} />
2023-07-22 13:53:31 +04:00
</Box>
2026-04-21 19:16:11 +04:00
{parole.streamVideo && parole.streamVideo.length > 0 && (
2023-07-22 13:53:31 +04:00
<Box>
2026-04-21 19:16:11 +04:00
<VweKouteAchte niVideyo parole={parole} />
2023-07-22 13:53:31 +04:00
</Box>
2020-12-15 08:50:14 +01:00
)}
2026-04-21 19:16:11 +04:00
{parole.streamAudio && parole.streamAudio.length > 0 && (
2023-07-22 13:53:31 +04:00
<Box>
2026-04-21 19:16:11 +04:00
<VweKouteAchte niOdyo parole={parole} />
2023-07-22 13:53:31 +04:00
</Box>
2020-12-15 08:50:14 +01:00
)}
2023-07-22 13:53:31 +04:00
</Box>
)}
</Toolbar>
</AppBar>
2022-05-22 22:18:43 +04:00
<Box
component='nav'
sx={{width: {sm: drawerWidth}, flexShrink: {sm: 0}, padding: 0}}
aria-label='mailbox folders'
>
<Drawer
variant='temporary'
open={mobileOpen}
ModalProps={{
keepMounted: true
}}
sx={{
display: {xs: 'block', sm: 'none'},
'& .MuiDrawer-paper': {boxSizing: 'border-box', width: drawerWidth}
}}
onClose={handleCloseDrawer}
>
2023-07-22 13:53:31 +04:00
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} />
2022-05-22 22:18:43 +04:00
</Drawer>
<Drawer
open
variant='permanent'
sx={{
display: {xs: 'none', sm: 'block'},
'& .MuiDrawer-paper': {boxSizing: 'border-box', width: drawerWidth, marginTop: '3em', borderTop: '2px solid #303030'},
}}
>
2023-07-22 13:53:31 +04:00
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} />
2022-05-22 22:18:43 +04:00
</Drawer>
</Box>
2023-07-22 13:53:31 +04:00
{success && (
<Snackbar open={open} autoHideDuration={3000} onClose={handleClose}>
<Alert severity='success' onClose={handleClose}>
<strong>{success}</strong>
</Alert>
</Snackbar>
)}
{error && (
<Snackbar open={open} autoHideDuration={3000} onClose={handleClose}>
<Alert severity='error' onClose={handleClose}>
<strong>Une erreur sest produite</strong> : <i>{error.message}</i>
</Alert>
</Snackbar>
)}
2022-05-22 22:18:43 +04:00
</Box>
)
}
2022-05-22 22:18:43 +04:00
TeksDrawer.propTypes = {
2023-07-22 13:53:31 +04:00
paroles: PropTypes.array,
2022-05-22 22:18:43 +04:00
}