added status found on post
This commit is contained in:
@@ -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 === "Мои объявления"}
|
||||
/>
|
||||
));
|
||||
|
||||
@@ -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 (
|
||||
<div className="f-card">
|
||||
<div className={`f-card${isClosed ? ' f-card-closed' : ''}`}>
|
||||
<div className="f-card-inner">
|
||||
<div className="f-card-img">
|
||||
{imageUrl
|
||||
@@ -46,6 +49,7 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, isOwne
|
||||
<div className={`f-type-badge ${ad.type === "loss" ? "f-type-loss" : "f-type-found"}`}>
|
||||
{ad.type === "loss" ? "Потеря" : "Находка"}
|
||||
</div>
|
||||
{isClosed && <div className="f-status-badge f-status-closed">✓ Найдено</div>}
|
||||
</div>
|
||||
<div className="f-card-title">{ad.title}</div>
|
||||
<div className="f-card-desc">{ad.description}</div>
|
||||
@@ -70,12 +74,12 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, isOwne
|
||||
)}
|
||||
</div>
|
||||
<div className="f-card-foot-right">
|
||||
{isAuthenticated && !isOwner && (
|
||||
{isAuthenticated && !isOwner && !isClosed && (
|
||||
<button className="f-card-contact" onClick={handleContact}>
|
||||
Написать
|
||||
</button>
|
||||
)}
|
||||
{onEdit && isOwner && (
|
||||
{onEdit && isOwner && !isClosed && (
|
||||
<button className="f-card-edit-btn"
|
||||
onClick={e => { e.stopPropagation(); onEdit(ad); }}>
|
||||
✏️
|
||||
@@ -87,6 +91,12 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, isOwne
|
||||
<TrashIcon />
|
||||
</button>
|
||||
)}
|
||||
{onMarkFound && isOwner && !isClosed && (
|
||||
<button className="f-card-found-btn"
|
||||
onClick={e => { e.stopPropagation(); onMarkFound(ad.id); }}>
|
||||
✓ Вещь найдена
|
||||
</button>
|
||||
)}
|
||||
<button className={`f-like-btn${liked ? " liked" : ""}`}
|
||||
onClick={e => { e.stopPropagation(); onLike(ad.id); }}>
|
||||
<HeartIcon filled={liked} />
|
||||
|
||||
Reference in New Issue
Block a user