This commit is contained in:
NotII
2025-03-24 00:17:45 +00:00
parent c65511aa5d
commit 6566b427b0
2 changed files with 20 additions and 9 deletions

View File

@@ -283,20 +283,19 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
// Send a message
const sendMessage = async () => {
if (!chatId || !message.trim()) return;
if (!message.trim()) return;
// Optimistically add message to UI
// Create temporary message to show immediately
const tempId = `temp-${Date.now()}`;
const tempMessage = {
const tempMessage: Message = {
_id: tempId,
chatId,
sender: "vendor" as const,
sender: 'vendor',
content: message.trim(),
attachments: [],
read: false,
read: true,
createdAt: new Date().toISOString(),
buyerId: chatData?.buyerId || "",
vendorId: chatData?.vendorId || "",
buyerId: chat?.buyerId || '',
vendorId: chat?.vendorId || '',
};
setMessages(prev => [...prev, tempMessage]);
@@ -309,7 +308,13 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
// Use clientFetch instead of direct axios calls
const response = await clientFetch(`/chats/${chatId}/message`, {
method: 'POST',
body: JSON.stringify({ message: message.trim() }),
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: message.trim(),
attachments: []
}),
});
// Replace temp message with real one from server