import { cn } from '../../../lib/cn'; import { IconError, IconSuccess } from '../../../assets/icons/missions'; import { useNavigate } from 'react-router-dom'; import { useLocation } from 'react-router-dom'; export interface MissionItemProps { id: number; name: string; timeLimit?: number; memoryLimit?: number; type?: 'first' | 'second'; status?: 'empty' | 'success' | 'error'; } export function formatMilliseconds(ms: number): string { const rounded = Math.round(ms) / 1000; const formatted = rounded.toString().replace(/\.?0+$/, ''); return `${formatted} c`; } export function formatBytesToMB(bytes: number): string { const megabytes = Math.floor(bytes / (1024 * 1024)); return `${megabytes} МБ`; } const MissionItem: React.FC = ({ id, name, timeLimit = 1000, memoryLimit = 256 * 1024 * 1024, type, status, }) => { const navigate = useNavigate(); const location = useLocation(); const path = location.pathname + location.search; return (
{ navigate(`/mission/${id}?back=${path}`); }} >
#{id}
{name}
стандартный ввод/вывод {formatMilliseconds(timeLimit)},{' '} {formatBytesToMB(memoryLimit)}
{status == 'error' && } {status == 'success' && }
); }; export default MissionItem;