import {useEffect, useState, useContext} from 'react' import Link from 'next/link' import PropTypes from 'prop-types' import {styled} from '@mui/material/styles' 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' import Typography from '@mui/material/Typography' import LinearProgress from '@mui/material/LinearProgress' import CircularProgress from '@mui/material/CircularProgress' import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace' import {jwennTeks} from '../../lib/oki-api' import ParolesListContext from '../../contexts/paroles-list' import MontreTeks from './montre-teks' import DenyeTeks from './denye-teks' import Teks from './teks' import VweKouteAchte from './vwe-koute-achte' import DrawerBar from './drawer-bar' const drawerWidth = 240 const PREFIX = 'drawer-bar' const classes = { vwe: `${PREFIX}-vwe`, koute: `${PREFIX}-koute` } const Stream = styled('div')(( { theme } ) => ({ [`& .${classes.koute}`]: { position: 'absolute', right: '40px', top: '8px', [theme.breakpoints.up('sm')]: { top: '10px' } }, [`& .${classes.vwe}`]: { position: 'absolute', right: '90px', top: '8px', [theme.breakpoints.up('sm')]: { top: '10px' } } })) export default function TeksDrawer({parole, paroleId, slug, denyeTeks}) { const [open, setOpen] = useState(false) const {paroles, setParoles} = useContext(ParolesListContext) const [mobileOpen, setMobileOpen] = useState(false) const [isLoading, setIsLoading] = useState(false) const [isParolesHidden, setIsParolesHidden] = useState(true) const [error, setError] = useState('') const [success, setSuccess] = useState('') const handleOpenDrawer = async () => { setMobileOpen(true) if (paroles.length === 0) { setIsLoading(true) try { const teks = await jwennTeks() setParoles(teks) } catch (error) { console.log('⚠️ error', error.message) } setIsLoading(false) } } const handleCloseDrawer = () => { setMobileOpen(false) } const handleClick = async () => { setIsLoading(true) try { const teks = await jwennTeks() setParoles(teks) } catch (error) { console.log('⚠️ error', error.message) } setIsLoading(false) setIsParolesHidden(false) } useEffect(() => { if (paroles.length > 0) { setIsParolesHidden(false) } }, [paroles.length]) useEffect(() => { if (error || success) { setOpen(true) } }, [error, success, setOpen]) const handleClose = (event, reason) => { if (reason === 'clickaway') { return } setOpen(false) setSuccess('') setError('') } return ( {parole ? ( {parole.streamVideo && parole.streamVideo.length > 0 && (
)} {parole.streamAudio && parole.streamAudio.length > 0 && (
)}
) : ( Dernières paroles )}
{isLoading ? ( ) : ( )} {isLoading || isParolesHidden ? ( <> {isLoading && ( )} ) : ( )} {parole ? ( ) : ( )}
) } TeksDrawer.defaultProps = { parole: null, paroleId: null, slug: null, denyeTeks: null } TeksDrawer.propTypes = { parole: PropTypes.object, paroleId: PropTypes.number, slug: PropTypes.string, denyeTeks: PropTypes.array }