import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { Heart, MessageCircle, MoreVertical, ChevronLeft, ChevronRight } from 'lucide-react' import { likePost, deletePost } from '../utils/api' import { hapticFeedback, showConfirm } from '../utils/telegram' import './PostCard.css' const TAG_COLORS = { furry: '#FF8A33', anime: '#4A90E2', other: '#A0A0A0' } const TAG_NAMES = { furry: 'Furry', anime: 'Anime', other: 'Other' } export default function PostCard({ post, currentUser, onUpdate }) { const navigate = useNavigate() const [liked, setLiked] = useState(post.likes.includes(currentUser.id)) const [likesCount, setLikesCount] = useState(post.likes.length) const [currentImageIndex, setCurrentImageIndex] = useState(0) // Поддержка и старого поля imageUrl и нового images const images = post.images && post.images.length > 0 ? post.images : (post.imageUrl ? [post.imageUrl] : []) const handleLike = async () => { try { hapticFeedback('light') const result = await likePost(post._id) setLiked(result.liked) setLikesCount(result.likes) if (result.liked) { hapticFeedback('success') } } catch (error) { console.error('Ошибка лайка:', error) } } const handleDelete = async () => { const confirmed = await showConfirm('Удалить этот пост?') if (confirmed) { try { await deletePost(post._id) hapticFeedback('success') onUpdate() } catch (error) { console.error('Ошибка удаления:', error) } } } const formatDate = (date) => { const d = new Date(date) return d.toLocaleDateString('ru-RU', { day: 'numeric', month: 'short' }) } const goToProfile = () => { navigate(`/user/${post.author._id}`) } return (
{/* Хедер поста */}
{post.author.username}
{post.author.firstName} {post.author.lastName}
@{post.author.username} · {formatDate(post.createdAt)}
{/* Контент */} {post.content && (
{post.content}
)} {/* Изображения */} {images.length > 0 && (
{`Image {images.length > 1 && ( <> {currentImageIndex > 0 && ( )} {currentImageIndex < images.length - 1 && ( )}
{images.map((_, index) => ( setCurrentImageIndex(index)} /> ))}
)}
)} {/* Теги */}
{post.tags.map((tag, index) => ( {TAG_NAMES[tag]} ))} {post.isNSFW && ( NSFW )}
{/* Действия */}
) }