import PinIcon from "./icons/PinIcon"; import CalendarIcon from "./icons/CalendarIcon"; import PhoneIcon from "./icons/PhoneIcon"; import MapIcon from "./icons/MapIcon"; import HeartIcon from "./icons/HeartIcon"; import TrashIcon from "./icons/TrashIcon"; import { useNavigate } from "react-router-dom"; import { useChats } from "../hooks/useChats"; import { useAuthContext } from "../context/AuthContext"; import { API_URL } from "../config/authConstants"; export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, onMarkFound, isOwner }) { const navigate = useNavigate(); const { createOrGetChat } = useChats(); const { isAuthenticated } = useAuthContext(); const handleContact = async (e) => { e.stopPropagation(); try { const chat = await createOrGetChat(ad.userId, ad.id); navigate(`/chats/${chat.id}`); } catch (err) { console.error(err); } }; const imageUrl = ad.images?.[0] ? `${API_URL}${ad.images[0]}` : null; // ✅ Формируем строку адреса из city + district const address = [ad.city, ad.district].filter(Boolean).join(", "); const createdAt = ad.createdAt ? new Date(ad.createdAt).toLocaleDateString("ru-RU") : null; // Проверяем, закрыт ли пост (вещь найдена) const isClosed = ad.status === 'CLOSED'; const roleClass = ad.userRole === 'LOST_AND_FOUND' ? 'f-card-role-lost-found' : ad.userRole === 'METRO' ? 'f-card-role-metro' : ''; const roleBadge = ad.userRole === 'LOST_AND_FOUND' ? (
Бюро находок
) : ad.userRole === 'METRO' ? (
М Метрополитен
) : null; return (
{imageUrl ? {ad.title} : {ad.emoji || "📋"} }
{ad.category &&
{ad.category}
}
{ad.type === "loss" ? "Потеря" : "Находка"}
{roleBadge} {isClosed &&
✓ Найдено
}
{ad.title}
{ad.description}
{/* ✅ address вместо ad.location */} {address &&
{address}
} {/* ✅ createdAt вместо ad.date */} {createdAt &&
{createdAt}
}
{address && ( )}
{ad.phone && ( e.stopPropagation()}> {ad.phone} )}
{isAuthenticated && !isOwner && !isClosed && ( )} {onEdit && isOwner && !isClosed && ( )} {onDelete && isOwner && ( )} {onMarkFound && isOwner && !isClosed && ( )}
); }