added chat with another users
This commit is contained in:
@@ -3,9 +3,25 @@ import CalendarIcon from "./icons/CalendarIcon";
|
||||
import PhoneIcon from "./icons/PhoneIcon";
|
||||
import MapIcon from "./icons/MapIcon";
|
||||
import HeartIcon from "./icons/HeartIcon";
|
||||
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, 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
|
||||
@@ -53,6 +69,11 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, isOwner }) {
|
||||
)}
|
||||
</div>
|
||||
<div className="f-card-foot-right">
|
||||
{isAuthenticated && !isOwner && (
|
||||
<button className="f-card-contact" onClick={handleContact}>
|
||||
Написать
|
||||
</button>
|
||||
)}
|
||||
{onEdit && isOwner && (
|
||||
<button className="f-like-btn"
|
||||
onClick={e => { e.stopPropagation(); onEdit(ad); }}>
|
||||
|
||||
Reference in New Issue
Block a user