refactor: utilise VoteButtons dans VersionTimeline
This commit is contained in:
@@ -20,8 +20,11 @@ import AccessTimeIcon from '@mui/icons-material/AccessTime'
|
|||||||
import CheckCircleIcon from '@mui/icons-material/CheckCircle'
|
import CheckCircleIcon from '@mui/icons-material/CheckCircle'
|
||||||
import ErrorIcon from '@mui/icons-material/Error'
|
import ErrorIcon from '@mui/icons-material/Error'
|
||||||
import EditIcon from '@mui/icons-material/Edit'
|
import EditIcon from '@mui/icons-material/Edit'
|
||||||
|
import Snackbar from '@mui/material/Snackbar'
|
||||||
|
import Alert from '@mui/material/Alert'
|
||||||
import SessionExpired from '../session/session-expired.js'
|
import SessionExpired from '../session/session-expired.js'
|
||||||
import VersionDialog from './version-dialog.js'
|
import VersionDialog from './version-dialog.js'
|
||||||
|
import VoteButtons from './vote-buttons.js'
|
||||||
import {formatDate} from '@/lib/format.js'
|
import {formatDate} from '@/lib/format.js'
|
||||||
import {compareVersion} from '@/lib/directus.js'
|
import {compareVersion} from '@/lib/directus.js'
|
||||||
|
|
||||||
@@ -102,9 +105,11 @@ function VersionCard({
|
|||||||
setError,
|
setError,
|
||||||
setIsErrorAlertOpen,
|
setIsErrorAlertOpen,
|
||||||
setIsOpenComparison,
|
setIsOpenComparison,
|
||||||
setVersionCompare
|
setVersionCompare,
|
||||||
|
onVoteResult
|
||||||
}) {
|
}) {
|
||||||
const status = getVersionStatus(version, index, totalVersions)
|
const status = getVersionStatus(version, index, totalVersions)
|
||||||
|
|
||||||
const statusConfig = getStatusConfig(status)
|
const statusConfig = getStatusConfig(status)
|
||||||
const userDisplayName = version.user_created?.split('-')[0] || 'Système'
|
const userDisplayName = version.user_created?.split('-')[0] || 'Système'
|
||||||
|
|
||||||
@@ -180,21 +185,7 @@ function VersionCard({
|
|||||||
{formatDate(version.date_created, 'PPpp')}
|
{formatDate(version.date_created, 'PPpp')}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{/* Placeholder for vote count - would need API enhancement */}
|
<VoteButtons hasCountsVisible versionId={version.id} onVoteResult={onVoteResult} />
|
||||||
<Box sx={{display: 'flex', gap: 1}}>
|
|
||||||
<Chip
|
|
||||||
label='👍 0'
|
|
||||||
size='small'
|
|
||||||
variant='outlined'
|
|
||||||
sx={{fontSize: '0.7rem'}}
|
|
||||||
/>
|
|
||||||
<Chip
|
|
||||||
label='👎 0'
|
|
||||||
size='small'
|
|
||||||
variant='outlined'
|
|
||||||
sx={{fontSize: '0.7rem'}}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
</Box>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|
||||||
@@ -224,9 +215,22 @@ export default function VersionTimeline({
|
|||||||
const countdownRef = useRef()
|
const countdownRef = useRef()
|
||||||
const [isOpenComparison, setIsOpenComparison] = useState(false)
|
const [isOpenComparison, setIsOpenComparison] = useState(false)
|
||||||
const [versionCompare, setVersionCompare] = useState(null)
|
const [versionCompare, setVersionCompare] = useState(null)
|
||||||
|
const [snackbar, setSnackbar] = useState({open: false, message: '', severity: 'success'})
|
||||||
|
|
||||||
const versionData = data.find(({id}) => id === versionCompare?.versionId)
|
const versionData = data.find(({id}) => id === versionCompare?.versionId)
|
||||||
|
|
||||||
|
const handleVoteResult = result => {
|
||||||
|
setSnackbar({
|
||||||
|
open: true,
|
||||||
|
message: result.message,
|
||||||
|
severity: result.success ? 'success' : 'error'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCloseSnackbar = () => {
|
||||||
|
setSnackbar(prev => ({...prev, open: false}))
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -269,6 +273,7 @@ export default function VersionTimeline({
|
|||||||
setIsErrorAlertOpen={setIsErrorAlertOpen}
|
setIsErrorAlertOpen={setIsErrorAlertOpen}
|
||||||
setIsOpenComparison={setIsOpenComparison}
|
setIsOpenComparison={setIsOpenComparison}
|
||||||
setVersionCompare={setVersionCompare}
|
setVersionCompare={setVersionCompare}
|
||||||
|
onVoteResult={handleVoteResult}
|
||||||
/>
|
/>
|
||||||
</TimelineContent>
|
</TimelineContent>
|
||||||
</TimelineItem>
|
</TimelineItem>
|
||||||
@@ -290,6 +295,17 @@ export default function VersionTimeline({
|
|||||||
setError={setError}
|
setError={setError}
|
||||||
setIsErrorAlertOpen={setIsErrorAlertOpen}
|
setIsErrorAlertOpen={setIsErrorAlertOpen}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Snackbar
|
||||||
|
open={snackbar.open}
|
||||||
|
autoHideDuration={6000}
|
||||||
|
anchorOrigin={{vertical: 'bottom', horizontal: 'center'}}
|
||||||
|
onClose={handleCloseSnackbar}
|
||||||
|
>
|
||||||
|
<Alert variant='filled' severity={snackbar.severity} sx={{width: '100%'}} onClose={handleCloseSnackbar}>
|
||||||
|
{snackbar.message}
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -313,5 +329,6 @@ VersionCard.propTypes = {
|
|||||||
setError: PropTypes.func.isRequired,
|
setError: PropTypes.func.isRequired,
|
||||||
setIsErrorAlertOpen: PropTypes.func.isRequired,
|
setIsErrorAlertOpen: PropTypes.func.isRequired,
|
||||||
setIsOpenComparison: PropTypes.func.isRequired,
|
setIsOpenComparison: PropTypes.func.isRequired,
|
||||||
setVersionCompare: PropTypes.func.isRequired
|
setVersionCompare: PropTypes.func.isRequired,
|
||||||
|
onVoteResult: PropTypes.func.isRequired
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user