2021-06-26 12:27:48 +02:00
|
|
|
import {useState, useEffect, useRef} from 'react'
|
2022-01-19 06:35:04 +04:00
|
|
|
import {styled} from '@mui/material/styles'
|
2021-06-26 12:27:48 +02:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
import {useSession} from 'next-auth/client'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
IconButton,
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogActions,
|
|
|
|
|
Button,
|
|
|
|
|
Typography,
|
|
|
|
|
Tooltip,
|
2022-01-19 06:35:04 +04:00
|
|
|
Zoom
|
2021-06-26 12:27:48 +02:00
|
|
|
} from '@material-ui/core'
|
|
|
|
|
import AddCommentIcon from '@material-ui/icons/AddComment'
|
|
|
|
|
import {useRouter} from 'next/router'
|
2022-01-18 09:08:26 +04:00
|
|
|
import Koneksyon from '../sesyon/koneksyon'
|
|
|
|
|
import KomanteList from './komante-list'
|
2021-06-26 12:27:48 +02:00
|
|
|
import EkriKomante from './ekri-komante'
|
|
|
|
|
|
2022-01-19 06:35:04 +04:00
|
|
|
const PREFIX = 'vwe-komante'
|
|
|
|
|
|
|
|
|
|
const classes = {
|
|
|
|
|
tooltip: `${PREFIX}-tooltip`,
|
|
|
|
|
margin: `${PREFIX}-margin`,
|
|
|
|
|
extendedIcon: `${PREFIX}-extendedIcon`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Root = styled('div')((
|
|
|
|
|
{
|
|
|
|
|
theme
|
|
|
|
|
}
|
|
|
|
|
) => ({
|
|
|
|
|
[`& .${classes.margin}`]: {
|
2021-06-26 12:27:48 +02:00
|
|
|
margin: theme.spacing(1)
|
|
|
|
|
},
|
2022-01-19 06:35:04 +04:00
|
|
|
|
|
|
|
|
[`& .${classes.extendedIcon}`]: {
|
2021-06-26 12:27:48 +02:00
|
|
|
marginRight: theme.spacing(1)
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
2022-01-19 06:35:04 +04:00
|
|
|
const KomanteTooltip = Tooltip
|
2021-06-26 12:27:48 +02:00
|
|
|
|
|
|
|
|
export default function VweKomante({komante, teks}) {
|
|
|
|
|
const [esOuve, meteEsOuve] = useState(false)
|
|
|
|
|
const [esKoneksyonOuve, meteEsKoneksyonOuve] = useState(false)
|
|
|
|
|
const [esKomenteOuve, meteEsKomanteOuve] = useState(false)
|
|
|
|
|
const [session] = useSession()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
|
meteEsOuve(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleClose = () => {
|
|
|
|
|
meteEsOuve(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const descriptionElementRef = useRef(null)
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (esOuve) {
|
|
|
|
|
const {current: descriptionElement} = descriptionElementRef
|
|
|
|
|
if (descriptionElement !== null) {
|
|
|
|
|
descriptionElement.focus()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [esOuve])
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-19 06:35:04 +04:00
|
|
|
(
|
|
|
|
|
<Root>
|
|
|
|
|
<KomanteTooltip
|
|
|
|
|
title='Komantè'
|
|
|
|
|
placement='bottom'
|
|
|
|
|
TransitionComponent={Zoom}
|
|
|
|
|
classes={{
|
|
|
|
|
tooltip: classes.tooltip
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<IconButton className={classes.margin} color='primary' aria-label='commentaire' component='span' onClick={handleClick}>
|
|
|
|
|
<AddCommentIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</KomanteTooltip>
|
|
|
|
|
<Dialog
|
|
|
|
|
open={esOuve}
|
|
|
|
|
scroll='paper'
|
|
|
|
|
aria-labelledby='scroll-dialog-title'
|
|
|
|
|
aria-describedby='scroll-dialog-description'
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
>
|
|
|
|
|
<DialogTitle align='center' id='scroll-dialog-title'>Kòmantè</DialogTitle>
|
|
|
|
|
<DialogContent dividers>
|
|
|
|
|
<Typography
|
|
|
|
|
ref={descriptionElementRef}
|
|
|
|
|
variant='inherit'
|
|
|
|
|
id='scroll-dialog-description'
|
|
|
|
|
tabIndex={-1}
|
|
|
|
|
>
|
|
|
|
|
{komante.length > 0 ? (
|
|
|
|
|
<KomanteList komante={komante} />
|
|
|
|
|
) : (
|
|
|
|
|
<Typography align='center'>
|
|
|
|
|
Aucun
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Typography>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions align='center' >
|
|
|
|
|
{session && session.user && !esKomenteOuve && (
|
|
|
|
|
<Button fullWidth color='primary' onClick={() => meteEsKomanteOuve(true)}>
|
|
|
|
|
Ajouter un commentaire
|
|
|
|
|
</Button>
|
2021-06-26 12:27:48 +02:00
|
|
|
)}
|
2022-01-19 06:35:04 +04:00
|
|
|
{!session && !esKoneksyonOuve && (
|
|
|
|
|
<Button fullWidth color='primary' onClick={() => meteEsKoneksyonOuve(true)}>
|
|
|
|
|
Se connecter pour commenter
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{!session && esKoneksyonOuve && (
|
|
|
|
|
<Koneksyon chimen={router.asPath} />
|
|
|
|
|
)}
|
|
|
|
|
</DialogActions>
|
|
|
|
|
{!session && esKoneksyonOuve && (
|
|
|
|
|
<Button style={{marginBottom: 10}} color='primary' onClick={() => meteEsKoneksyonOuve(false)}>
|
|
|
|
|
Annuler
|
2021-06-26 12:27:48 +02:00
|
|
|
</Button>
|
|
|
|
|
)}
|
2022-01-19 06:35:04 +04:00
|
|
|
{session && session.user && esKomenteOuve && (
|
|
|
|
|
<>
|
|
|
|
|
<EkriKomante session={session} teks={teks} meteEsKomanteOuve={meteEsKomanteOuve} />
|
|
|
|
|
<Button fullWidth style={{marginBottom: 10}} color='primary' onClick={() => meteEsKomanteOuve(false)}>
|
|
|
|
|
Fermer
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
2021-06-26 12:27:48 +02:00
|
|
|
)}
|
2022-01-19 06:35:04 +04:00
|
|
|
</Dialog>
|
|
|
|
|
</Root>
|
|
|
|
|
)
|
2021-06-26 12:27:48 +02:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VweKomante.defaultProps = {
|
|
|
|
|
komante: null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VweKomante.propTypes = {
|
|
|
|
|
komante: PropTypes.array,
|
|
|
|
|
teks: PropTypes.object.isRequired
|
|
|
|
|
}
|