@pubuduth-aplicy/chat-ui 2.1.9 → 2.1.11

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.9",
3
+ "version": "2.1.11",
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": "",
@@ -6,7 +6,7 @@ import useChatUIStore from '../../stores/Zustant';
6
6
  // import useSendMessage from '../../hooks/useSendMessage'; // Importing the useSendMessage hook
7
7
 
8
8
  const MessageInput = () => {
9
- const { socket, userId } = useChatContext();
9
+ const { socket } = useChatContext();
10
10
  const { selectedConversation } = useChatUIStore();
11
11
  const [message, setMessage] = useState(""); // State for storing the message input
12
12
  const { mutate: sendMessage } = useMessageMutation();
@@ -5,12 +5,16 @@ import { useEffect, useRef } from "react";
5
5
  import Message from "./Message";
6
6
  import { useChatContext } from "../../providers/ChatProvider";
7
7
  import { useMessages } from "../../hooks/queries/useChatApi";
8
+ import useChatUIStore from "../../stores/Zustant";
8
9
  // import useListenMessages from "../../hooks/useListenMessages";
9
10
 
10
11
  const Messages = () => {
11
- const { userId } = useChatContext();
12
- const { data: messages } = useMessages(userId);
12
+ const { selectedConversation } = useChatUIStore()
13
+ const {userId}=useChatContext()
14
+ const { data: messages } = useMessages(selectedConversation?._id,userId);
13
15
  // useListenMessages();
16
+ console.log(messages);
17
+
14
18
  const lastMessageRef = useRef<HTMLDivElement>(null);
15
19
 
16
20
  useEffect(() => {
@@ -35,19 +39,19 @@ const Messages = () => {
35
39
  // )}
36
40
  // </div>
37
41
 
38
- <div className='px-4 flex-1 overflow-auto sm:px-6 lg:px-8'>
39
- {messages.length > 0 &&
40
- messages.map((message:any) => (
41
- <div key={message._id} ref={lastMessageRef}>
42
- <Message message={message} />
43
- </div>
44
- ))}
45
-
46
- {/* {loading && [...Array(3)].map((_, idx) => <MessageSkeleton key={idx} />)} */}
47
- {messages.length === 0 && (
48
- <p className='text-center'>Send a message to start the conversation</p>
49
- )}
50
- </div>
42
+ <div className='px-4 flex-1 overflow-auto sm:px-6 lg:px-8'>
43
+ {messages.length > 0 &&
44
+ messages.map((message: any) => (
45
+ <div key={message._id} ref={lastMessageRef}>
46
+ <Message message={message} />
47
+ </div>
48
+ ))}
49
+
50
+ {/* {loading && [...Array(3)].map((_, idx) => <MessageSkeleton key={idx} />)} */}
51
+ {messages.length === 0 && (
52
+ <p className='text-center'>Send a message to start the conversation</p>
53
+ )}
54
+ </div>
51
55
  );
52
56
  };
53
57
  export default Messages;
@@ -5,9 +5,14 @@ import useChatUIStore from "../../stores/Zustant";
5
5
 
6
6
  interface ConversationProps {
7
7
  conversation: {
8
- _id: string;
8
+ participantDetails:{
9
+ _id: string;
9
10
  profilePic: string;
10
- username: string;
11
+ firstname: string;
12
+ idpic:string;
13
+
14
+ }
15
+ _id:string;
11
16
  };
12
17
  lastIdx: boolean;
13
18
  }
@@ -28,12 +33,12 @@ console.log(conversation);
28
33
  >
29
34
  <img
30
35
  className="w-12 h-12 relative rounded-[100px]"
31
- src={conversation.profilePic|| conversation.idpic}
36
+ src={conversation.participantDetails.profilePic|| conversation.participantDetails.idpic}
32
37
  />
33
38
  <div className="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex">
34
39
  <div className="self-stretch justify-start items-center inline-flex">
35
40
  <div className="grow shrink basis-0 text-slate-900 text-base font-semibold font-['Inter'] leading-tight">
36
- {conversation.firstname}
41
+ {conversation.participantDetails.firstname}
37
42
  </div>
38
43
  </div>
39
44
  </div>
@@ -15,8 +15,8 @@ export const useGetConversations = (id: any) => {
15
15
  });
16
16
  };
17
17
 
18
- export const useMessages = (chatId: string) => {
18
+ export const useMessages = (chatId: string,userid:string) => {
19
19
  return useQuery({
20
- queryKey:['messages', chatId],
21
- queryFn: () => fetchMessages(chatId)});
20
+ queryKey:['messages', chatId,userid],
21
+ queryFn: () => fetchMessages(chatId,userid)});
22
22
  };
@@ -10,7 +10,7 @@ export const sendMessage = async ({ chatId, message }: { chatId: any; message: s
10
10
  };
11
11
 
12
12
 
13
- export const fetchMessages = async (chatId: string) => {
14
- const response = await apiClient.get(`${Path.getconversation}/${chatId}`);
13
+ export const fetchMessages = async (chatId: string,userid:string) => {
14
+ const response = await apiClient.get(`${Path.getmessage}/${chatId}/${userid}`);
15
15
  return response.data();
16
16
  };
@@ -12,9 +12,13 @@ interface ChatUIState {
12
12
  isChatOpen: boolean;
13
13
  unreadCount: number;
14
14
  selectedConversation: {
15
- _id: string;
15
+ participantDetails:{
16
+ _id: string;
16
17
  profilePic: string;
17
- username: string;
18
+ firstname: string;
19
+ idpic:string;
20
+ }
21
+ _id:string;
18
22
  } | null;
19
23
  setSelectedConversation: (selectedConversation: { _id: string; profilePic: string; username: string; } | null) => void;
20
24
  toggleChat: () => void;