Makes TeksDrawer permanent
This commit is contained in:
@@ -1,49 +1,20 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
import {useState} from 'react'
|
import {useState} from 'react'
|
||||||
import {styled} from '@mui/material/styles'
|
import Box from '@mui/material/Box'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import {union, deburr} from 'lodash'
|
import {union, deburr} from 'lodash'
|
||||||
import useMediaQuery from '@mui/material/useMediaQuery'
|
import useMediaQuery from '@mui/material/useMediaQuery'
|
||||||
|
|
||||||
import {
|
import Divider from '@mui/material/Divider'
|
||||||
Divider,
|
import FormControl from '@mui/material/FormControl'
|
||||||
FormControl,
|
import InputAdornment from '@mui/material/InputAdornment'
|
||||||
InputAdornment,
|
import InputBase from '@mui/material/InputBase'
|
||||||
InputBase
|
|
||||||
} from '@mui/material'
|
|
||||||
|
|
||||||
import SearchIcon from '@mui/icons-material/Search'
|
import SearchIcon from '@mui/icons-material/Search'
|
||||||
|
|
||||||
import MizikLis from '../awtis/mizik-lis'
|
import MizikLis from '../awtis/mizik-lis'
|
||||||
|
|
||||||
const PREFIX = 'drawer-bar'
|
|
||||||
|
|
||||||
const classes = {
|
|
||||||
toolbar: `${PREFIX}-toolbar`,
|
|
||||||
list: `${PREFIX}-list`,
|
|
||||||
form: `${PREFIX}-form`,
|
|
||||||
text: `${PREFIX}-text`
|
|
||||||
}
|
|
||||||
|
|
||||||
const Root = styled('div')((
|
|
||||||
{
|
|
||||||
theme
|
|
||||||
}
|
|
||||||
) => ({
|
|
||||||
[`& .${classes.toolbar}`]: theme.mixins.toolbar,
|
|
||||||
|
|
||||||
[`& .${classes.list}`]: {
|
|
||||||
marginBottom: '3em'
|
|
||||||
},
|
|
||||||
|
|
||||||
[`& .${classes.form}`]: {
|
|
||||||
marginLeft: theme.spacing(1)
|
|
||||||
},
|
|
||||||
|
|
||||||
[`& .${classes.text}`]: {
|
|
||||||
marginBottom: '0.5em'
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
const getMizikFiltered = (paroles, filter) => {
|
const getMizikFiltered = (paroles, filter) => {
|
||||||
if (paroles) {
|
if (paroles) {
|
||||||
const filteredTitre = paroles.filter(({attributes}) => {
|
const filteredTitre = paroles.filter(({attributes}) => {
|
||||||
@@ -60,10 +31,9 @@ const getMizikFiltered = (paroles, filter) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DrawerBar({meteEsMobilOuve, paroles, slug}) {
|
export default function DrawerBar({paroles}) {
|
||||||
const isMobile = useMediaQuery('(max-width:600px)')
|
const isMobile = useMediaQuery('(max-width:600px)')
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [slugTeksChwazi, meteSlugTeksChwazi] = useState(slug)
|
|
||||||
|
|
||||||
const mizikFiltered = getMizikFiltered(paroles, search)
|
const mizikFiltered = getMizikFiltered(paroles, search)
|
||||||
|
|
||||||
@@ -74,10 +44,10 @@ export default function DrawerBar({meteEsMobilOuve, paroles, slug}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Root className='search'>
|
<Box sx={{height: '100%'}}>
|
||||||
<FormControl style={{marginTop: `${isMobile ? '3em' : 0}`}} className={classes.form}>
|
<FormControl>
|
||||||
<InputBase
|
<InputBase
|
||||||
className={classes.toolbar}
|
sx={{paddingBlock: 2}}
|
||||||
placeholder='Recherche...'
|
placeholder='Recherche...'
|
||||||
startAdornment={
|
startAdornment={
|
||||||
<InputAdornment position='start'>
|
<InputAdornment position='start'>
|
||||||
@@ -89,26 +59,16 @@ export default function DrawerBar({meteEsMobilOuve, paroles, slug}) {
|
|||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Divider />
|
<Divider />
|
||||||
<div style={{marginBottom: `${isMobile ? 0 : '3em'}`}} className={classes.list}>
|
<Box style={{marginBottom: `${isMobile ? 0 : '3em'}`, height: `calc(100% - ${isMobile ? '65px' : '115px'})`}}>
|
||||||
<MizikLis
|
<MizikLis
|
||||||
niAwtis
|
niAwtis
|
||||||
meteEsMobilOuve={meteEsMobilOuve}
|
|
||||||
paroles={mizikFiltered}
|
paroles={mizikFiltered}
|
||||||
slugTeksChwazi={slugTeksChwazi}
|
|
||||||
meteSlugTeksChwazi={meteSlugTeksChwazi}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</Box>
|
||||||
</Root>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawerBar.propTypes = {
|
DrawerBar.propTypes = {
|
||||||
meteEsMobilOuve: PropTypes.func,
|
paroles: PropTypes.array.isRequired
|
||||||
paroles: PropTypes.array.isRequired,
|
|
||||||
slug: PropTypes.string
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawerBar.defaultProps = {
|
|
||||||
meteEsMobilOuve: null,
|
|
||||||
slug: null
|
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-156
@@ -1,8 +1,9 @@
|
|||||||
import {useEffect, useState, useContext} from 'react'
|
'use client'
|
||||||
|
|
||||||
|
import {useState, useEffect, forwardRef} from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import {useParams} from 'next/navigation'
|
import {useParams} from 'next/navigation'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import {styled} from '@mui/material/styles'
|
|
||||||
import AppBar from '@mui/material/AppBar'
|
import AppBar from '@mui/material/AppBar'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import CssBaseline from '@mui/material/CssBaseline'
|
import CssBaseline from '@mui/material/CssBaseline'
|
||||||
@@ -10,100 +11,28 @@ import Drawer from '@mui/material/Drawer'
|
|||||||
import IconButton from '@mui/material/IconButton'
|
import IconButton from '@mui/material/IconButton'
|
||||||
import MenuIcon from '@mui/icons-material/Menu'
|
import MenuIcon from '@mui/icons-material/Menu'
|
||||||
import Toolbar from '@mui/material/Toolbar'
|
import Toolbar from '@mui/material/Toolbar'
|
||||||
import Typography from '@mui/material/Typography'
|
import MuiAlert from '@mui/material/Alert'
|
||||||
import LinearProgress from '@mui/material/LinearProgress'
|
import Snackbar from '@mui/material/Snackbar'
|
||||||
import CircularProgress from '@mui/material/CircularProgress'
|
|
||||||
|
|
||||||
import KeyboardBackspaceIcon from '@mui/icons-material/KeyboardBackspace'
|
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 VweKouteAchte from './vwe-koute-achte'
|
||||||
|
|
||||||
import DrawerBar from './drawer-bar'
|
import DrawerBar from './drawer-bar'
|
||||||
|
import Pataje from './pataje'
|
||||||
|
|
||||||
const drawerWidth = 240
|
const drawerWidth = 240
|
||||||
|
|
||||||
const PREFIX = 'drawer-bar'
|
const Alert = forwardRef(function Alert(props, ref) {
|
||||||
|
return <MuiAlert ref={ref} elevation={6} variant='filled' {...props} />
|
||||||
|
})
|
||||||
|
|
||||||
const classes = {
|
export default function TeksDrawer({paroles}) {
|
||||||
vwe: `${PREFIX}-vwe`,
|
const {slug} = useParams()
|
||||||
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 [mobileOpen, setMobileOpen] = useState(false)
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [isParolesHidden, setIsParolesHidden] = useState(true)
|
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
const [success, setSuccess] = useState('')
|
const [success, setSuccess] = useState('')
|
||||||
|
|
||||||
const handleOpenDrawer = async () => {
|
const parole = paroles.find(({attributes}) => attributes.slug === slug)
|
||||||
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(() => {
|
useEffect(() => {
|
||||||
if (error || success) {
|
if (error || success) {
|
||||||
@@ -121,6 +50,14 @@ export default function TeksDrawer({parole, paroleId, slug, denyeTeks}) {
|
|||||||
setError('')
|
setError('')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleOpenDrawer = async () => {
|
||||||
|
setMobileOpen(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseDrawer = () => {
|
||||||
|
setMobileOpen(false)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: 'flex'}}>
|
<Box sx={{display: 'flex'}}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
@@ -135,37 +72,41 @@ export default function TeksDrawer({parole, paroleId, slug, denyeTeks}) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
|
<Box sx={{display: 'flex', alignContent: 'center'}}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color='inherit'
|
color='inherit'
|
||||||
aria-label='open drawer'
|
aria-label='open drawer'
|
||||||
edge='start'
|
edge='start'
|
||||||
sx={{mr: 2, display: {sm: 'none'}}}
|
sx={{display: {sm: 'none'}}}
|
||||||
onClick={handleOpenDrawer}
|
onClick={handleOpenDrawer}
|
||||||
>
|
>
|
||||||
<MenuIcon />
|
<MenuIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
{parole ? (
|
{parole && (
|
||||||
<Stream>
|
|
||||||
<Link passHref href='/paroles'>
|
<Link passHref href='/paroles'>
|
||||||
<IconButton aria-label='return' size='medium'>
|
<IconButton aria-label='return' size='medium'>
|
||||||
<KeyboardBackspaceIcon style={{fontSize: '1.5em'}} />
|
<KeyboardBackspaceIcon style={{fontSize: '1.5em'}} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Link>
|
</Link>
|
||||||
{parole.streamVideo && parole.streamVideo.length > 0 && (
|
|
||||||
<div className={classes.vwe}>
|
|
||||||
<VweKouteAchte niVideyo parole={parole} />
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
{parole.streamAudio && parole.streamAudio.length > 0 && (
|
</Box>
|
||||||
<div className={classes.koute}>
|
{parole && (
|
||||||
<VweKouteAchte niOdyo parole={parole} />
|
<Box sx={{display: 'flex', position: 'relative', top: '-20px'}}>
|
||||||
</div>
|
<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>
|
||||||
)}
|
)}
|
||||||
</Stream>
|
{parole.attributes.streamAudio && parole.attributes.streamAudio.length > 0 && (
|
||||||
) : (
|
<Box>
|
||||||
<Typography noWrap variant='h6'>
|
<VweKouteAchte niOdyo parole={parole.attributes} />
|
||||||
Dernières paroles
|
</Box>
|
||||||
</Typography>
|
)}
|
||||||
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
@@ -186,18 +127,7 @@ export default function TeksDrawer({parole, paroleId, slug, denyeTeks}) {
|
|||||||
}}
|
}}
|
||||||
onClose={handleCloseDrawer}
|
onClose={handleCloseDrawer}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} />
|
||||||
<Box sx={{
|
|
||||||
position: 'absolute',
|
|
||||||
right: 100,
|
|
||||||
top: 200,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CircularProgress />
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} slug={slug} />
|
|
||||||
)}
|
|
||||||
</Drawer>
|
</Drawer>
|
||||||
<Drawer
|
<Drawer
|
||||||
open
|
open
|
||||||
@@ -207,55 +137,27 @@ export default function TeksDrawer({parole, paroleId, slug, denyeTeks}) {
|
|||||||
'& .MuiDrawer-paper': {boxSizing: 'border-box', width: drawerWidth, marginTop: '3em', borderTop: '2px solid #303030'},
|
'& .MuiDrawer-paper': {boxSizing: 'border-box', width: drawerWidth, marginTop: '3em', borderTop: '2px solid #303030'},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isLoading || isParolesHidden ? (
|
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} />
|
||||||
<>
|
|
||||||
<MontreTeks handleClick={handleClick} />
|
|
||||||
{isLoading && (
|
|
||||||
<Box sx={{width: '100%'}}>
|
|
||||||
<LinearProgress />
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<DrawerBar meteEsMobilOuve={setMobileOpen} paroles={paroles} slug={slug} />
|
|
||||||
)}
|
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
{success && (
|
||||||
component='main'
|
<Snackbar open={open} autoHideDuration={3000} onClose={handleClose}>
|
||||||
sx={{flexGrow: 1, p: 2, width: {sm: `calc(100% - ${drawerWidth}px)`}}}
|
<Alert severity='success' onClose={handleClose}>
|
||||||
>
|
<strong>{success}</strong>
|
||||||
<Toolbar />
|
</Alert>
|
||||||
{parole ? (
|
</Snackbar>
|
||||||
<Teks
|
)}
|
||||||
parole={parole}
|
{error && (
|
||||||
paroleId={paroleId}
|
<Snackbar open={open} autoHideDuration={3000} onClose={handleClose}>
|
||||||
commentaires={parole?.commentaires.data}
|
<Alert severity='error' onClose={handleClose}>
|
||||||
open={open}
|
<strong>Une erreur s’est produite</strong> : <i>{error.message}</i>
|
||||||
success={success}
|
</Alert>
|
||||||
error={error}
|
</Snackbar>
|
||||||
setSuccess={setSuccess}
|
|
||||||
setError={setError}
|
|
||||||
handleClose={handleClose}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<DenyeTeks denyeTeks={denyeTeks} />
|
|
||||||
)}
|
)}
|
||||||
</Box>
|
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
TeksDrawer.defaultProps = {
|
|
||||||
parole: null,
|
|
||||||
paroleId: null,
|
|
||||||
slug: null,
|
|
||||||
denyeTeks: null
|
|
||||||
}
|
|
||||||
|
|
||||||
TeksDrawer.propTypes = {
|
TeksDrawer.propTypes = {
|
||||||
parole: PropTypes.object,
|
paroles: PropTypes.array,
|
||||||
paroleId: PropTypes.number,
|
|
||||||
slug: PropTypes.string,
|
|
||||||
denyeTeks: PropTypes.array
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user