From 47d58680b363644ef05eb225ca1f141fb36c64cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sun, 4 Jan 2026 11:00:48 +0400 Subject: [PATCH] =?UTF-8?q?build:=20upgrade=20Mui=20&=20d'autres=20lib=20l?= =?UTF-8?q?i=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/versions/get-versions.js | 2 +- components/versions/version-comparison.js | 2 +- components/versions/version-timeline.js | 69 +++++- package.json | 16 +- yarn.lock | 284 ++++++++-------------- 5 files changed, 166 insertions(+), 207 deletions(-) diff --git a/components/versions/get-versions.js b/components/versions/get-versions.js index b3436c2..163eadb 100644 --- a/components/versions/get-versions.js +++ b/components/versions/get-versions.js @@ -2,7 +2,7 @@ import {useState, useRef, useEffect} from 'react' import PropTypes from 'prop-types' -import Grid from '@mui/material/Grid2' +import Grid from '@mui/material/Grid' import Typography from '@mui/material/Typography' import HomeIcon from '@mui/icons-material/Home' import Box from '@mui/material/Box' diff --git a/components/versions/version-comparison.js b/components/versions/version-comparison.js index 8c6222a..27b8444 100644 --- a/components/versions/version-comparison.js +++ b/components/versions/version-comparison.js @@ -1,7 +1,7 @@ import Box from '@mui/material/Box' import Typography from '@mui/material/Typography' import Paper from '@mui/material/Paper' -import Grid from '@mui/material/Grid2' +import Grid from '@mui/material/Grid' import PropTypes from 'prop-types' import Snackbar from '@mui/material/Snackbar' import Alert from '@mui/material/Alert' diff --git a/components/versions/version-timeline.js b/components/versions/version-timeline.js index 520ed55..b168a29 100644 --- a/components/versions/version-timeline.js +++ b/components/versions/version-timeline.js @@ -1,4 +1,4 @@ -import {useRef, useState} from 'react' +import {useRef, useState, useEffect} from 'react' import {useTheme} from '@mui/material/styles' import PropTypes from 'prop-types' import Box from '@mui/material/Box' @@ -34,17 +34,25 @@ import PrintButton from './print-button.js' import {formatDate} from '@/lib/format.js' import {compareVersion} from '@/lib/directus.js' -function getVersionStatus(version, index, totalVersions) { +function getVersionStatus(version, index, totalVersions, data) { // Logic to determine version status based on position and data - if (index === 0) { - return 'current' // Most recent - } + // Find which version is the "main" (published) by checking if it matches current content + // This would require the current item content to be passed + // For now, we assume the most recent is current unless it's been promoted + // Check if this is the initial version if (index === totalVersions - 1) { return 'initial' // First version } - return 'archived' // Intermediate versions + // If there's a more recent version after this one, this is outdated + // unless this IS the main version (would need item content to determine) + if (index > 0) { + return 'outdated' // Older versions are outdated + } + + // Most recent version is current (being edited/proposed) + return 'current' } function getStatusConfig(status) { @@ -115,15 +123,56 @@ function VersionCard({ onVoteResult }) { const theme = useTheme() - const status = getVersionStatus(version, index, totalVersions) + const [versionStatus, setVersionStatus] = useState(null) + const [isOutdated, setIsOutdated] = useState(false) + + // Fetch real status from API + useEffect(() => { + async function fetchVersionStatus() { + try { + const comparisonData = await compareVersion({ + accessToken, + userId, + versionId: version.id, + countdownRef, + setError, + setIsErrorAlertOpen + }) + + if (comparisonData) { + // Store outdated flag for vote disabling + setIsOutdated(comparisonData.outdated) + + // Determine status based on API response + let status + if (comparisonData.outdated) { + status = 'outdated' + } else if (index === totalVersions - 1) { + status = 'initial' + } else { + status = 'current' + } + setVersionStatus(status) + } + } catch (error) { + // Fallback to position-based status on error + setVersionStatus(getVersionStatus(version, index, totalVersions, null)) + } + } + + fetchVersionStatus() + }, [version.id, index, totalVersions, accessToken, userId, countdownRef, setError, setIsErrorAlertOpen]) + + const status = versionStatus || getVersionStatus(version, index, totalVersions, null) const statusConfig = getStatusConfig(status) const userDisplayName = version.user_created?.split('-')[0] || 'Système' - // Check if voting is disabled (after 3 days) + // Check if voting is disabled (after 3 days OR if outdated) const createdAt = new Date(version.date_created) const threeDaysAgo = new Date(Date.now() - (3 * 24 * 60 * 60 * 1000)) - const isVoteDisabled = createdAt < threeDaysAgo + const isExpired = createdAt < threeDaysAgo + const isVoteDisabled = isExpired || isOutdated const handleCompareClick = async () => { const comparisonData = await compareVersion({ @@ -214,7 +263,7 @@ function VersionCard({ size='small' variant='outlined' /> - {isVoteDisabled && ( + {isExpired && !isOutdated && (