Add Edit component to Titre & Article
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography'
|
||||||
|
import Edit from './edit.js'
|
||||||
|
|
||||||
export default function Article({numero, contenu}) {
|
export default function Article({session, articleId, numero, contenu}) {
|
||||||
const formattedContent = contenu.replaceAll('\n', '<br />')
|
const formattedContent = contenu.replaceAll('\n', '<br />')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box textAlign='justify' p={0.5}>
|
<Box textAlign='justify' p={0.5}>
|
||||||
{numero > 0 && (
|
<Box sx={{display: 'flex', alignItems: 'center'}}>
|
||||||
<Typography marginBlock={1} fontWeight='bold'>Article {numero}</Typography>
|
<Typography marginBlock={1} fontWeight='bold'>{numero === 0 ? 'Article 1' : `Article ${numero}`}</Typography>
|
||||||
)}
|
{session && (
|
||||||
|
<Edit session={session} article={articleId} />
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
<Typography dangerouslySetInnerHTML={{__html: formattedContent}} />
|
<Typography dangerouslySetInnerHTML={{__html: formattedContent}} />
|
||||||
</Box>
|
</Box>
|
||||||
@@ -17,6 +21,8 @@ export default function Article({numero, contenu}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Article.propTypes = {
|
Article.propTypes = {
|
||||||
|
session: PropTypes.object,
|
||||||
|
articleId: PropTypes.string.isRequired,
|
||||||
numero: PropTypes.number,
|
numero: PropTypes.number,
|
||||||
contenu: PropTypes.string.isRequired
|
contenu: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ import Titre from './titre.js'
|
|||||||
import Article from './article.js'
|
import Article from './article.js'
|
||||||
import {formatKonstitisyon} from '@/lib/format.js'
|
import {formatKonstitisyon} from '@/lib/format.js'
|
||||||
|
|
||||||
export default function Konstitisyon({titres, articles}) {
|
export default function Konstitisyon({session, titres, articles}) {
|
||||||
const konstitisyon = formatKonstitisyon(titres, articles)
|
const konstitisyon = formatKonstitisyon(titres, articles)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{konstitisyon.map(({titreId, titre, articles}) => (
|
{konstitisyon.map(({titreId, titre, articles}) => (
|
||||||
<Paper key={titreId} variant='outlined' sx={{p: 1, marginBlock: 2}} p={2} >
|
<Paper key={titreId} variant='outlined' sx={{p: 1, marginBlock: 2}} p={2} >
|
||||||
<Titre titre={titre} />
|
<Titre session={session} titreId={titreId} titre={titre} />
|
||||||
{articles.map(({id, numero, contenu}) => (
|
{articles.map(({id, numero, contenu}) => (
|
||||||
<Article key={id} numero={numero} contenu={contenu} />
|
<Article key={id} session={session} articleId={id} numero={numero} contenu={contenu} />
|
||||||
))}
|
))}
|
||||||
</Paper>
|
</Paper>
|
||||||
))}
|
))}
|
||||||
@@ -23,6 +23,7 @@ export default function Konstitisyon({titres, articles}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Konstitisyon.propTypes = {
|
Konstitisyon.propTypes = {
|
||||||
|
session: PropTypes.object,
|
||||||
titres: PropTypes.object.isRequired,
|
titres: PropTypes.object.isRequired,
|
||||||
articles: PropTypes.object.isRequired
|
articles: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import Typography from '@mui/material/Typography'
|
import Typography from '@mui/material/Typography'
|
||||||
|
import Edit from './edit.js'
|
||||||
|
|
||||||
export default function Titre({titre}) {
|
export default function Titre({session, titreId, titre}) {
|
||||||
return (
|
return (
|
||||||
<Box p={1} marginBlock={1}>
|
<Box p={1} marginBlock={1} sx={{display: 'flex', alignItems: 'center'}}>
|
||||||
<Typography sx={{textDecoration: 'underline'}} fontWeight='bold'>{titre}</Typography>
|
<Typography sx={{textDecoration: 'underline'}} fontWeight='bold'>{titre}</Typography>
|
||||||
|
{session && (
|
||||||
|
<Edit session={session} titre={titreId} />
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Titre.propTypes = {
|
Titre.propTypes = {
|
||||||
|
session: PropTypes.object,
|
||||||
|
titreId: PropTypes.string.isRequired,
|
||||||
titre: PropTypes.string.isRequired
|
titre: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user