'use client' import {useState, useRef, useEffect} from 'react' import PropTypes from 'prop-types' import Grid from '@mui/material/Grid2' import Typography from '@mui/material/Typography' import HomeIcon from '@mui/icons-material/Home' import Box from '@mui/material/Box' import AuthAlert from '../auth-form/auth-alert.js' import SessionExpired from '../session/session-expired.js' import {Loading} from '../loading.js' import ListVersions from './list-versions.js' import {listVersions} from '@/lib/directus.js' import Sign from '@/components/session/sign.js' const navButton = { title: 'Accueil', path: '/', color: 'success', icon: } export default function GetVersions({session}) { const {accessToken, userId} = session.user const [versions, setVersions] = useState(null) const [isErrorAlertOpen, setIsErrorAlertOpen] = useState(false) const [error, setError] = useState('') const countdownRef = useRef() useEffect(() => { async function fetchVersions() { const data = await listVersions({ accessToken, userId, countdownRef, setError, setIsErrorAlertOpen }) setVersions(data) } fetchVersions() }, [accessToken, userId]) if (!versions) { return ( <> {error && } ) } const titres = versions?.filter(({collection}) => collection === 'titres') const articles = versions?.filter(({collection}) => collection === 'articles') return ( <> {error && } Liste des versions 0 && articles.length === 0) || (articles.length > 0 && titres.length === 0) ? 'center' : 'flex-start' } > {titres.length > 0 && ( 0 ? 6 : 12}}> )} {articles.length > 0 && ( 0 ? 6 : 12}}> )} ) } GetVersions.propTypes = { session: PropTypes.object.isRequired }