Merge pull request #89 from SlimusMinus/fix-chat-post-image
All checks were successful
deploy-frontend / deploy (push) Successful in 44s
All checks were successful
deploy-frontend / deploy (push) Successful in 44s
Fix chat post image
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
// Тот же лимит, что ChatService.MAX_MESSAGE_LENGTH на бэкенде
|
||||||
|
const MAX_MESSAGE_LENGTH = 4000;
|
||||||
|
|
||||||
export default function ChatInputBar({
|
export default function ChatInputBar({
|
||||||
input,
|
input,
|
||||||
onInputChange,
|
onInputChange,
|
||||||
@@ -13,6 +16,7 @@ export default function ChatInputBar({
|
|||||||
onChange={(e) => onInputChange(e.target.value)}
|
onChange={(e) => onInputChange(e.target.value)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
className="chat-input"
|
className="chat-input"
|
||||||
|
maxLength={MAX_MESSAGE_LENGTH}
|
||||||
/>
|
/>
|
||||||
<button type="submit" className="chat-send-btn" disabled={!connected}>
|
<button type="submit" className="chat-send-btn" disabled={!connected}>
|
||||||
➤
|
➤
|
||||||
|
|||||||
@@ -47,11 +47,26 @@ export function useChats() {
|
|||||||
if (postId) url.searchParams.set("postId", postId);
|
if (postId) url.searchParams.set("postId", postId);
|
||||||
|
|
||||||
const res = await apiFetch(url, { method: "POST" });
|
const res = await apiFetch(url, { method: "POST" });
|
||||||
if (!res.ok) throw new Error(t('chats.createError'));
|
if (!res.ok) {
|
||||||
|
// Причину отказа (чат с собой, чужое объявление и т.п.) пишем в консоль,
|
||||||
|
// иначе 400 выглядит как необъяснимый сбой
|
||||||
|
const body = await res.json().catch(() => null);
|
||||||
|
console.warn("createOrGetChat failed:", res.status, body?.message);
|
||||||
|
throw new Error(t('chats.createError'));
|
||||||
|
}
|
||||||
const chat = await res.json();
|
const chat = await res.json();
|
||||||
if (postInfo && chat.id) {
|
// Объявление чата берём из ответа бэкенда: если он вернул существующий чат по
|
||||||
|
// другому объявлению, postInfo с карточки привязал бы к нему чужую картинку.
|
||||||
|
// postInfo — только дополнение (emoji) для того же объявления.
|
||||||
|
if (chat.id) {
|
||||||
|
const sameAd = postInfo && (chat.post?.id ?? chat.postId) != null
|
||||||
|
&& String(chat.post?.id ?? chat.postId) === String(postInfo.id);
|
||||||
|
if (chat.post) {
|
||||||
|
setPostForChat(chat.id, { ...(sameAd ? postInfo : {}), ...chat.post });
|
||||||
|
} else if (sameAd) {
|
||||||
setPostForChat(chat.id, postInfo);
|
setPostForChat(chat.id, postInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return chat;
|
return chat;
|
||||||
}, [t]);
|
}, [t]);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
|||||||
const rewardAnchorRef = useRef(null);
|
const rewardAnchorRef = useRef(null);
|
||||||
const descRef = useRef(null);
|
const descRef = useRef(null);
|
||||||
const imgTouchStartRef = useRef(null);
|
const imgTouchStartRef = useRef(null);
|
||||||
const { isAuthenticated } = useAuthContext();
|
const { isAuthenticated, user } = useAuthContext();
|
||||||
|
// Своё объявление: писать самому себе нельзя (бэкенд отвечает 400), кнопку не показываем.
|
||||||
|
// isOwner тут не подходит — в общей ленте он false и для своих объявлений.
|
||||||
|
const isOwnAd = user?.id != null && ad.userId != null && String(ad.userId) === String(user.id);
|
||||||
const { contactSeller, error: contactError, clearError } = useContactSeller(ad);
|
const { contactSeller, error: contactError, clearError } = useContactSeller(ad);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -301,10 +304,12 @@ export default function PostOnFeed({ ad, onEdit, onDelete, onMarkFound, onReopen
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="f-card-foot-right">
|
<div className="f-card-foot-right">
|
||||||
|
{!isOwnAd && (
|
||||||
<button type="button" className="f-card-contact"
|
<button type="button" className="f-card-contact"
|
||||||
onClick={handleContact}>
|
onClick={handleContact}>
|
||||||
{t('postCard.write')}
|
{t('postCard.write')}
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{onMarkFound && isOwner && !isClosed && (
|
{onMarkFound && isOwner && !isClosed && (
|
||||||
|
|||||||
Reference in New Issue
Block a user