@pubuduth-aplicy/chat-ui 2.1.43 → 2.1.44

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubuduth-aplicy/chat-ui",
3
- "version": "2.1.43",
3
+ "version": "2.1.44",
4
4
  "description": "This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -0,0 +1,18 @@
1
+ // config.ts
2
+ export interface ChatConfig {
3
+ apiUrl: string;
4
+ }
5
+
6
+ let chatConfig: ChatConfig;
7
+
8
+ export function initChatConfig(config: ChatConfig) {
9
+ chatConfig = config;
10
+ }
11
+
12
+ export function getChatConfig() {
13
+ if (!chatConfig) {
14
+ throw new Error("Chat config not initialized. Call initChatConfig first.");
15
+ }
16
+ return chatConfig;
17
+ }
18
+
@@ -7,40 +7,42 @@ import useChatUIStore from "../../stores/Zustant";
7
7
  import { ConversationProps } from "../../types/type";
8
8
 
9
9
  const Conversation = ({ conversation, lastIdx }: ConversationProps) => {
10
- const { setSelectedConversation, setOnlineUsers,onlineUsers } = useChatUIStore();
10
+ const { setSelectedConversation, setOnlineUsers, onlineUsers } =
11
+ useChatUIStore();
11
12
  const { socket } = useChatContext();
12
- console.log(conversation);
13
+ console.log(conversation);
13
14
 
14
- const handleSelectConversation = async () => {
15
- setSelectedConversation(conversation);
15
+ const handleSelectConversation = async () => {
16
+ setSelectedConversation(conversation);
16
17
 
17
- const unreadMessages = conversation.unreadMessageIds || []; // Get all unread message IDs
18
+ const unreadMessages = conversation.unreadMessageIds || []; // Get all unread message IDs
18
19
 
19
- if (unreadMessages.length > 0) {
20
- console.log("Emitting messageRead for messages:", unreadMessages);
20
+ if (unreadMessages.length > 0) {
21
+ console.log("Emitting messageRead for messages:", unreadMessages);
21
22
 
22
- socket.emit("messageRead", {
23
- messageIds: unreadMessages, // Send all unread message IDs
24
- receiverId: conversation.participantDetails._id,
25
- });
26
- }
27
- };
23
+ socket.emit("messageRead", {
24
+ messageIds: unreadMessages, // Send all unread message IDs
25
+ receiverId: conversation.participantDetails._id,
26
+ });
27
+ }
28
+ };
28
29
 
29
- useEffect(() => {
30
- if (!socket) return;
30
+ useEffect(() => {
31
+ if (!socket) return;
31
32
 
32
- const handleOnlineUsers = (users: string[]) => {
33
- setOnlineUsers(users);
34
- };
33
+ const handleOnlineUsers = (users: string[]) => {
34
+ setOnlineUsers(users);
35
+ };
35
36
 
36
- socket.on("getOnlineUsers", handleOnlineUsers);
37
+ socket.on("getOnlineUsers", handleOnlineUsers);
37
38
 
38
- return () => {
39
- socket.off("getOnlineUsers", handleOnlineUsers);
40
- };
41
- }, [socket, setOnlineUsers]);
39
+ return () => {
40
+ socket.off("getOnlineUsers", handleOnlineUsers);
41
+ };
42
+ }, [socket, setOnlineUsers]);
42
43
 
43
- const isUserOnline = conversation?.participantDetails?._id &&
44
+ const isUserOnline =
45
+ conversation?.participantDetails?._id &&
44
46
  onlineUsers?.includes(conversation.participantDetails._id);
45
47
  return (
46
48
  <>
@@ -51,23 +53,29 @@ const handleSelectConversation = async () => {
51
53
  >
52
54
  <img
53
55
  className="chatSidebarConversationImg"
54
- src={conversation.participantDetails?.profilePic|| conversation.participantDetails?.idpic}
56
+ src={
57
+ conversation.participantDetails?.profilePic ||
58
+ conversation.participantDetails?.idpic
59
+ }
55
60
  />
56
- <p className="text-sm text-[#12bbb5]">
57
- {isUserOnline ? "Online" : "Offline"}
58
- </p>
61
+ <p className="text-sm text-[#12bbb5]">
62
+ {isUserOnline ? "Online" : "Offline"}
63
+ </p>
59
64
  <div className="chatSidebarConversationContainer">
60
65
  {/* <div className="chatSidebarConversationInnerDiv"> */}
61
- <p className="text-sm text-gray-500">
62
- {conversation.participantDetails?.firstname}
63
- </p>
64
- <p className="chatSidebarConversationOuterDiv">
65
- {conversation.lastMessage.message}
66
- </p>
66
+ <p className="text-sm text-gray-500">
67
+ {conversation.participantDetails?.firstname}
68
+ </p>
69
+ <p className="chatSidebarConversationOuterDiv">
70
+ {conversation.lastMessage.message}
71
+ </p>
67
72
  {/* </div> */}
68
73
  </div>
69
74
  <span className="text-xs text-gray-500">
70
- {new Date(conversation.lastMessage.createdAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
75
+ {new Date(conversation.lastMessage.createdAt).toLocaleTimeString([], {
76
+ hour: "2-digit",
77
+ minute: "2-digit",
78
+ })}
71
79
  </span>
72
80
  </div>
73
81
 
@@ -1,7 +1,9 @@
1
1
  import axios from "axios";
2
+ import { getChatConfig } from "../../Chat.config";
2
3
 
4
+ const { apiUrl } = getChatConfig();
3
5
  export const apiClient = axios.create({
4
- baseURL: import.meta.env.VITE_APP_BACKEND_PORT,
6
+ baseURL: apiUrl,
5
7
  timeout: 5000,
6
8
  withCredentials:true,
7
9
  headers: {
@@ -8,6 +8,7 @@ import React, {
8
8
  useRef,
9
9
  } from "react";
10
10
  import { Socket, io } from "socket.io-client";
11
+ import { getChatConfig } from "../Chat.config";
11
12
  // import { apiClient } from '../lib/api/apiClient';
12
13
  // import { S3Client } from '../lib/storage/s3Client';
13
14
  // import { CryptoUtils } from '../lib/encryption/cryptoUtils';
@@ -20,7 +21,7 @@ interface ChatProviderProps {
20
21
  // accessKeyId: string;
21
22
  // secretAccessKey: string;
22
23
  // };
23
- userId: string; // User ID for identification
24
+ userId: string;
24
25
  children: ReactNode;
25
26
  }
26
27
 
@@ -41,13 +42,14 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
41
42
  const socketRef = useRef<Socket | null>(null);
42
43
  const [socket, setSocket] = useState<Socket | null>(null);
43
44
  const [onlineUsers, setOnlineUsers] = useState([]);
44
- const apiUrl = import.meta.env.VITE_APP_BACKEND_PORT;
45
+ const { apiUrl } = getChatConfig();
46
+ // const apiUrl = import.meta.env.VITE_APP_BACKEND_PORT;
45
47
  console.log("API URL:", apiUrl);
46
48
 
47
49
  useEffect(() => {
48
50
  if (!socketRef.current) {
49
51
  console.log("🔌 Creating new socket connection...");
50
- const socketInstance = io('http://localhost:3001', {
52
+ const socketInstance = io(apiUrl, {
51
53
  query: {
52
54
  userId: userId,
53
55
  },