fix: ajout d'un cercle circulaire lors du chargement des commentaires

This commit is contained in:
2026-01-24 12:23:04 +04:00
parent 315c71baa4
commit 8ec761b2c8
3 changed files with 60 additions and 40 deletions
+2 -2
View File
@@ -116,6 +116,6 @@ export default function Konstitisyon({session, titres, articles}) {
Konstitisyon.propTypes = { Konstitisyon.propTypes = {
session: PropTypes.object, session: PropTypes.object,
titres: PropTypes.object.isRequired, titres: PropTypes.array.isRequired,
articles: PropTypes.object.isRequired articles: PropTypes.array.isRequired
} }
+56 -35
View File
@@ -10,6 +10,7 @@ import Typography from '@mui/material/Typography'
import Pagination from '@mui/material/Pagination' import Pagination from '@mui/material/Pagination'
import Divider from '@mui/material/Divider' import Divider from '@mui/material/Divider'
import Box from '@mui/material/Box' import Box from '@mui/material/Box'
import CircularProgress from '@mui/material/CircularProgress'
import {readItems, withToken} from '@directus/sdk' import {readItems, withToken} from '@directus/sdk'
import SessionExpired from '../session/session-expired.js' import SessionExpired from '../session/session-expired.js'
import {directusClient, handleUserStatus} from '@/lib/directus.js' import {directusClient, handleUserStatus} from '@/lib/directus.js'
@@ -20,6 +21,7 @@ const commentsPerPage = process.env.NEXT_PUBLIC_COMMENTS_PER_PAGE || 2
export default function ListComments({session, selectedTitre, isOpen, setIsOpen, setError, setIsErrorAlertOpen}) { export default function ListComments({session, selectedTitre, isOpen, setIsOpen, setError, setIsErrorAlertOpen}) {
const countdownRef = useRef() const countdownRef = useRef()
const [comments, setComments] = useState([]) const [comments, setComments] = useState([])
const [isLoading, setIsLoading] = useState(false)
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const pageCount = Math.ceil(comments.length / commentsPerPage) const pageCount = Math.ceil(comments.length / commentsPerPage)
@@ -27,8 +29,15 @@ export default function ListComments({session, selectedTitre, isOpen, setIsOpen,
const startIndex = (page - 1) * commentsPerPage const startIndex = (page - 1) * commentsPerPage
const selectedComments = comments.slice(startIndex, startIndex + commentsPerPage) const selectedComments = comments.slice(startIndex, startIndex + commentsPerPage)
useEffect(() => {
setComments([])
setPage(1)
}, [selectedTitre?.id])
useEffect(() => { useEffect(() => {
async function fetchComments() { async function fetchComments() {
setIsLoading(true)
try { try {
await handleUserStatus(session.user.accessToken, session.user.userId) await handleUserStatus(session.user.accessToken, session.user.userId)
@@ -54,6 +63,8 @@ export default function ListComments({session, selectedTitre, isOpen, setIsOpen,
setError(error?.errors[0]?.message) setError(error?.errors[0]?.message)
setIsErrorAlertOpen(true) setIsErrorAlertOpen(true)
} }
} finally {
setIsLoading(false)
} }
} }
@@ -74,42 +85,52 @@ export default function ListComments({session, selectedTitre, isOpen, setIsOpen,
<> <>
<Dialog open={isOpen} onClose={handleClose}> <Dialog open={isOpen} onClose={handleClose}>
<DialogTitle>Commentaires</DialogTitle> <DialogTitle>Commentaires</DialogTitle>
<List sx={{width: '100%', maxWidth: 360, bgcolor: 'background.paper'}}> {isLoading ? (
{selectedComments && selectedComments.length > 0 ? selectedComments.map(({id, date_created, contenu, user_created}) => ( <Box sx={{display: 'flex', justifyContent: 'center', p: 4}}>
<React.Fragment key={id}> <CircularProgress />
<ListItem alignItems='flex-start'> </Box>
<ListItemText ) : (
primary={ <>
<Typography sx={{textDecoration: 'underline'}} component='span' variant='body2'> <List sx={{width: '100%', maxWidth: 360, bgcolor: 'background.paper'}}>
@{user_created.split('-')[0]} {selectedComments && selectedComments.length > 0 ? selectedComments.map(({id, date_created, contenu, user_created}) => (
</Typography> <React.Fragment key={id}>
} <ListItem alignItems='flex-start'>
secondary={ <ListItemText
<> primary={
<Typography <Typography sx={{textDecoration: 'underline'}} component='span' variant='body2'>
sx={{display: 'inline'}} @{user_created.split('-')[0]}
component='span' </Typography>
variant='body2' }
color='text.primary' secondary={
> <>
{contenu} <Typography
</Typography> sx={{display: 'inline'}}
<br /> component='span'
{formatDate(date_created, 'PPPPpp')} variant='body2'
</> color='text.primary'
} >
/> {contenu}
</ListItem> </Typography>
<br />
{formatDate(date_created, 'PPPPpp')}
</>
}
/>
</ListItem>
<Divider component='li' /> <Divider component='li' />
</React.Fragment> </React.Fragment>
)) : ( )) : (
<Typography textAlign='center'>Aucun commentaire</Typography> <Typography textAlign='center' sx={{p: 2}}>Aucun commentaire</Typography>
)} )}
</List> </List>
<Box sx={{display: 'flex', justifyContent: 'center'}}> {pageCount > 1 && (
<Pagination size='small' sx={{marginBlock: 3}} color='success' count={pageCount} page={page} onChange={handleChange} /> <Box sx={{display: 'flex', justifyContent: 'center'}}>
</Box> <Pagination size='small' sx={{marginBlock: 3}} color='success' count={pageCount} page={page} onChange={handleChange} />
</Box>
)}
</>
)}
</Dialog> </Dialog>
<SessionExpired ref={countdownRef} setError={setError} setIsErrorAlertOpen={setIsErrorAlertOpen} /> <SessionExpired ref={countdownRef} setError={setError} setIsErrorAlertOpen={setIsErrorAlertOpen} />
</> </>
+1 -2
View File
@@ -141,9 +141,8 @@ export async function listVersions({
return versions return versions
} catch (error) { } catch (error) {
console.log('error', error)
if (error?.errors[0]?.message === 'Token expired.') { if (error) {
countdownRef.current.startCountdown() countdownRef.current.startCountdown()
} else { } else {
console.log(error?.errors[0]?.message) console.log(error?.errors[0]?.message)