64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
|
|
import React from 'react';
|
|||
|
|
import { CurrentView, NewsArticle } from '../types'; // Added NewsArticle type
|
|||
|
|
import { SECTION_IDS, NEWS_SECTION_CONTENT } from '../constants';
|
|||
|
|
import { ChevronRightIcon } from './icons';
|
|||
|
|
import NewsCard from './NewsCard';
|
|||
|
|
|
|||
|
|
interface NewsSectionProps {
|
|||
|
|
newsArticles: NewsArticle[]; // Changed from mockNews
|
|||
|
|
setCurrentView: (view: CurrentView) => void;
|
|||
|
|
setSelectedItemId: (id: string | null) => void;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const NewsSection: React.FC<NewsSectionProps> = ({ newsArticles, setCurrentView, setSelectedItemId }) => {
|
|||
|
|
|
|||
|
|
const handleShowAllClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|||
|
|
e.preventDefault();
|
|||
|
|
setCurrentView('newsAll');
|
|||
|
|
setSelectedItemId(null);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
if (!newsArticles || newsArticles.length === 0) {
|
|||
|
|
return (
|
|||
|
|
<section id={SECTION_IDS.latestNews} className="py-16 md:py-24 bg-white">
|
|||
|
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8 text-center">
|
|||
|
|
<p className="text-slate-600 font-inter">Загрузка новостей...</p>
|
|||
|
|
</div>
|
|||
|
|
</section>
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<section id={SECTION_IDS.latestNews} className="py-16 md:py-24 bg-white">
|
|||
|
|
<div className="container mx-auto px-4 sm:px-6 lg:px-8">
|
|||
|
|
<div className="flex justify-between items-baseline mb-12 md:mb-16">
|
|||
|
|
<h2 className="font-quicksand text-4xl sm:text-5xl font-bold text-slate-900">
|
|||
|
|
{NEWS_SECTION_CONTENT.title}
|
|||
|
|
</h2>
|
|||
|
|
<a
|
|||
|
|
href={`#${SECTION_IDS.newsAllPage}`}
|
|||
|
|
onClick={handleShowAllClick}
|
|||
|
|
className="group inline-flex items-center text-base font-medium text-slate-700 hover:text-black transition-colors whitespace-nowrap"
|
|||
|
|
aria-label={NEWS_SECTION_CONTENT.showAllAriaLabel}
|
|||
|
|
>
|
|||
|
|
{NEWS_SECTION_CONTENT.showAllText}
|
|||
|
|
<ChevronRightIcon className="ml-1 w-5 h-5 transform group-hover:translate-x-1 transition-transform duration-200" />
|
|||
|
|
</a>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-8">
|
|||
|
|
{newsArticles.slice(-4).reverse().map(article => (
|
|||
|
|
<NewsCard
|
|||
|
|
key={article.id}
|
|||
|
|
article={article}
|
|||
|
|
setCurrentView={setCurrentView}
|
|||
|
|
setSelectedItemId={setSelectedItemId}
|
|||
|
|
/>
|
|||
|
|
))}
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
</section>
|
|||
|
|
);
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
export default NewsSection;
|