Add components to write comments
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
'use client'
|
||||
|
||||
import PropTypes from 'prop-types'
|
||||
import {useState} from 'react'
|
||||
import Box from '@mui/material/Box'
|
||||
import Paper from '@mui/material/Paper'
|
||||
import {styled} from '@mui/material/styles'
|
||||
import IconButton from '@mui/material/IconButton'
|
||||
import AddCommentIcon from '@mui/icons-material/AddComment'
|
||||
import Tooltip, {tooltipClasses} from '@mui/material/Tooltip'
|
||||
import AuthAlert from '../auth-form/auth-alert.js'
|
||||
import Titre from './titre.js'
|
||||
import Article from './article.js'
|
||||
import HandleComments from './handle-comments.js'
|
||||
import {formatKonstitisyon} from '@/lib/format.js'
|
||||
|
||||
const LightTooltip = styled(({className, ...props}) => (
|
||||
@@ -24,27 +26,66 @@ const LightTooltip = styled(({className, ...props}) => (
|
||||
|
||||
export default function Konstitisyon({session, titres, articles}) {
|
||||
const konstitisyon = formatKonstitisyon(titres, articles)
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [isErrorAlertOpen, setIsErrorAlertOpen] = useState(false)
|
||||
const [isSuccessAlertOpen, setIsSuccessAlertOpen] = useState(false)
|
||||
const [selectedTitre, setSelectedTitre] = useState(null)
|
||||
const [error, setError] = useState('')
|
||||
const [success, setSuccess] = useState('')
|
||||
|
||||
const handleCommentsDialog = (titreId, titre) => {
|
||||
setSelectedTitre({id: titreId, titre})
|
||||
setIsOpen(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<Box>
|
||||
{konstitisyon.map(({titreId, titre, articles}) => (
|
||||
<Paper key={titreId} variant='outlined' sx={{p: 1, marginBlock: 2}} p={2} >
|
||||
<Titre session={session} titreId={titreId} titre={titre} />
|
||||
{articles.map(({id, numero, contenu}) => (
|
||||
<Article key={id} session={session} articleId={id} numero={numero} contenu={contenu} />
|
||||
))}
|
||||
{session && (
|
||||
<Box sx={{textAlign: 'right'}}>
|
||||
<IconButton size='large' aria-label='commenter'>
|
||||
<LightTooltip title='Commenter'>
|
||||
<AddCommentIcon color='warning' fontSize='inherit' />
|
||||
</LightTooltip>
|
||||
</IconButton>
|
||||
</Box>
|
||||
)}
|
||||
</Paper>
|
||||
))}
|
||||
</Box>
|
||||
<>
|
||||
{error && <AuthAlert
|
||||
isOpen={isErrorAlertOpen}
|
||||
setIsOpen={setIsErrorAlertOpen}
|
||||
message={error}
|
||||
severity='error'
|
||||
/>}
|
||||
|
||||
{success && <AuthAlert
|
||||
isOpen={isSuccessAlertOpen}
|
||||
setIsOpen={setIsSuccessAlertOpen}
|
||||
message={success}
|
||||
severity='success'
|
||||
/>}
|
||||
|
||||
<Box>
|
||||
{konstitisyon.map(({titreId, titre, articles}) => (
|
||||
<Paper key={titreId} variant='outlined' sx={{p: 1, marginBlock: 2}} p={2} >
|
||||
<Titre session={session} titreId={titreId} titre={titre} />
|
||||
{articles.map(({id, numero, contenu}) => (
|
||||
<Article key={id} session={session} articleId={id} numero={numero} contenu={contenu} />
|
||||
))}
|
||||
{session && (
|
||||
<Box sx={{textAlign: 'right'}}>
|
||||
<IconButton size='large' aria-label='commenter' onClick={() => handleCommentsDialog(titreId, titre)}>
|
||||
<LightTooltip title='Commenter'>
|
||||
<AddCommentIcon color='warning' fontSize='inherit' />
|
||||
</LightTooltip>
|
||||
</IconButton>
|
||||
</Box>
|
||||
)}
|
||||
</Paper>
|
||||
))}
|
||||
{selectedTitre && (
|
||||
<HandleComments
|
||||
session={session}
|
||||
selectedTitre={selectedTitre}
|
||||
isOpen={isOpen}
|
||||
setIsOpen={setIsOpen}
|
||||
setError={setError}
|
||||
setSuccess={setSuccess}
|
||||
setIsErrorAlertOpen={setIsErrorAlertOpen}
|
||||
setIsSuccessAlertOpen={setIsSuccessAlertOpen}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user