@pubuduth-aplicy/chat-ui 2.0.6 → 2.0.8

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.0.6",
3
+ "version": "2.0.8",
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": "",
@@ -1,25 +1,28 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
 
3
3
  import { useGetConversations } from "../../hooks/queries/useChatApi";
4
+ import { useChatContext } from "../../providers/ChatProvider";
4
5
  import Conversation from "./Conversation";
5
6
 
6
7
  const Conversations = () => {
7
- const { data: conversations } = useGetConversations();
8
-
9
- // const { loading, conversations } = useGetConversations();
8
+ const { userId } = useChatContext();
9
+ const { data: conversations } = useGetConversations(userId);
10
+ console.log("conversations",conversations);
11
+ console.log("userId",userId);
12
+ // const { loading, conversations } = useGetConversations();
10
13
  return (
11
- <div className='py-2 flex flex-col overflow-auto'>
12
- {conversations?.map((conversation:any, idx:any) => (
13
- <Conversation
14
- key={conversation._id}
15
- conversation={conversation}
16
- lastIdx={idx === conversations.length - 1}
17
- />
18
- ))}
14
+ <div className="py-2 flex flex-col overflow-auto">
15
+ {conversations?.map((conversation: any, idx: any) => (
16
+ <Conversation
17
+ key={conversation._id}
18
+ conversation={conversation}
19
+ lastIdx={idx === conversations.length - 1}
20
+ />
21
+ ))}
19
22
 
20
- {/* {loading ? <span className='loading loading-spinner mx-auto'></span> : null} */}
21
- </div>
22
- )
23
- }
23
+ {/* {loading ? <span className='loading loading-spinner mx-auto'></span> : null} */}
24
+ </div>
25
+ );
26
+ };
24
27
 
25
- export default Conversations
28
+ export default Conversations;
@@ -3,16 +3,17 @@ import { useState } from 'react'
3
3
  import searchicon from '../../assets/icons8-search.svg'
4
4
  import useChatUIStore from '../../stores/Zustant';
5
5
  import { useGetConversations } from '../../hooks/queries/useChatApi';
6
+ import { useChatContext } from '../../providers/ChatProvider';
6
7
  // import { MagnifyingGlass } from "@phosphor-icons/react"
7
8
  // import useGetConversations from "../../hooks/useGetConversations";
8
9
  // import useConversation from '../../zustand/useConversation'
9
10
  // import toast from 'react-hot-toast';
10
11
 
11
12
  const SearchInput = () => {
12
-
13
+ const {userId} =useChatContext()
13
14
  const [search, setSearch] = useState("");
14
15
  const { setSelectedConversation } = useChatUIStore();
15
- const { data: conversations } = useGetConversations();
16
+ const { data } = useGetConversations(userId);
16
17
 
17
18
  const handleSubmit = (e:any) => {
18
19
  e.preventDefault();
@@ -21,7 +22,7 @@ const SearchInput = () => {
21
22
  return
22
23
  }
23
24
 
24
- const conversation = conversations.find((c: { username: string }) => c.username.toLowerCase().includes(search.toLowerCase()));
25
+ const conversation = data.find((c: { username: string }) => c.username.toLowerCase().includes(search.toLowerCase()));
25
26
 
26
27
  if (conversation) {
27
28
  setSelectedConversation(conversation);
@@ -1,12 +1,15 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { useQuery } from "@tanstack/react-query";
2
3
  import { getAllConversationData } from "../../service/sidebarApi";
3
4
 
4
5
 
5
- export const useGetConversations = () => {
6
+ export const useGetConversations = (id:any) => {
6
7
  return useQuery({
7
- queryKey: ['GET_ALL_CONVERSATION'],
8
- queryFn: getAllConversationData,
8
+ queryKey: ['GET_ALL_CONVERSATION',id],
9
+ queryFn: () =>
10
+ id ? getAllConversationData(id) : Promise.reject("No ID provided"),
9
11
  staleTime: 1 * 60 * 1000,
12
+ enabled: !!id,
10
13
  refetchOnWindowFocus: false,
11
14
  });
12
15
  };
@@ -2,9 +2,10 @@
2
2
  import { apiClient } from "../lib/api/apiClient";
3
3
  import { Path } from "../lib/api/endpoint";
4
4
 
5
- export const getAllConversationData = async () => {
5
+
6
+ export const getAllConversationData = async (userid: string) => {
6
7
  try {
7
- const res = await apiClient.get(Path.getconversation);
8
+ const res = await apiClient.get(`${Path.getconversation}/${userid}`);
8
9
  return res.data;
9
10
  } catch (error: any) {
10
11
  console.log("ERROR: ", error);