@pubuduth-aplicy/chat-ui 2.1.76 → 2.1.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Chat.config.ts +1 -0
- package/src/components/Chat.tsx +7 -10
- package/src/components/messages/Message.tsx +0 -1
- package/src/components/messages/MessageContainer.tsx +13 -58
- package/src/components/messages/MessageInput.tsx +0 -3
- package/src/components/messages/Messages.tsx +8 -9
- package/src/components/sidebar/Conversation.tsx +9 -9
- package/src/components/sidebar/Conversations.tsx +3 -3
- package/src/declarations.d.ts +2 -0
- package/src/hooks/mutations/useDeleteMessage.ts +5 -5
- package/src/hooks/mutations/useEditMessage.ts +5 -5
- package/src/hooks/mutations/useSendMessage.ts +5 -5
- package/src/providers/ChatProvider.tsx +14 -14
- package/src/service/messageService.ts +1 -1
- package/src/service/sidebarApi.ts +2 -2
- package/src/style/style.css +194 -11
package/package.json
CHANGED
package/src/Chat.config.ts
CHANGED
package/src/components/Chat.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import { Sidebar } from "./sidebar/Sidebar";
|
|
|
5
5
|
import { useChatContext } from "../providers/ChatProvider";
|
|
6
6
|
|
|
7
7
|
export const Chat = () => {
|
|
8
|
-
const { setMessages, updateMessageStatus } = useChatUIStore();
|
|
8
|
+
const { setMessages, selectedConversation, updateMessageStatus } = useChatUIStore();
|
|
9
9
|
|
|
10
10
|
const { socket, sendMessage } = useChatContext();
|
|
11
11
|
|
|
@@ -15,16 +15,9 @@ export const Chat = () => {
|
|
|
15
15
|
const handleMessage = (event: MessageEvent) => {
|
|
16
16
|
try {
|
|
17
17
|
const parsed = JSON.parse(event.data);
|
|
18
|
-
console.log("Parsed WebSocket message:", parsed);
|
|
19
18
|
|
|
20
19
|
if (parsed.event === "newMessage") {
|
|
21
20
|
const message = parsed.data;
|
|
22
|
-
console.log(
|
|
23
|
-
"📨 Message received at:",
|
|
24
|
-
message.createdAt,
|
|
25
|
-
"from:",
|
|
26
|
-
message
|
|
27
|
-
);
|
|
28
21
|
// Send delivery confirmation
|
|
29
22
|
// Update UI immediately
|
|
30
23
|
setMessages((prev) => [...prev, message]);
|
|
@@ -51,10 +44,14 @@ export const Chat = () => {
|
|
|
51
44
|
return (
|
|
52
45
|
<div className="container mx-auto mb-5">
|
|
53
46
|
<div className="grid-container">
|
|
54
|
-
<div className={`sidebarContainer dark:bg-gray-800
|
|
47
|
+
<div className={`sidebarContainer dark:bg-gray-800 ${
|
|
48
|
+
selectedConversation ? "mobile-hidden" : "mobile-visible"
|
|
49
|
+
}`}>
|
|
55
50
|
<Sidebar />
|
|
56
51
|
</div>
|
|
57
|
-
<div className=
|
|
52
|
+
<div className={`messageContainer ${
|
|
53
|
+
selectedConversation ? "mobile-visible" : "mobile-hidden"
|
|
54
|
+
}`}>
|
|
58
55
|
<MessageContainer />
|
|
59
56
|
</div>
|
|
60
57
|
</div>
|
|
@@ -114,7 +114,6 @@ const Message = ({ message }: MessageProps) => {
|
|
|
114
114
|
// const handleDownload = (url: string, name: string) => {
|
|
115
115
|
// saveAs(url, name);
|
|
116
116
|
// };
|
|
117
|
-
console.log("check message status", message.status);
|
|
118
117
|
|
|
119
118
|
const [downloadingIndex, setDownloadingIndex] = useState<number | null>(null);
|
|
120
119
|
const [downloadProgress, setDownloadProgress] = useState<number>(0);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { MessageSquare } from "lucide-react";
|
|
2
|
+
import { ChevronLeft, MessageSquare } from "lucide-react";
|
|
3
|
+
import { FiArrowLeft } from "react-icons/fi";
|
|
3
4
|
import { useEffect } from "react";
|
|
4
5
|
import MessageInput from "./MessageInput";
|
|
5
6
|
import Messages from "./Messages";
|
|
@@ -13,52 +14,6 @@ const MessageContainer = () => {
|
|
|
13
14
|
useChatUIStore();
|
|
14
15
|
const { socket, isUserOnline } = useChatContext();
|
|
15
16
|
const { role } = getChatConfig();
|
|
16
|
-
// useEffect(() => {
|
|
17
|
-
// if (!socket) return;
|
|
18
|
-
|
|
19
|
-
// const handleMessage = (event) => {
|
|
20
|
-
// try {
|
|
21
|
-
// const parsed = JSON.parse(event.data);
|
|
22
|
-
|
|
23
|
-
// if (parsed.event === 'newMessage') {
|
|
24
|
-
// const message = parsed.data;
|
|
25
|
-
// console.log('Received message:', message);
|
|
26
|
-
|
|
27
|
-
// if (selectedConversation?._id !== message.chatId) return;
|
|
28
|
-
|
|
29
|
-
// const messageId = message._id || message.messageId;
|
|
30
|
-
// console.log('Message ID for unread:', messageId);
|
|
31
|
-
|
|
32
|
-
// if (!messageId) {
|
|
33
|
-
// console.warn('Message has no _id or messageId, skipping unread tracking');
|
|
34
|
-
// return;
|
|
35
|
-
// }
|
|
36
|
-
|
|
37
|
-
// const updatedUnread = [
|
|
38
|
-
// ...(selectedConversation?.unreadMessageIds || []),
|
|
39
|
-
// messageId,
|
|
40
|
-
// ];
|
|
41
|
-
|
|
42
|
-
// console.log('Updated unreadMessageIds:', updatedUnread);
|
|
43
|
-
|
|
44
|
-
// setSelectedConversation({
|
|
45
|
-
// ...selectedConversation,
|
|
46
|
-
// unreadMessageIds: updatedUnread,
|
|
47
|
-
// });
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// // Handle other events...
|
|
51
|
-
|
|
52
|
-
// } catch (error) {
|
|
53
|
-
// console.error("WebSocket message parse error:", error);
|
|
54
|
-
// }
|
|
55
|
-
// };
|
|
56
|
-
|
|
57
|
-
// socket.addEventListener("message", handleMessage);
|
|
58
|
-
// return () => socket.removeEventListener("message", handleMessage);
|
|
59
|
-
// }, [socket, setMessages, selectedConversation, setSelectedConversation]);
|
|
60
|
-
|
|
61
|
-
// Join chat room when conversation is selected
|
|
62
17
|
|
|
63
18
|
useEffect(() => {
|
|
64
19
|
if (selectedConversation?._id && socket?.readyState === WebSocket.OPEN) {
|
|
@@ -68,7 +23,7 @@ const MessageContainer = () => {
|
|
|
68
23
|
event: "joinChat",
|
|
69
24
|
data: {
|
|
70
25
|
chatId: selectedConversation._id,
|
|
71
|
-
userId: userId
|
|
26
|
+
userId: userId,
|
|
72
27
|
},
|
|
73
28
|
})
|
|
74
29
|
);
|
|
@@ -81,7 +36,6 @@ const MessageContainer = () => {
|
|
|
81
36
|
const handleMessage = (event: MessageEvent) => {
|
|
82
37
|
try {
|
|
83
38
|
const data = JSON.parse(event.data);
|
|
84
|
-
console.log("Parsed WebSocket message in mc:", data);
|
|
85
39
|
|
|
86
40
|
if (data.event === "getOnlineUsers") {
|
|
87
41
|
setOnlineUsers(data.payload); // payload should be an array of user IDs
|
|
@@ -100,20 +54,18 @@ const MessageContainer = () => {
|
|
|
100
54
|
|
|
101
55
|
// Listen for online users updates
|
|
102
56
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
57
|
+
const participantDetails = Array.isArray(
|
|
58
|
+
selectedConversation?.participantDetails
|
|
59
|
+
)
|
|
106
60
|
? selectedConversation?.participantDetails
|
|
107
61
|
: [selectedConversation?.participantDetails].filter(Boolean);
|
|
108
62
|
|
|
109
|
-
const participant = participantDetails.find(
|
|
110
|
-
(p: any) => p._id !== userId
|
|
111
|
-
);
|
|
63
|
+
const participant = participantDetails.find((p: any) => p._id !== userId);
|
|
112
64
|
|
|
113
65
|
// const participant = selectedConversation?.participantDetails?.find(
|
|
114
66
|
// (p: any) => p._id !== userId
|
|
115
67
|
// );
|
|
116
|
-
|
|
68
|
+
|
|
117
69
|
const isOnline = isUserOnline(participant?._id || "");
|
|
118
70
|
|
|
119
71
|
// Cleanup on unmount
|
|
@@ -129,8 +81,11 @@ const MessageContainer = () => {
|
|
|
129
81
|
<>
|
|
130
82
|
<div className="chatMessageContainerInner">
|
|
131
83
|
<div className="chatMessageContainerInnerDiv">
|
|
132
|
-
<button
|
|
133
|
-
|
|
84
|
+
<button
|
|
85
|
+
className="backButton"
|
|
86
|
+
onClick={() => setSelectedConversation(null)}
|
|
87
|
+
>
|
|
88
|
+
<ChevronLeft size={20} />
|
|
134
89
|
</button>
|
|
135
90
|
{selectedConversation.type === "service" ? (
|
|
136
91
|
<div className="w-10 h-10 rounded-full bg-gray-200 flex items-center justify-center">
|
|
@@ -76,7 +76,6 @@ const MessageInput = () => {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
}, [selectedConversation?._id, socket, sendMessage]);
|
|
79
|
-
console.log('selected', selectedConversation);
|
|
80
79
|
|
|
81
80
|
useEffect(() => {
|
|
82
81
|
// Clear all input state when conversation changes
|
|
@@ -136,12 +135,10 @@ const MessageInput = () => {
|
|
|
136
135
|
const handleMessage = (event: MessageEvent) => {
|
|
137
136
|
try {
|
|
138
137
|
const data = JSON.parse(event.data);
|
|
139
|
-
console.log("Received WebSocket message:", data);
|
|
140
138
|
if (
|
|
141
139
|
data.event === "typing" &&
|
|
142
140
|
data.data.chatId === selectedConversation._id
|
|
143
141
|
) {
|
|
144
|
-
console.log("Setting typing user:", data.data.userId);
|
|
145
142
|
setTypingUser(data.data.userId);
|
|
146
143
|
} else if (
|
|
147
144
|
data.event === "stopTyping" &&
|
|
@@ -44,14 +44,13 @@ const Messages = () => {
|
|
|
44
44
|
const handleMessage = (event: MessageEvent) => {
|
|
45
45
|
try {
|
|
46
46
|
const parsed = JSON.parse(event.data);
|
|
47
|
-
console.log("Parsed WebSocket message1:", parsed);
|
|
48
47
|
if (parsed.type === "newMessage" || parsed.event === "newMessage") {
|
|
49
48
|
const newMessage = parsed.data;
|
|
50
49
|
if (!newMessage) {
|
|
51
|
-
console.warn(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
50
|
+
// console.warn(
|
|
51
|
+
// "Received newMessage event without a message payload",
|
|
52
|
+
// parsed
|
|
53
|
+
// );
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
|
|
@@ -74,7 +73,7 @@ const Messages = () => {
|
|
|
74
73
|
if (parsed.event === "messageStatusUpdated") {
|
|
75
74
|
const { messageId, status } = parsed.data || {};
|
|
76
75
|
if (!messageId) {
|
|
77
|
-
console.error("Missing messageId in status update", parsed);
|
|
76
|
+
// console.error("Missing messageId in status update", parsed);
|
|
78
77
|
return;
|
|
79
78
|
}
|
|
80
79
|
|
|
@@ -88,7 +87,7 @@ const Messages = () => {
|
|
|
88
87
|
return msg;
|
|
89
88
|
|
|
90
89
|
if (newIdx > currentIdx) {
|
|
91
|
-
console.log(`Updating status for ${messageId} to ${status}`);
|
|
90
|
+
// console.log(`Updating status for ${messageId} to ${status}`);
|
|
92
91
|
return { ...msg, status };
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -98,7 +97,7 @@ const Messages = () => {
|
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
if (parsed.event === "messageEdited") {
|
|
101
|
-
console.log("Received messageEdited event:", parsed);
|
|
100
|
+
// console.log("Received messageEdited event:", parsed);
|
|
102
101
|
|
|
103
102
|
const updatedMessage = parsed.data;
|
|
104
103
|
if (!updatedMessage || !updatedMessage.messageId) return;
|
|
@@ -113,7 +112,7 @@ const Messages = () => {
|
|
|
113
112
|
}
|
|
114
113
|
|
|
115
114
|
if (parsed.event === "messageDeleted") {
|
|
116
|
-
console.log("Received messageDeleted event:", parsed);
|
|
115
|
+
// console.log("Received messageDeleted event:", parsed);
|
|
117
116
|
|
|
118
117
|
const { messageId } = parsed.data || {};
|
|
119
118
|
if (!messageId) return;
|
|
@@ -21,14 +21,14 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
const handleSelectConversation = () => {
|
|
24
|
-
console.log(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
24
|
+
// console.log(
|
|
25
|
+
// "Selected Conversation Data:",
|
|
26
|
+
// JSON.stringify(conversation, null, 2)
|
|
27
|
+
// );
|
|
28
28
|
setSelectedConversation(conversation);
|
|
29
29
|
const unreadMessageIds = conversation.unreadMessageIds || [];
|
|
30
30
|
if (unreadMessageIds.length > 0 && socket?.readyState === WebSocket.OPEN) {
|
|
31
|
-
console.log("unread messages", unreadMessageIds);
|
|
31
|
+
// console.log("unread messages", unreadMessageIds);
|
|
32
32
|
|
|
33
33
|
const message = {
|
|
34
34
|
event: "messageRead",
|
|
@@ -64,9 +64,9 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
64
64
|
};
|
|
65
65
|
}, [socket, setOnlineUsers]);
|
|
66
66
|
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
|
|
69
|
-
}, [conversation]);
|
|
67
|
+
// useEffect(() => {
|
|
68
|
+
// // console.log("Current conversation state:", conversation);
|
|
69
|
+
// }, [conversation]);
|
|
70
70
|
|
|
71
71
|
const isOnline = isUserOnline(participant?._id || "");
|
|
72
72
|
const isSelected = selectedConversation?._id === conversation._id;
|
|
@@ -116,7 +116,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
|
|
|
116
116
|
</p>
|
|
117
117
|
<div className="flex items-center gap-2">
|
|
118
118
|
{unreadCount > 0 && (
|
|
119
|
-
|
|
119
|
+
<span className="background text-white text-xs rounded-full h-5 w-5 flex items-center justify-center">
|
|
120
120
|
{unreadCount}
|
|
121
121
|
</span>
|
|
122
122
|
)}
|
|
@@ -35,7 +35,7 @@ const Conversations = () => {
|
|
|
35
35
|
const allServiceChatsMap = new Map<string, GroupedServiceChats[string]>();
|
|
36
36
|
|
|
37
37
|
groups.forEach((group) => {
|
|
38
|
-
console.log("group", group.personalConversation);
|
|
38
|
+
// console.log("group", group.personalConversation);
|
|
39
39
|
|
|
40
40
|
if (group.personalConversation) {
|
|
41
41
|
allGeneralChats.push(group.personalConversation);
|
|
@@ -246,8 +246,8 @@ const Conversations = () => {
|
|
|
246
246
|
.filter(([_, group]) => group.conversations.length > 0) // Remove empty groups
|
|
247
247
|
);
|
|
248
248
|
|
|
249
|
-
console.log("filteredGeneralChats",filteredGeneralChats);
|
|
250
|
-
console.log("filteredGroupedServiceChats");
|
|
249
|
+
// console.log("filteredGeneralChats",filteredGeneralChats);
|
|
250
|
+
// console.log("filteredGroupedServiceChats");
|
|
251
251
|
|
|
252
252
|
return (
|
|
253
253
|
<div className="chatSidebarConversations">
|
package/src/declarations.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const useDeleteMessageMutation = () => {
|
|
|
8
8
|
return useMutation({
|
|
9
9
|
mutationFn: deleteMessage,
|
|
10
10
|
onSuccess: () => {
|
|
11
|
-
console.log("Message deleted successfully!", "success");
|
|
11
|
+
// console.log("Message deleted successfully!", "success");
|
|
12
12
|
// Invalidate both messages and conversations queries
|
|
13
13
|
queryClient.invalidateQueries({ queryKey: ['messages'] });
|
|
14
14
|
queryClient.invalidateQueries({ queryKey: ['conversations'] });
|
|
@@ -16,11 +16,11 @@ export const useDeleteMessageMutation = () => {
|
|
|
16
16
|
onError: (error: any) => {
|
|
17
17
|
console.error("Failed to delete message:", error);
|
|
18
18
|
|
|
19
|
-
const errorMessage =
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// const errorMessage =
|
|
20
|
+
// error?.response?.data?.errors[0]?.msg ||
|
|
21
|
+
// "An error occurred while deleting the message.";
|
|
22
22
|
|
|
23
|
-
console.log("useDeleteMessageMutation error:", errorMessage);
|
|
23
|
+
// console.log("useDeleteMessageMutation error:", errorMessage);
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
};
|
|
@@ -8,15 +8,15 @@ export const useEditMessageMutation = () => {
|
|
|
8
8
|
return useMutation({
|
|
9
9
|
mutationFn: setEditMessage,
|
|
10
10
|
onSuccess: () => {
|
|
11
|
-
console.log("Message edited successfully!", "success");
|
|
11
|
+
// console.log("Message edited successfully!", "success");
|
|
12
12
|
queryClient.invalidateQueries({ queryKey: ['messages'] });
|
|
13
13
|
},
|
|
14
14
|
onError: (error: any) => {
|
|
15
15
|
console.error("Failed to edit message:", error);
|
|
16
|
-
const errorMessage =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log("useMessageMutation edit error:", errorMessage);
|
|
16
|
+
// const errorMessage =
|
|
17
|
+
// error?.response?.data?.errors[0]?.msg ||
|
|
18
|
+
// "An error occurred while editing the message.";
|
|
19
|
+
// console.log("useMessageMutation edit error:", errorMessage);
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
|
|
@@ -7,17 +7,17 @@ export const useMessageMutation = () => {
|
|
|
7
7
|
return useMutation({
|
|
8
8
|
mutationFn: sendMessage,
|
|
9
9
|
onSuccess: () => {
|
|
10
|
-
console.log("Service submitted successfully!", "success");
|
|
10
|
+
// console.log("Service submitted successfully!", "success");
|
|
11
11
|
queryClient.invalidateQueries({ queryKey: ['messages'] });
|
|
12
12
|
},
|
|
13
13
|
onError: (error: any) => {
|
|
14
14
|
console.error("Failed to submit service data:", error);
|
|
15
15
|
|
|
16
|
-
const errorMessage =
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
// const errorMessage =
|
|
17
|
+
// error?.response?.data?.errors[0]?.msg ||
|
|
18
|
+
// "An error occurred while submitting service data.";
|
|
19
19
|
|
|
20
|
-
console.log("useSumbitServiceMutation :", errorMessage);
|
|
20
|
+
// console.log("useSumbitServiceMutation :", errorMessage);
|
|
21
21
|
},
|
|
22
22
|
});
|
|
23
23
|
};
|
|
@@ -41,19 +41,19 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
41
41
|
const reconnectAttempts = useRef(0);
|
|
42
42
|
const maxReconnectAttempts = 5;
|
|
43
43
|
const reconnectInterval = 5000; // 5 seconds
|
|
44
|
-
const {
|
|
44
|
+
const { webSocketUrl } = getChatConfig();
|
|
45
45
|
|
|
46
46
|
const connectWebSocket = useCallback(() => {
|
|
47
|
-
console.log("🔌 Creating new WebSocket connection...");
|
|
47
|
+
// console.log("🔌 Creating new WebSocket connection...");
|
|
48
48
|
|
|
49
49
|
// Convert HTTP URL to WebSocket URL
|
|
50
|
-
const wsUrl =
|
|
50
|
+
const wsUrl = webSocketUrl.replace(/^http:/, "ws:").replace(/^https:/, "wss:");
|
|
51
51
|
const socketInstance = new WebSocket(
|
|
52
52
|
`${wsUrl}?userId=${encodeURIComponent(userId)}`
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
socketInstance.onopen = () => {
|
|
56
|
-
console.log("✅ WebSocket connected");
|
|
56
|
+
// console.log("✅ WebSocket connected");
|
|
57
57
|
setIsConnected(true);
|
|
58
58
|
reconnectAttempts.current = 0;
|
|
59
59
|
|
|
@@ -71,12 +71,12 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
71
71
|
const data = JSON.parse(event.data);
|
|
72
72
|
|
|
73
73
|
if (data.event === "getOnlineUsers") {
|
|
74
|
-
console.log("Online users update:", data.data);
|
|
74
|
+
// console.log("Online users update:", data.data);
|
|
75
75
|
setOnlineUsers(new Set(data.data));
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// Handle other message types here
|
|
79
|
-
console.log("Received message:", data);
|
|
79
|
+
// console.log("Received message:", data);
|
|
80
80
|
} catch (error) {
|
|
81
81
|
console.error("Error parsing message:", error);
|
|
82
82
|
}
|
|
@@ -86,24 +86,24 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
86
86
|
console.error("❌ WebSocket error:", error);
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
socketInstance.onclose = (
|
|
90
|
-
console.log("🔌 WebSocket connection closed", event);
|
|
91
|
-
console.log("❌ WebSocket disconnected:", event.code, event.reason);
|
|
89
|
+
socketInstance.onclose = () => {
|
|
90
|
+
// console.log("🔌 WebSocket connection closed", event);
|
|
91
|
+
// console.log("❌ WebSocket disconnected:", event.code, event.reason);
|
|
92
92
|
setIsConnected(false);
|
|
93
93
|
|
|
94
94
|
// Attempt reconnection
|
|
95
95
|
if (reconnectAttempts.current < maxReconnectAttempts) {
|
|
96
96
|
reconnectAttempts.current += 1;
|
|
97
|
-
console.log(
|
|
98
|
-
|
|
99
|
-
);
|
|
97
|
+
// console.log(
|
|
98
|
+
// `Attempting to reconnect (${reconnectAttempts.current}/${maxReconnectAttempts})...`
|
|
99
|
+
// );
|
|
100
100
|
setTimeout(connectWebSocket, reconnectInterval);
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
socketRef.current = socketInstance;
|
|
105
105
|
setSocket(socketInstance);
|
|
106
|
-
}, [
|
|
106
|
+
}, [webSocketUrl, userId]);
|
|
107
107
|
|
|
108
108
|
const sendMessage = useCallback((data: any) => {
|
|
109
109
|
if (socketRef.current?.readyState === WebSocket.OPEN) {
|
|
@@ -117,7 +117,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
|
|
|
117
117
|
connectWebSocket();
|
|
118
118
|
|
|
119
119
|
return () => {
|
|
120
|
-
console.log("❌ Closing WebSocket connection...");
|
|
120
|
+
// console.log("❌ Closing WebSocket connection...");
|
|
121
121
|
if (socketRef.current) {
|
|
122
122
|
socketRef.current.close(1000, "Component unmounted");
|
|
123
123
|
socketRef.current = null;
|
|
@@ -47,7 +47,7 @@ export const fetchMessages = async (chatId: string | undefined, userid: string,
|
|
|
47
47
|
const response = await apiClient.get(`${Path.getmessage}/${chatId}/${userid}`, {
|
|
48
48
|
params: { pagenum, limit: 20 },
|
|
49
49
|
});
|
|
50
|
-
console.log(response);
|
|
50
|
+
// console.log(response);
|
|
51
51
|
return response.data;
|
|
52
52
|
} catch (error) {
|
|
53
53
|
console.error("Error fetching messages:", error);
|
|
@@ -16,11 +16,11 @@ export const getAllConversationData = async (userid: string) => {
|
|
|
16
16
|
|
|
17
17
|
const res = await apiClient.get<ApiResponse>(endpoint);
|
|
18
18
|
if (res.data) {
|
|
19
|
-
console.log("API Response: ", res.data);
|
|
19
|
+
// console.log("API Response: ", res.data);
|
|
20
20
|
|
|
21
21
|
}
|
|
22
22
|
const conversationsWithParticipantDetails = res.data.serviceInfo;
|
|
23
|
-
console.log("conversationsWithParticipantDetails", res.data.serviceInfo);
|
|
23
|
+
// console.log("conversationsWithParticipantDetails", res.data.serviceInfo);
|
|
24
24
|
|
|
25
25
|
// If needed, you can map the conversations in the specific structure
|
|
26
26
|
// const formattedConversations = conversationsWithParticipantDetails?.map((conversation) => ({
|
package/src/style/style.css
CHANGED
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
/* background-color: #9CA3AF; */
|
|
10
10
|
--bg-opacity: 0;
|
|
11
11
|
backdrop-blur: blur(16px);
|
|
12
|
+
|
|
13
|
+
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
.sidebarContainer {
|
|
15
17
|
/* grid-column: span 3; */
|
|
16
18
|
/* overflow-y: auto; */
|
|
17
|
-
border: 1px solid #ddd;
|
|
19
|
+
/* border: 1px solid #ddd; */
|
|
18
20
|
max-height: 100vh;
|
|
19
21
|
}
|
|
20
22
|
|
|
@@ -23,6 +25,29 @@
|
|
|
23
25
|
/* border: 1px solid; */
|
|
24
26
|
max-height: 100vh;
|
|
25
27
|
overflow-y: auto;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.sidebarContainer,
|
|
32
|
+
.messageContainer {
|
|
33
|
+
height: 100%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.hide-on-mobile {
|
|
37
|
+
display: none;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.show {
|
|
41
|
+
display: block;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Back button visible only on mobile */
|
|
45
|
+
.back-button {
|
|
46
|
+
display: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.background {
|
|
50
|
+
background-color: #317490;
|
|
26
51
|
}
|
|
27
52
|
|
|
28
53
|
.chatSidebarMain {
|
|
@@ -58,7 +83,7 @@
|
|
|
58
83
|
justify-content: flex-start;
|
|
59
84
|
align-items: center;
|
|
60
85
|
height: 2.5rem;
|
|
61
|
-
background-color:
|
|
86
|
+
background-color: #FEFEFF;
|
|
62
87
|
/* Move bg color here */
|
|
63
88
|
}
|
|
64
89
|
|
|
@@ -167,6 +192,7 @@
|
|
|
167
192
|
flex-direction: column;
|
|
168
193
|
justify-content: center;
|
|
169
194
|
height: 100%;
|
|
195
|
+
background-color: #FEFEFF;
|
|
170
196
|
}
|
|
171
197
|
|
|
172
198
|
.chatMessageContainerInner {
|
|
@@ -379,7 +405,7 @@
|
|
|
379
405
|
}
|
|
380
406
|
|
|
381
407
|
.chatMessageInputSubmit {
|
|
382
|
-
background-color: #
|
|
408
|
+
background-color: #317490;
|
|
383
409
|
border: none;
|
|
384
410
|
width: 40px;
|
|
385
411
|
height: 40px;
|
|
@@ -412,6 +438,8 @@
|
|
|
412
438
|
width: 100%;
|
|
413
439
|
font-family: Arial, sans-serif;
|
|
414
440
|
margin-bottom: 8px;
|
|
441
|
+
margin: 0 auto;
|
|
442
|
+
max-width: 1200px;
|
|
415
443
|
}
|
|
416
444
|
|
|
417
445
|
.message-row {
|
|
@@ -468,14 +496,14 @@
|
|
|
468
496
|
}
|
|
469
497
|
|
|
470
498
|
.outgoing .chat-bubble {
|
|
471
|
-
background-color: #
|
|
472
|
-
color: #
|
|
499
|
+
background-color: #317490;
|
|
500
|
+
color: #DDE8ED;
|
|
473
501
|
|
|
474
502
|
}
|
|
475
503
|
|
|
476
504
|
.incoming .chat-bubble {
|
|
477
|
-
background-color: #
|
|
478
|
-
color: #
|
|
505
|
+
background-color: #F4F3F6;
|
|
506
|
+
color: #476179;
|
|
479
507
|
}
|
|
480
508
|
|
|
481
509
|
.timestamp_incomeing {
|
|
@@ -551,15 +579,15 @@
|
|
|
551
579
|
.sidebarContainer {
|
|
552
580
|
/* display: grid; */
|
|
553
581
|
grid-column: span 3;
|
|
554
|
-
background-color:
|
|
555
|
-
border-radius:
|
|
582
|
+
background-color: #FEFEFF;
|
|
583
|
+
border-radius: 2%;
|
|
556
584
|
}
|
|
557
585
|
|
|
558
586
|
.messageContainer {
|
|
559
587
|
display: grid;
|
|
560
588
|
grid-column: span 6;
|
|
561
|
-
border: 1px solid #ddd;
|
|
562
|
-
border-radius:
|
|
589
|
+
/* border: 1px solid #ddd; */
|
|
590
|
+
border-radius: 3%;
|
|
563
591
|
}
|
|
564
592
|
|
|
565
593
|
.chatMessageContainerInnerDiv_button {
|
|
@@ -1905,4 +1933,159 @@
|
|
|
1905
1933
|
|
|
1906
1934
|
.message-option-btn.disabled:hover::before {
|
|
1907
1935
|
background: #666;
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
.backButton {
|
|
1939
|
+
display: none;
|
|
1940
|
+
align-items: center;
|
|
1941
|
+
gap: 4px;
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
|
|
1945
|
+
@media (max-width: 768px) {
|
|
1946
|
+
.grid-container {
|
|
1947
|
+
display: flex;
|
|
1948
|
+
flex-direction: column;
|
|
1949
|
+
width: 100%;
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
.sidebarContainer {
|
|
1953
|
+
max-height: auto;
|
|
1954
|
+
order: 1;
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
.messageContainer {
|
|
1958
|
+
max-height: auto;
|
|
1959
|
+
order: 2;
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
.chatSidebarSearchbar {
|
|
1963
|
+
padding: 1rem;
|
|
1964
|
+
flex-wrap: wrap;
|
|
1965
|
+
height: auto;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
.chatMessagesBubble_inner {
|
|
1969
|
+
max-width: 70%; /* allow wider bubbles on small screens */
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
/* Mobile Layout (≤ 480px) */
|
|
1974
|
+
@media (max-width: 480px) {
|
|
1975
|
+
.grid-container {
|
|
1976
|
+
flex-direction: column;
|
|
1977
|
+
width: 100%;
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
.chatSidebarMain {
|
|
1981
|
+
flex-direction: column;
|
|
1982
|
+
padding: 0.5rem;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
.chatSidebarSearchbarContainer {
|
|
1986
|
+
padding: 0.5rem;
|
|
1987
|
+
font-size: 0.9rem;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
.chatMessageContainerInner {
|
|
1991
|
+
padding: 1rem;
|
|
1992
|
+
font-size: 0.8rem;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
.chatMessagesBubble_inner {
|
|
1996
|
+
max-width: 85%;
|
|
1997
|
+
font-size: 13px;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
.chatMessageInput {
|
|
2001
|
+
font-size: 0.9rem;
|
|
2002
|
+
padding: 6px 4px;
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
.chatMessageInputSubmit {
|
|
2006
|
+
width: 35px;
|
|
2007
|
+
height: 35px;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
.chat-bubble {
|
|
2011
|
+
font-size: 13px;
|
|
2012
|
+
max-width: 90%;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
.timestamp_incomeing,
|
|
2016
|
+
.timestamp_outgoing {
|
|
2017
|
+
font-size: 10px;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
.attachments-preview {
|
|
2021
|
+
width: 100%;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
/* Mobile styles */
|
|
2027
|
+
@media (max-width: 768px) {
|
|
2028
|
+
.grid-container {
|
|
2029
|
+
display: block;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
.chatMessageContainer {
|
|
2033
|
+
display: flex;
|
|
2034
|
+
flex-direction: column;
|
|
2035
|
+
justify-content: center;
|
|
2036
|
+
height: 100%;
|
|
2037
|
+
background-color: #FEFEFF;
|
|
2038
|
+
width: 100%;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
.sidebarContainer,
|
|
2042
|
+
.messageContainer {
|
|
2043
|
+
width: 100%;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
.back-button {
|
|
2047
|
+
display: block;
|
|
2048
|
+
}
|
|
2049
|
+
.messageContainer.active {
|
|
2050
|
+
display: block;
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
.sidebarContainer.hidden {
|
|
2054
|
+
display: none;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
.backButton {
|
|
2058
|
+
display: inline-block;
|
|
2059
|
+
margin-right: 10px;
|
|
2060
|
+
background: none;
|
|
2061
|
+
border: none;
|
|
2062
|
+
font-size: 14px;
|
|
2063
|
+
cursor: pointer;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
.mobile-hidden {
|
|
2067
|
+
display: none !important;
|
|
2068
|
+
}
|
|
2069
|
+
.mobile-visible {
|
|
2070
|
+
display: block !important;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
.chatMessageInputform{
|
|
2074
|
+
padding-left: 0rem;
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
.message-input-container{
|
|
2078
|
+
padding: 0px;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
.media-item{
|
|
2082
|
+
width: 100%;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
.chatMessageInputSubmit {
|
|
2086
|
+
/* width: 25px; */
|
|
2087
|
+
height: 35px;
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
|
|
1908
2091
|
}
|