diff --git a/src/components/MainFeed.jsx b/src/components/MainFeed.jsx index 26f5b43..ab3f91a 100644 --- a/src/components/MainFeed.jsx +++ b/src/components/MainFeed.jsx @@ -13,6 +13,7 @@ import RulesModal from "./RulesModal"; import { useAuthContext } from "../context/AuthContext"; import { useDeletePost } from "../hooks/useDeletePost"; import { useFavorites } from "../hooks/useFavorites"; +import { usePostStatus } from "../hooks/usePostStatus"; /** * MainFeed — корневой компонент приложения. @@ -24,6 +25,7 @@ export default function MainFeed() { const { user, token, isAuthenticated, logout } = useAuthContext(); const { deletePost } = useDeletePost(); const { toggleFavorite, loadFavorites } = useFavorites(); + const { markAsFound } = usePostStatus(); // Открыт ли левый сайдбар (мобильный слайд-аут) const [sidebarOpen, setSidebarOpen] = useState(false); @@ -172,6 +174,19 @@ export default function MainFeed() { } }, [deletePost, loadFeed, loadMyPosts]); + /** Отмечает объявление как "Вещь найдена" и перезагружает ленту */ + const handleMarkFound = useCallback(async (postId) => { + if (!window.confirm("Отметить это объявление как \"Вещь найдена\"?")) { + return; + } + + const success = await markAsFound(postId, token); + if (success) { + loadFeed(); + loadMyPosts(); + } + }, [markAsFound, token, loadFeed, loadMyPosts]); + // После создания или редактирования объявления перезагружаем ленту, // чтобы получить актуальные данные (включая изображения) из БД const handleNewAd = useCallback(() => { loadFeed(); loadMyPosts(); }, [loadFeed, loadMyPosts]); @@ -283,6 +298,7 @@ export default function MainFeed() { onLike={toggleLike} onEdit={activeNav === "Мои объявления" ? handleEdit : undefined} onDelete={activeNav === "Мои объявления" ? handleDelete : undefined} + onMarkFound={activeNav === "Мои объявления" ? handleMarkFound : undefined} isOwner={activeNav === "Мои объявления"} /> )); diff --git a/src/components/PostOnFeed.jsx b/src/components/PostOnFeed.jsx index 60bea67..64610ff 100644 --- a/src/components/PostOnFeed.jsx +++ b/src/components/PostOnFeed.jsx @@ -9,7 +9,7 @@ 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, isOwner }) { +export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, onMarkFound, isOwner }) { const navigate = useNavigate(); const { createOrGetChat } = useChats(); const { isAuthenticated } = useAuthContext(); @@ -30,9 +30,12 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, isOwne const createdAt = ad.createdAt ? new Date(ad.createdAt).toLocaleDateString("ru-RU") : null; + + // Проверяем, закрыт ли пост (вещь найдена) + const isClosed = ad.status === 'CLOSED'; return ( -