@pubuduth-aplicy/chat-ui 2.0.5 → 2.0.7
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,15 +1,17 @@
|
|
|
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
|
-
|
|
8
|
+
const {userId}= useChatContext()
|
|
9
|
+
const { data: conversations } = useGetConversations(userId);
|
|
8
10
|
|
|
9
11
|
// const { loading, conversations } = useGetConversations();
|
|
10
12
|
return (
|
|
11
13
|
<div className='py-2 flex flex-col overflow-auto'>
|
|
12
|
-
{conversations
|
|
14
|
+
{conversations?.map((conversation:any, idx:any) => (
|
|
13
15
|
<Conversation
|
|
14
16
|
key={conversation._id}
|
|
15
17
|
conversation={conversation}
|
|
@@ -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
|
|
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 =
|
|
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:
|
|
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
|
-
|
|
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);
|