import { useState, useEffect } from 'react'; import { useParams, Link } from 'react-router-dom'; import { ArrowLeft, Clock, Share2, Bookmark } from 'lucide-react'; import { Header } from '../components/Header'; import { ReactionButtons } from '../components/ReactionButtons'; import { PhotoGallery } from '../components/PhotoGallery'; //import { articles } from '../data/mock'; import {Article, CategoryTitles} from '../types'; import { ArticleContent } from '../components/ArticleContent'; import MinutesWord from '../components/MinutesWord'; import axios from "axios"; export function ArticlePage() { const { id } = useParams(); const [articleData, setArticleData] = useState
(null); // const [error, setError] = useState(null); /* const [articleData, setArticleData] = useState
( articles.find(a => a.id === id) ); */ useEffect(() => { const fetchArticle = async () => { try { const response = await axios.get(`/api/articles/${id}`); setArticleData(response.data); } catch (error) { //setError('Не удалось загрузить статью'); console.error(error); } }; fetchArticle(); }, [id]); useEffect(() => { window.scrollTo(0, 0); }, [id]); if (!articleData) { return (

Article not found

Назад на главную
); } const handleReaction = (reaction: 'like' | 'dislike') => { setArticleData(prev => { if (!prev) return prev; const newArticle = { ...prev }; if (prev.userReaction === 'like') newArticle.likes--; if (prev.userReaction === 'dislike') newArticle.dislikes--; if (prev.userReaction !== reaction) { if (reaction === 'like') newArticle.likes++; if (reaction === 'dislike') newArticle.dislikes++; newArticle.userReaction = reaction; } else { newArticle.userReaction = null; } return newArticle; }); }; return (
К списку статей
{/* Article Header */}
{articleData.author.displayName}

{articleData.author.displayName}

{articleData.readTime} на чтение ·{' '} {new Date(articleData.publishedAt).toLocaleDateString('ru-RU', { month: 'long', day: 'numeric', year: 'numeric', })}

{articleData.title}

{articleData.excerpt}

{CategoryTitles[articleData.categoryId]}
{/* Cover Image */} {articleData.title} {/* Article Content */}
{/* Photo Gallery */} {articleData.gallery && articleData.gallery.length > 0 && (

Фото галерея

)} {/* Article Footer */}
); }