Show which listing each chat is about
The chat list and header show the listing's type, city and closed/deleted status; the header info button opens the full listing in PostDetailModal with a "show on map" action. Deleted or unpublished listings are marked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,25 @@ import { useAuthContext } from "../context/AuthContext";
|
||||
import PostOnFeed from "../pages/PostOnFeed";
|
||||
import CloseIcon from "./icons/CloseIcon";
|
||||
|
||||
export default function PostDetailModal({ postId, onClose, onLocationClick, onAuthRequired }) {
|
||||
/**
|
||||
* Модалка с полным объявлением, догружаемым по id.
|
||||
*
|
||||
* compact — компактная карточка (без адреса и даты), как при открытии с карты;
|
||||
* hideContact — без кнопки «Написать» (модалка открыта из самого чата);
|
||||
* fallbackTitle — что показать над сообщением, если объявление удалено или скрыто;
|
||||
* footer(post) — дополнительные действия под карточкой.
|
||||
*
|
||||
* @param {{
|
||||
* postId: any, onClose: () => void,
|
||||
* onLocationClick?: (ad: any) => void, onAuthRequired?: () => void,
|
||||
* compact?: boolean, hideContact?: boolean,
|
||||
* fallbackTitle?: string, footer?: (post: any) => any,
|
||||
* }} props
|
||||
*/
|
||||
export default function PostDetailModal({
|
||||
postId, onClose, onLocationClick, onAuthRequired,
|
||||
compact = true, hideContact = false, fallbackTitle, footer,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const { user } = useAuthContext();
|
||||
const [post, setPost] = useState(null);
|
||||
@@ -22,6 +40,8 @@ export default function PostDetailModal({ postId, onClose, onLocationClick, onAu
|
||||
setError(null);
|
||||
try {
|
||||
const res = await apiFetch(`${API_URL}/api/v1/posts/${encodeURIComponent(postId)}`);
|
||||
// 404 — объявление удалено или снято с публикации (модерация, отклонено)
|
||||
if (res.status === 404) throw new Error("notFound");
|
||||
if (!res.ok) throw new Error("Failed to load post");
|
||||
const data = await res.json();
|
||||
if (!cancelled) {
|
||||
@@ -52,20 +72,31 @@ export default function PostDetailModal({ postId, onClose, onLocationClick, onAu
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
{error === "notFound" && (
|
||||
<div className="f-post-detail-status f-post-detail-gone" role="status">
|
||||
{fallbackTitle && <div className="f-post-detail-gone-title">{fallbackTitle}</div>}
|
||||
<div className="f-post-detail-gone-text">{t("chat.postUnavailable")}</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && error !== "notFound" && (
|
||||
<div className="f-post-detail-status f-post-detail-error">
|
||||
{t("common.error")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{post && (
|
||||
<PostOnFeed
|
||||
ad={post}
|
||||
isOwner={isOwner}
|
||||
onLocationClick={onLocationClick}
|
||||
onAuthRequired={onAuthRequired}
|
||||
compact
|
||||
/>
|
||||
<>
|
||||
<PostOnFeed
|
||||
ad={post}
|
||||
isOwner={isOwner}
|
||||
onLocationClick={onLocationClick}
|
||||
onAuthRequired={onAuthRequired}
|
||||
compact={compact}
|
||||
hideContact={hideContact}
|
||||
/>
|
||||
{footer?.(post)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user