import React, { useEffect } from 'react'; import Box from '@mui/material/Box'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import CardHeader from '@mui/material/CardHeader'; import Container from '@mui/material/Container'; import Grid from '@mui/material/Grid'; import Link from '@mui/material/Link'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { observer } from 'mobx-react-lite'; import { useStore } from '../../../shared/hooks/useStore.ts'; import { formatDate, getDateValue } from '../../news/utils/formatDate.ts'; const RecentNewsComponent: React.FC = () => { const { news } = useStore(); useEffect(() => { const load = async () => { try { await news.fetch({ limit: 10 }); } catch { /* errors surfaced via store state */ } }; void load(); }, [news]); const visibleNews = news.list .slice() .sort((a, b) => getDateValue(b.publishedAt) - getDateValue(a.publishedAt)) .slice(0, 3); const hasNews = visibleNews.length > 0; return ( Последние новости {news.isLoading && ( Загружаем последние новости... )} {news.error && ( {news.error} )} {hasNews && ( {visibleNews.map((item) => ( {item.summary} Читать полностью ))} )} Лента новостей ); }; export const RecentNews = observer(RecentNewsComponent);