2023-07-22 13:53:31 +04:00
|
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
|
|
import {useState, useEffect, forwardRef} from 'react'
|
2020-12-13 23:20:07 +01:00
|
|
|
|
import Link from 'next/link'
|
2023-07-22 13:36:33 +04:00
|
|
|
|
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)
|
2022-05-14 01:37:55 +04:00
|
|
|
|
const [error, setError] = useState('')
|
2021-06-02 02:24:19 +02:00
|
|
|
|
const [success, setSuccess] = useState('')
|
|
|
|
|
|
|
2023-07-22 13:53:31 +04:00
|
|
|
|
const parole = paroles.find(({attributes}) => attributes.slug === slug)
|
2020-12-13 23:20:07 +01:00
|
|
|
|
|
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)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-13 23:20:07 +01:00
|
|
|
|
return (
|
2022-05-22 22:18:43 +04:00
|
|
|
|
<Box sx={{display: 'flex'}}>
|
2020-12-13 23:20:07 +01:00
|
|
|
|
<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
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2020-12-13 23:20:07 +01:00
|
|
|
|
<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'}} />
|
2020-12-13 23:20:07 +01:00
|
|
|
|
</IconButton>
|
|
|
|
|
|
</Link>
|
2023-07-22 13:53:31 +04:00
|
|
|
|
)}
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
{parole && (
|
|
|
|
|
|
<Box sx={{display: 'flex', position: 'relative', top: '-20px'}}>
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<Pataje parole={parole.attributes} setError={setError} setSuccess={setSuccess} />
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
|
|
{parole.attributes.streamVideo && parole.attributes.streamVideo.length > 0 && (
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<VweKouteAchte niVideyo parole={parole.attributes} />
|
|
|
|
|
|
</Box>
|
2020-12-15 08:50:14 +01:00
|
|
|
|
)}
|
2023-07-22 13:53:31 +04:00
|
|
|
|
{parole.attributes.streamAudio && parole.attributes.streamAudio.length > 0 && (
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<VweKouteAchte niOdyo parole={parole.attributes} />
|
|
|
|
|
|
</Box>
|
2020-12-15 08:50:14 +01:00
|
|
|
|
)}
|
2023-07-22 13:53:31 +04:00
|
|
|
|
</Box>
|
2020-12-13 23:20:07 +01:00
|
|
|
|
)}
|
|
|
|
|
|
</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 s’est produite</strong> : <i>{error.message}</i>
|
|
|
|
|
|
</Alert>
|
|
|
|
|
|
</Snackbar>
|
|
|
|
|
|
)}
|
2022-05-22 22:18:43 +04:00
|
|
|
|
</Box>
|
2020-12-13 23:20:07 +01:00
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|