@droppii-org/chat-sdk 0.0.5 → 0.0.6
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/dist/assets/droppiiFontSelection.json +14521 -0
- package/dist/components/ChatBubble.d.ts +10 -0
- package/dist/components/ChatBubble.d.ts.map +1 -0
- package/dist/components/ChatBubble.js +26 -0
- package/dist/components/chat-bubble/ChatBubble.d.ts +9 -0
- package/dist/components/chat-bubble/ChatBubble.d.ts.map +1 -0
- package/dist/components/chat-bubble/ChatBubble.js +27 -0
- package/dist/components/conversation/DeskConversationList.d.ts +8 -0
- package/dist/components/conversation/DeskConversationList.d.ts.map +1 -0
- package/dist/components/conversation/DeskConversationList.js +168 -0
- package/dist/components/icon/index.d.ts +11 -0
- package/dist/components/icon/index.d.ts.map +1 -0
- package/dist/components/icon/index.js +18 -0
- package/dist/components/message/MessageList.d.ts +10 -0
- package/dist/components/message/MessageList.d.ts.map +1 -0
- package/dist/components/message/MessageList.js +91 -0
- package/dist/components/session/AssignedSessionFilter.d.ts +7 -0
- package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -0
- package/dist/components/session/AssignedSessionFilter.js +90 -0
- package/dist/context/ChatContext.d.ts +5 -0
- package/dist/context/ChatContext.d.ts.map +1 -0
- package/dist/context/ChatContext.js +36 -0
- package/dist/hooks/conversation/useConversation.d.ts +11 -0
- package/dist/hooks/conversation/useConversation.d.ts.map +1 -0
- package/dist/hooks/conversation/useConversation.js +51 -0
- package/dist/hooks/message/useMessage.d.ts +9 -0
- package/dist/hooks/message/useMessage.d.ts.map +1 -0
- package/dist/hooks/message/useMessage.js +46 -0
- package/dist/hooks/message/useSendMessage.d.ts +10 -0
- package/dist/hooks/message/useSendMessage.d.ts.map +1 -0
- package/dist/hooks/message/useSendMessage.js +42 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/screens/desk-message/index.d.ts +3 -0
- package/dist/screens/desk-message/index.d.ts.map +1 -0
- package/dist/screens/desk-message/index.js +14 -0
- package/dist/types/chat.d.ts +9 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/sdk.d.ts +1 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +1 -0
- package/package.json +11 -2
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SessionType } from "@openim/wasm-client-sdk";
|
|
2
|
+
interface ChatBubbleProps {
|
|
3
|
+
conversationId: string;
|
|
4
|
+
sourceID: string;
|
|
5
|
+
sessionType: SessionType;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const ChatBubble: ({ conversationId, sourceID, sessionType, className, }: ChatBubbleProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default ChatBubble;
|
|
10
|
+
//# sourceMappingURL=ChatBubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatBubble.d.ts","sourceRoot":"","sources":["../../src/components/ChatBubble.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,UAAU,eAAe;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,UAAU,GAAI,uDAKjB,eAAe,4CAgDjB,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { FloatButton, Drawer } from "antd";
|
|
5
|
+
import { MessageOutlined, CloseOutlined } from "@ant-design/icons";
|
|
6
|
+
import MessageList from "./message/MessageList";
|
|
7
|
+
import { useConversationDetail } from "src/hooks/conversation/useConversation";
|
|
8
|
+
const ChatBubble = ({ conversationId, sourceID, sessionType, className, }) => {
|
|
9
|
+
const { conversationDetail } = useConversationDetail({
|
|
10
|
+
sourceID,
|
|
11
|
+
sessionType,
|
|
12
|
+
});
|
|
13
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
+
const toggleChat = () => {
|
|
15
|
+
setIsOpen(!isOpen);
|
|
16
|
+
};
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx(FloatButton, { icon: isOpen ? _jsx(CloseOutlined, {}) : _jsx(MessageOutlined, {}), type: "primary", style: {
|
|
18
|
+
right: 24,
|
|
19
|
+
bottom: 24,
|
|
20
|
+
width: 60,
|
|
21
|
+
height: 60,
|
|
22
|
+
}, onClick: toggleChat, className: className }), _jsx(Drawer, { placement: "right", onClose: () => setIsOpen(false), open: isOpen, mask: true, closable: false, styles: {
|
|
23
|
+
body: { padding: 0 },
|
|
24
|
+
}, children: _jsx(MessageList, { conversationId: conversationId, conversationData: conversationDetail, className: "flex-1", onClose: () => setIsOpen(false) }) })] }));
|
|
25
|
+
};
|
|
26
|
+
export default ChatBubble;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConversationItem } from "@openim/wasm-client-sdk";
|
|
2
|
+
interface ChatBubbleProps {
|
|
3
|
+
conversationId: string;
|
|
4
|
+
conversationData: ConversationItem | null;
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const ChatBubble: ({ conversationId, conversationData, className }: ChatBubbleProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default ChatBubble;
|
|
9
|
+
//# sourceMappingURL=ChatBubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatBubble.d.ts","sourceRoot":"","sources":["../../../src/components/chat-bubble/ChatBubble.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,UAAU,eAAe;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,UAAU,GAAI,iDAAiD,eAAe,4CAkDnF,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { FloatButton, Drawer } from "antd";
|
|
5
|
+
import { MessageOutlined, CloseOutlined } from "@ant-design/icons";
|
|
6
|
+
import MessageList from "../message/MessageList";
|
|
7
|
+
const ChatBubble = ({ conversationId, conversationData, className }) => {
|
|
8
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
const toggleChat = () => {
|
|
10
|
+
setIsOpen(!isOpen);
|
|
11
|
+
};
|
|
12
|
+
return (_jsxs(_Fragment, { children: [_jsx(FloatButton, { icon: isOpen ? _jsx(CloseOutlined, {}) : _jsx(MessageOutlined, {}), type: "primary", style: {
|
|
13
|
+
right: 24,
|
|
14
|
+
bottom: 24,
|
|
15
|
+
width: 60,
|
|
16
|
+
height: 60,
|
|
17
|
+
}, onClick: toggleChat, className: className }), _jsx(Drawer, { title: "Chat", placement: "right", onClose: () => setIsOpen(false), open: isOpen, width: 400, height: 600, style: {
|
|
18
|
+
position: "fixed",
|
|
19
|
+
right: 24,
|
|
20
|
+
bottom: 100,
|
|
21
|
+
borderRadius: "12px",
|
|
22
|
+
}, styles: {
|
|
23
|
+
body: { padding: 0, height: "100%" },
|
|
24
|
+
header: { padding: "12px 16px", borderBottom: "1px solid #f0f0f0" },
|
|
25
|
+
}, mask: false, destroyOnClose: false, children: _jsx("div", { style: { height: "100%", display: "flex", flexDirection: "column" }, children: _jsx(MessageList, { conversationId: conversationId, conversationData: conversationData, className: "flex-1" }) }) })] }));
|
|
26
|
+
};
|
|
27
|
+
export default ChatBubble;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface DeskConversationListProps {
|
|
2
|
+
onConversationSelect?: (conversationId: string, threadId: string) => void;
|
|
3
|
+
selectedConversationId?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const DeskConversationList: ({ onConversationSelect, selectedConversationId, className, }: DeskConversationListProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default DeskConversationList;
|
|
8
|
+
//# sourceMappingURL=DeskConversationList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeskConversationList.d.ts","sourceRoot":"","sources":["../../../src/components/conversation/DeskConversationList.tsx"],"names":[],"mappings":"AAkHA,UAAU,yBAAyB;IACjC,oBAAoB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1E,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAmDD,QAAA,MAAM,oBAAoB,GAAI,8DAI3B,yBAAyB,4CAiK3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
import { useRouter, useSearchParams, usePathname } from "next/navigation";
|
|
5
|
+
import { useConversationList } from "../../hooks/conversation/useConversation";
|
|
6
|
+
import { Icon } from "../icon";
|
|
7
|
+
const mockConversations = [
|
|
8
|
+
{
|
|
9
|
+
id: "1",
|
|
10
|
+
threadId: "thread_001",
|
|
11
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
12
|
+
username: "phhuyen2110",
|
|
13
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
14
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
15
|
+
timestamp: "27/07",
|
|
16
|
+
unreadCount: 1,
|
|
17
|
+
isOnline: true,
|
|
18
|
+
status: "unassigned",
|
|
19
|
+
source: "obefe",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "2",
|
|
23
|
+
threadId: "thread_002",
|
|
24
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
25
|
+
username: "phhuyen2110",
|
|
26
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
27
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
28
|
+
timestamp: "27/07",
|
|
29
|
+
unreadCount: 1,
|
|
30
|
+
isOnline: true,
|
|
31
|
+
status: "slow",
|
|
32
|
+
source: "obefe",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: "3",
|
|
36
|
+
threadId: "thread_003",
|
|
37
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
38
|
+
username: "phhuyen2110",
|
|
39
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
40
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
41
|
+
timestamp: "27/07",
|
|
42
|
+
unreadCount: 1,
|
|
43
|
+
isOnline: true,
|
|
44
|
+
status: "waiting",
|
|
45
|
+
source: "obefe",
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "4",
|
|
49
|
+
threadId: "thread_004",
|
|
50
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
51
|
+
username: "phhuyen2110",
|
|
52
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
53
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
54
|
+
timestamp: "27/07",
|
|
55
|
+
unreadCount: 1,
|
|
56
|
+
isOnline: true,
|
|
57
|
+
status: "not_replied",
|
|
58
|
+
source: "obefe",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "5",
|
|
62
|
+
threadId: "thread_005",
|
|
63
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
64
|
+
username: "phhuyen2110",
|
|
65
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
66
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
67
|
+
timestamp: "27/07",
|
|
68
|
+
unreadCount: 1,
|
|
69
|
+
isOnline: true,
|
|
70
|
+
status: "processing",
|
|
71
|
+
source: "obefe",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "6",
|
|
75
|
+
threadId: "thread_006",
|
|
76
|
+
name: "Phương Huyền (phhuyen2110)",
|
|
77
|
+
username: "phhuyen2110",
|
|
78
|
+
avatar: "https://i.pinimg.com/736x/55/e5/ed/55e5edbb1a5b5f6e4f3cefc98de629ca.jpg",
|
|
79
|
+
lastMessage: "Customer: hi Livechat Obefe",
|
|
80
|
+
timestamp: "27/07",
|
|
81
|
+
unreadCount: 1,
|
|
82
|
+
isOnline: true,
|
|
83
|
+
status: "closed",
|
|
84
|
+
source: "obefe",
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
const getStatusIcon = (status) => {
|
|
88
|
+
switch (status) {
|
|
89
|
+
case "unassigned":
|
|
90
|
+
return {
|
|
91
|
+
icon: "user-del-o",
|
|
92
|
+
bgColor: "bg-red-100",
|
|
93
|
+
iconColor: "text-red-500",
|
|
94
|
+
};
|
|
95
|
+
case "slow":
|
|
96
|
+
return {
|
|
97
|
+
icon: "warning-square-o",
|
|
98
|
+
bgColor: "bg-orange-100",
|
|
99
|
+
iconColor: "text-orange-500",
|
|
100
|
+
};
|
|
101
|
+
case "waiting":
|
|
102
|
+
return {
|
|
103
|
+
icon: "time-circle-o",
|
|
104
|
+
bgColor: "bg-yellow-100",
|
|
105
|
+
iconColor: "text-yellow-600",
|
|
106
|
+
};
|
|
107
|
+
case "not_replied":
|
|
108
|
+
return {
|
|
109
|
+
icon: "arrow-reply-o",
|
|
110
|
+
bgColor: "bg-orange-100",
|
|
111
|
+
iconColor: "text-orange-500",
|
|
112
|
+
};
|
|
113
|
+
case "processing":
|
|
114
|
+
return {
|
|
115
|
+
icon: "play-b",
|
|
116
|
+
bgColor: "bg-blue-100",
|
|
117
|
+
iconColor: "text-blue-500",
|
|
118
|
+
};
|
|
119
|
+
case "paused":
|
|
120
|
+
return {
|
|
121
|
+
icon: "pause-b",
|
|
122
|
+
bgColor: "bg-gray-100",
|
|
123
|
+
iconColor: "text-gray-500",
|
|
124
|
+
};
|
|
125
|
+
case "closed":
|
|
126
|
+
return {
|
|
127
|
+
icon: "check-b",
|
|
128
|
+
bgColor: "bg-green-100",
|
|
129
|
+
iconColor: "text-green-500",
|
|
130
|
+
};
|
|
131
|
+
default:
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const DeskConversationList = ({ onConversationSelect, selectedConversationId, className = "", }) => {
|
|
136
|
+
const { conversationList } = useConversationList();
|
|
137
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
138
|
+
const router = useRouter();
|
|
139
|
+
const pathname = usePathname();
|
|
140
|
+
const searchParams = useSearchParams();
|
|
141
|
+
console.log(conversationList);
|
|
142
|
+
const currentThreadId = searchParams.get("threadId");
|
|
143
|
+
const [selectedThreadId, setSelectedThreadId] = useState(currentThreadId);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
setSelectedThreadId(currentThreadId);
|
|
146
|
+
}, [currentThreadId]);
|
|
147
|
+
const conversations = mockConversations;
|
|
148
|
+
const filteredConversations = conversations.filter((conv) => conv.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
|
149
|
+
conv.lastMessage.toLowerCase().includes(searchQuery.toLowerCase()));
|
|
150
|
+
const handleConversationClick = (conversation) => {
|
|
151
|
+
const newSearchParams = new URLSearchParams(searchParams);
|
|
152
|
+
newSearchParams.set("threadId", conversation.threadId);
|
|
153
|
+
router.push(`${pathname}?${newSearchParams.toString()}`);
|
|
154
|
+
setSelectedThreadId(conversation.threadId);
|
|
155
|
+
onConversationSelect === null || onConversationSelect === void 0 ? void 0 : onConversationSelect(conversation.id, conversation.threadId);
|
|
156
|
+
};
|
|
157
|
+
return (_jsxs("div", { className: `flex flex-col h-full bg-white border-r border-gray-200 ${className}`, children: [_jsx("div", { className: "p-3 border-b border-gray-200", children: _jsxs("div", { className: "relative", children: [_jsx(Icon, { icon: "search-o", size: 18, className: "absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400" }), _jsx("input", { type: "text", placeholder: "T\u00ECm ki\u1EBFm", value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), className: "w-full pl-10 pr-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm" })] }) }), _jsxs("div", { className: "flex-1 overflow-y-auto", children: [filteredConversations.map((conversation) => (_jsxs("div", { onClick: () => handleConversationClick(conversation), className: `relative p-3 border-b border-gray-100 hover:bg-gray-50 cursor-pointer transition-colors ${selectedThreadId === conversation.threadId
|
|
158
|
+
? "bg-blue-50"
|
|
159
|
+
: "bg-white"}`, children: [selectedThreadId === conversation.threadId && (_jsx("div", { className: "absolute left-0 top-0 bottom-0 w-1 bg-blue-500" })), _jsxs("div", { className: "flex items-start gap-3", children: [_jsxs("div", { className: "relative flex-shrink-0", children: [_jsx("img", { src: conversation.avatar, alt: conversation.name, className: "w-12 h-12 rounded-full object-cover" }), conversation.isOnline && (_jsx("div", { className: "absolute -bottom-0.5 -right-0.5 w-4 h-4 bg-green-500 border-2 border-white rounded-full" }))] }), _jsx("div", { className: "flex-1 min-w-0", children: _jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("h3", { className: "font-semibold text-gray-900 text-sm truncate", children: conversation.name }), _jsx("p", { className: "text-xs text-gray-500 truncate mt-0.5", children: conversation.lastMessage })] }), _jsxs("div", { className: "flex flex-col items-end gap-1 ml-2", children: [_jsx("span", { className: "text-xs text-gray-400", children: conversation.timestamp }), _jsxs("div", { className: "flex items-center gap-1", children: [conversation.unreadCount > 0 && (_jsx("span", { className: "inline-flex items-center justify-center w-5 h-5 text-xs font-medium text-white bg-red-500 rounded-full", children: conversation.unreadCount })), (() => {
|
|
160
|
+
const statusIcon = getStatusIcon(conversation.status);
|
|
161
|
+
if (!statusIcon)
|
|
162
|
+
return null;
|
|
163
|
+
return (_jsx("div", { className: `w-5 h-5 ${statusIcon.bgColor} rounded-full flex items-center justify-center`, children: _jsx(Icon, { icon: statusIcon.icon, size: 12, className: statusIcon.iconColor }) }));
|
|
164
|
+
})()] })] })] }) })] })] }, conversation.id))), filteredConversations.length === 0 && (_jsxs("div", { className: "flex flex-col items-center justify-center py-12 text-gray-500", children: [_jsx(Icon, { icon: "chat-square-b", size: 48, className: "text-gray-300 mb-4" }), _jsx("p", { className: "text-lg font-medium mb-2", children: "Kh\u00F4ng t\u00ECm th\u1EA5y cu\u1ED9c tr\u00F2 chuy\u1EC7n" }), _jsx("p", { className: "text-sm text-center", children: searchQuery
|
|
165
|
+
? "Thử tìm kiếm với từ khóa khác"
|
|
166
|
+
: "Chưa có cuộc trò chuyện nào" })] }))] })] }));
|
|
167
|
+
};
|
|
168
|
+
export default DeskConversationList;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface IconProps {
|
|
3
|
+
icon: string;
|
|
4
|
+
size?: number | string;
|
|
5
|
+
color?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: React.CSSProperties;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const Icon: React.FC<IconProps>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/icon/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAqBpC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import IcoMoon from "react-icomoon";
|
|
14
|
+
import iconSet from "../../assets/droppiiFontSelection.json";
|
|
15
|
+
export const Icon = (_a) => {
|
|
16
|
+
var { icon, size = 24, color = "currentColor", className = "", style = {}, onClick } = _a, props = __rest(_a, ["icon", "size", "color", "className", "style", "onClick"]);
|
|
17
|
+
return (_jsx(IcoMoon, Object.assign({ iconSet: iconSet, icon: icon, size: size, color: color, className: className, style: style, onClick: onClick }, props)));
|
|
18
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ConversationItem } from "@openim/wasm-client-sdk";
|
|
2
|
+
interface MessageListProps {
|
|
3
|
+
conversationId: string;
|
|
4
|
+
conversationData: ConversationItem | null;
|
|
5
|
+
className?: string;
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const MessageList: (props: MessageListProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default MessageList;
|
|
10
|
+
//# sourceMappingURL=MessageList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/message/MessageList.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,yBAAyB,CAAC;AASjC,UAAU,gBAAgB;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CAsL3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { SessionType, } from "@openim/wasm-client-sdk";
|
|
4
|
+
import { useChatContext } from "../../context/ChatContext";
|
|
5
|
+
import { useMessage } from "../../hooks/message/useMessage";
|
|
6
|
+
import { Avatar, Button, Input, Tooltip } from "antd";
|
|
7
|
+
import { Icon } from "../icon";
|
|
8
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
|
+
import clsx from "clsx";
|
|
10
|
+
import { useSendMessage } from "../../hooks/message/useSendMessage";
|
|
11
|
+
const MessageList = (props) => {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { conversationId, conversationData, onClose } = props;
|
|
14
|
+
const { messageList, refetch } = useMessage(conversationId);
|
|
15
|
+
const scrollRef = useRef(null);
|
|
16
|
+
const shouldScrollToBottomRef = useRef(true);
|
|
17
|
+
const lastMessageCountRef = useRef((messageList === null || messageList === void 0 ? void 0 : messageList.length) || 0);
|
|
18
|
+
const { user } = useChatContext();
|
|
19
|
+
const { sendTextMessage } = useSendMessage({
|
|
20
|
+
recvID: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationType) !== SessionType.Single
|
|
21
|
+
? ""
|
|
22
|
+
: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.userID) || "",
|
|
23
|
+
groupID: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.conversationType) === SessionType.Single
|
|
24
|
+
? ""
|
|
25
|
+
: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.groupID) || "",
|
|
26
|
+
});
|
|
27
|
+
const [textMessage, setTextMessage] = useState("");
|
|
28
|
+
const [showScrollToBottomButton, setShowScrollToBottomButton] = useState(false);
|
|
29
|
+
const scrollToBottom = useCallback((force = false) => {
|
|
30
|
+
if (scrollRef.current) {
|
|
31
|
+
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
|
32
|
+
if (force) {
|
|
33
|
+
shouldScrollToBottomRef.current = true; // If forced, ensure auto-scroll is re-enabled
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
const handleScroll = useCallback(() => {
|
|
38
|
+
if (!scrollRef.current)
|
|
39
|
+
return;
|
|
40
|
+
const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
|
|
41
|
+
const distanceFromBottom = scrollHeight - scrollTop - clientHeight;
|
|
42
|
+
const SCROLL_UP_THRESHOLD = 200; // If user scrolls up more than 200px from bottom, disable auto-scroll
|
|
43
|
+
const SCROLL_DOWN_THRESHOLD = 5; // If user scrolls within 5px of bottom, re-enable auto-scroll
|
|
44
|
+
if (distanceFromBottom > SCROLL_UP_THRESHOLD) {
|
|
45
|
+
shouldScrollToBottomRef.current = false;
|
|
46
|
+
}
|
|
47
|
+
else if (distanceFromBottom <= SCROLL_DOWN_THRESHOLD) {
|
|
48
|
+
shouldScrollToBottomRef.current = true;
|
|
49
|
+
}
|
|
50
|
+
// Show button if not at bottom AND auto-scroll is disabled
|
|
51
|
+
setShowScrollToBottomButton(distanceFromBottom > SCROLL_DOWN_THRESHOLD &&
|
|
52
|
+
!shouldScrollToBottomRef.current);
|
|
53
|
+
}, []);
|
|
54
|
+
const onSendTextMessage = async () => {
|
|
55
|
+
setTextMessage("");
|
|
56
|
+
const res = await sendTextMessage(textMessage);
|
|
57
|
+
if (res) {
|
|
58
|
+
refetch();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const renderMessageItem = useCallback((message) => {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
const isMine = (message === null || message === void 0 ? void 0 : message.sendID) === (user === null || user === void 0 ? void 0 : user.userID);
|
|
64
|
+
return (_jsx("div", { className: clsx("flex", isMine ? "justify-end" : "justify-start"), children: _jsxs("div", { className: "flex items-end gap-2", children: [!isMine && (_jsx(Avatar, { children: ((_b = (_a = message === null || message === void 0 ? void 0 : message.senderNickname) === null || _a === void 0 ? void 0 : _a.charAt) === null || _b === void 0 ? void 0 : _b.call(_a, 0)) || "A" })), _jsxs("div", { className: "flex flex-col items-start", children: [!isMine && (_jsx("span", { className: "text-xs text-gray-500 mb-1 px-3", children: message === null || message === void 0 ? void 0 : message.senderNickname })), _jsx("div", { className: clsx("px-3 py-2 sm:px-4 sm:py-2 rounded-2xl max-w-full break-words", isMine
|
|
65
|
+
? "bg-blue-500 text-white"
|
|
66
|
+
: "bg-gray-100 text-gray-900"), children: _jsx("p", { className: "text-sm sm:text-base whitespace-pre-wrap", children: ((_c = message === null || message === void 0 ? void 0 : message.textElem) === null || _c === void 0 ? void 0 : _c.content) || "Tin nhắn không khả dụng" }) })] })] }) }));
|
|
67
|
+
}, [user === null || user === void 0 ? void 0 : user.userID]);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const currentMessageCount = (messageList === null || messageList === void 0 ? void 0 : messageList.length) || 0;
|
|
70
|
+
const previousMessageCount = lastMessageCountRef.current;
|
|
71
|
+
if (currentMessageCount > previousMessageCount) {
|
|
72
|
+
const newMessages = messageList === null || messageList === void 0 ? void 0 : messageList.slice(previousMessageCount);
|
|
73
|
+
const hasNewMessageFromCurrentUser = newMessages === null || newMessages === void 0 ? void 0 : newMessages.some((msg) => msg.sendID === (user === null || user === void 0 ? void 0 : user.userID));
|
|
74
|
+
// If current user sent a message, always scroll to bottom
|
|
75
|
+
// If another user sent a message, only scroll if shouldScrollToBottomRef is true (user is already at bottom)
|
|
76
|
+
if (hasNewMessageFromCurrentUser) {
|
|
77
|
+
setTimeout(() => scrollToBottom(true), 50); // Force scroll for own messages
|
|
78
|
+
}
|
|
79
|
+
else if (shouldScrollToBottomRef.current) {
|
|
80
|
+
setTimeout(() => scrollToBottom(), 50); // Scroll if auto-scroll is enabled for others' messages
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
lastMessageCountRef.current = currentMessageCount;
|
|
84
|
+
}, [messageList, user === null || user === void 0 ? void 0 : user.userID, scrollToBottom]);
|
|
85
|
+
return (_jsxs("div", { className: "flex flex-col flex-1 relative h-full bg-white", children: [_jsxs("div", { className: "px-4 py-3 flex items-center border-b gap-3", children: [_jsx(Avatar, { src: conversationData === null || conversationData === void 0 ? void 0 : conversationData.faceURL, children: ((_b = (_a = conversationData === null || conversationData === void 0 ? void 0 : conversationData.showName) === null || _a === void 0 ? void 0 : _a.charAt) === null || _b === void 0 ? void 0 : _b.call(_a, 0)) || "A" }), _jsxs("div", { className: "flex flex-col flex-1", children: [_jsx("p", { children: (conversationData === null || conversationData === void 0 ? void 0 : conversationData.showName) || "" }), _jsx("p", { className: "text-xs text-gray-500", children: "2 thành viên" })] }), _jsx(Button, { type: "text", shape: "circle", icon: _jsx(Icon, { icon: "align-justify-o", size: 24 }) }), !!onClose && (_jsx(Button, { type: "text", shape: "circle", icon: _jsx(Icon, { icon: "close-b", size: 24 }), onClick: onClose }))] }), _jsx("div", { className: "flex flex-col flex-1 min-h-0", children: _jsx("div", { className: "relative h-full h-full", children: _jsx("div", { ref: scrollRef, className: "h-full overflow-y-auto p-3 sm:p-4 flex flex-col gap-2", children: messageList === null || messageList === void 0 ? void 0 : messageList.map((message) => renderMessageItem(message)) }) }) }), _jsx("div", { className: "border-t px-4 py-3", children: _jsx("div", { className: "border rounded-lg bg-gray-50", children: _jsxs("div", { className: "px-4 py-3 flex items-center gap-4", children: [_jsx(Input, { placeholder: "Nh\u1EADp tin nh\u1EAFn", size: "small", variant: "borderless", value: textMessage, onChange: (e) => setTextMessage(e.target.value), onKeyDown: (e) => {
|
|
86
|
+
if (e.key === "Enter") {
|
|
87
|
+
onSendTextMessage();
|
|
88
|
+
}
|
|
89
|
+
} }), _jsx(Tooltip, { title: "G\u1EEDi tin nh\u1EAFn", children: _jsx(Button, { type: "primary", shape: "circle", size: "middle", icon: _jsx(Icon, { icon: "send-b", color: "white", size: 16 }), disabled: textMessage.length === 0, onClick: onSendTextMessage }) })] }) }) })] }));
|
|
90
|
+
};
|
|
91
|
+
export default MessageList;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface AssignedSessionFilterProps {
|
|
2
|
+
onFilterChange?: (categoryId: string, subCategoryId?: string) => void;
|
|
3
|
+
className?: string;
|
|
4
|
+
}
|
|
5
|
+
declare const AssignedSessionFilter: ({ onFilterChange, className, }: AssignedSessionFilterProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export default AssignedSessionFilter;
|
|
7
|
+
//# sourceMappingURL=AssignedSessionFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssignedSessionFilter.d.ts","sourceRoot":"","sources":["../../../src/components/session/AssignedSessionFilter.tsx"],"names":[],"mappings":"AAyEA,UAAU,0BAA0B;IAClC,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,qBAAqB,GAAI,gCAG5B,0BAA0B,4CA0H5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Icon } from "../icon";
|
|
5
|
+
const messageCategories = [
|
|
6
|
+
{
|
|
7
|
+
icon: "chat-square-b",
|
|
8
|
+
label: "Đang mở",
|
|
9
|
+
count: 43,
|
|
10
|
+
color: "text-gray-600",
|
|
11
|
+
subCategories: [
|
|
12
|
+
{
|
|
13
|
+
icon: "user-del-o",
|
|
14
|
+
label: "Chưa phân công",
|
|
15
|
+
count: 1,
|
|
16
|
+
color: "text-orange-500",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
icon: "warning-square-o",
|
|
20
|
+
label: "Chậm xử lý",
|
|
21
|
+
count: 1,
|
|
22
|
+
color: "text-red-500",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
icon: "time-circle-o",
|
|
26
|
+
label: "Chờ xử lý",
|
|
27
|
+
count: 0,
|
|
28
|
+
color: "text-orange-400",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
icon: "arrow-reply-o",
|
|
32
|
+
label: "Chưa trả lời",
|
|
33
|
+
count: 1,
|
|
34
|
+
color: "text-purple-500",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
icon: "play-b",
|
|
38
|
+
label: "Đang xử lý",
|
|
39
|
+
count: 38,
|
|
40
|
+
color: "text-gray-600",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
icon: "pause-b",
|
|
44
|
+
label: "Tạm chờ",
|
|
45
|
+
count: 2,
|
|
46
|
+
color: "text-gray-600",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
icon: "check-b",
|
|
52
|
+
label: "Đã đóng",
|
|
53
|
+
count: 0,
|
|
54
|
+
color: "text-green-600",
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const AssignedSessionFilter = ({ onFilterChange, className = "", }) => {
|
|
58
|
+
const [expandedCategories, setExpandedCategories] = useState(new Set([0]));
|
|
59
|
+
const [selectedFilter, setSelectedFilter] = useState("");
|
|
60
|
+
const toggleCategory = (index) => {
|
|
61
|
+
const newExpanded = new Set(expandedCategories);
|
|
62
|
+
if (newExpanded.has(index)) {
|
|
63
|
+
newExpanded.delete(index);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
newExpanded.add(index);
|
|
67
|
+
}
|
|
68
|
+
setExpandedCategories(newExpanded);
|
|
69
|
+
};
|
|
70
|
+
const handleFilterSelect = (categoryId, subCategoryId) => {
|
|
71
|
+
const filterId = subCategoryId || categoryId;
|
|
72
|
+
setSelectedFilter(filterId);
|
|
73
|
+
onFilterChange === null || onFilterChange === void 0 ? void 0 : onFilterChange(categoryId, subCategoryId);
|
|
74
|
+
};
|
|
75
|
+
return (_jsxs("div", { className: `w-64 bg-white border-r border-gray-200 flex flex-col ${className}`, children: [_jsx("div", { className: "p-4 border-b border-gray-200", children: _jsx("h2", { className: "text-lg font-semibold text-gray-800", children: "TIN NH\u1EAEN C\u1EE6A T\u00D4I" }) }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx("ul", { className: "py-2", children: messageCategories.map((category, index) => (_jsxs("li", { children: [_jsxs("button", { onClick: () => {
|
|
76
|
+
if (category.subCategories) {
|
|
77
|
+
toggleCategory(index);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
handleFilterSelect(category.label);
|
|
81
|
+
}
|
|
82
|
+
}, className: `w-full flex items-center justify-between px-4 py-3 hover:bg-gray-50 transition-colors group ${selectedFilter === category.label && !category.subCategories
|
|
83
|
+
? "bg-blue-50 border-r-2 border-blue-500"
|
|
84
|
+
: ""}`, children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [category.subCategories && (_jsx(Icon, { icon: expandedCategories.has(index)
|
|
85
|
+
? "chevron-down-b"
|
|
86
|
+
: "chevron-right-b", size: 14, className: "text-gray-400" })), _jsx(Icon, { icon: category.icon, size: 20, className: category.color })] }), _jsx("span", { className: "font-medium text-gray-800 text-left", children: category.label })] }), _jsx("span", { className: "text-sm font-medium text-gray-500 min-w-0", children: category.count })] }), category.subCategories && expandedCategories.has(index) && (_jsx("ul", { className: "ml-4 border-l border-gray-200", children: category.subCategories.map((subCategory, subIndex) => (_jsx("li", { children: _jsxs("button", { onClick: () => handleFilterSelect(category.label, subCategory.label), className: `w-full flex items-center justify-between px-4 py-2 hover:bg-gray-50 transition-colors group ${selectedFilter === subCategory.label
|
|
87
|
+
? "bg-blue-50 border-r-2 border-blue-500"
|
|
88
|
+
: ""}`, children: [_jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "flex-shrink-0 ml-4", children: _jsx(Icon, { icon: subCategory.icon, size: 18, className: subCategory.color }) }), _jsx("span", { className: "text-sm font-medium text-gray-700 text-left", children: subCategory.label })] }), _jsx("span", { className: "text-xs font-medium text-gray-500 min-w-0", children: subCategory.count })] }) }, subIndex))) }))] }, index))) }) })] }));
|
|
89
|
+
};
|
|
90
|
+
export default AssignedSessionFilter;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChatContextType, ChatProviderProps } from "src/types/chat";
|
|
2
|
+
export declare const ChatContext: import("react").Context<ChatContextType>;
|
|
3
|
+
export declare const useChatContext: () => ChatContextType;
|
|
4
|
+
export declare const ChatProvider: ({ children, config }: ChatProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
//# sourceMappingURL=ChatContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatContext.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGpE,eAAO,MAAM,WAAW,0CAEtB,CAAC;AAEH,eAAO,MAAM,cAAc,uBAAgC,CAAC;AAE5D,eAAO,MAAM,YAAY,GAAI,sBAAsB,iBAAiB,4CAkCnE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
4
|
+
import { getSDK, } from "@openim/wasm-client-sdk";
|
|
5
|
+
const DChatSDK = getSDK();
|
|
6
|
+
export const ChatContext = createContext({
|
|
7
|
+
user: null,
|
|
8
|
+
});
|
|
9
|
+
export const useChatContext = () => useContext(ChatContext);
|
|
10
|
+
export const ChatProvider = ({ children, config }) => {
|
|
11
|
+
const [loading, setLoading] = useState(true);
|
|
12
|
+
const [user, setUser] = useState(null);
|
|
13
|
+
const getUserInfo = () => {
|
|
14
|
+
DChatSDK.getSelfUserInfo()
|
|
15
|
+
.then(({ data }) => {
|
|
16
|
+
setUser(data);
|
|
17
|
+
})
|
|
18
|
+
.catch(({ errCode, errMsg }) => {
|
|
19
|
+
console.log("getSelfUserInfo", errCode, errMsg);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const handleLogin = () => {
|
|
23
|
+
DChatSDK.login(config)
|
|
24
|
+
.then((res) => {
|
|
25
|
+
getUserInfo();
|
|
26
|
+
setLoading(false);
|
|
27
|
+
})
|
|
28
|
+
.catch(({ errCode, errMsg }) => {
|
|
29
|
+
console.log("login", errCode, errMsg);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
handleLogin();
|
|
34
|
+
}, [config]);
|
|
35
|
+
return (_jsx(ChatContext.Provider, { value: { user }, children: !loading ? children : null }));
|
|
36
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConversationItem, SessionType } from '@openim/wasm-client-sdk';
|
|
2
|
+
export declare const useConversationList: () => {
|
|
3
|
+
conversationList: ConversationItem[];
|
|
4
|
+
};
|
|
5
|
+
export declare const useConversationDetail: ({ sourceID, sessionType }: {
|
|
6
|
+
sourceID: string;
|
|
7
|
+
sessionType: SessionType;
|
|
8
|
+
}) => {
|
|
9
|
+
conversationDetail: ConversationItem | null;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useConversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/conversation/useConversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAIhF,eAAO,MAAM,mBAAmB;;CA8B/B,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,2BAAyB;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAC;;CAqB1G,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getSDK } from '@openim/wasm-client-sdk';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
const DChatSDK = getSDK();
|
|
4
|
+
export const useConversationList = () => {
|
|
5
|
+
const [conversationList, setConversationList] = useState([]);
|
|
6
|
+
const getAllConversationList = useCallback(async () => {
|
|
7
|
+
DChatSDK.getAllConversationList().then(({ data }) => {
|
|
8
|
+
console.log('getAllConversationList', data);
|
|
9
|
+
setConversationList(data);
|
|
10
|
+
}).catch((err) => {
|
|
11
|
+
console.log('getAllConversationList', err);
|
|
12
|
+
});
|
|
13
|
+
}, []);
|
|
14
|
+
const getOneConversation = useCallback(async () => {
|
|
15
|
+
DChatSDK.getOneConversation({
|
|
16
|
+
sourceID: '3408237279',
|
|
17
|
+
sessionType: 3
|
|
18
|
+
}).then(({ data }) => {
|
|
19
|
+
console.log('getOneConversation', data);
|
|
20
|
+
}).catch((err) => {
|
|
21
|
+
console.log('getOneConversation', err);
|
|
22
|
+
});
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
getAllConversationList();
|
|
26
|
+
getOneConversation();
|
|
27
|
+
}, [getAllConversationList]);
|
|
28
|
+
return {
|
|
29
|
+
conversationList,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const useConversationDetail = ({ sourceID, sessionType }) => {
|
|
33
|
+
const [conversationDetail, setConversationDetail] = useState(null);
|
|
34
|
+
const getConversationDetail = useCallback(async () => {
|
|
35
|
+
DChatSDK.getOneConversation({
|
|
36
|
+
sourceID,
|
|
37
|
+
sessionType
|
|
38
|
+
}).then(({ data }) => {
|
|
39
|
+
console.log('getOneConversation', data);
|
|
40
|
+
setConversationDetail(data);
|
|
41
|
+
}).catch((err) => {
|
|
42
|
+
console.log('getOneConversation', err);
|
|
43
|
+
});
|
|
44
|
+
}, [sourceID, sessionType]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
getConversationDetail();
|
|
47
|
+
}, [getConversationDetail]);
|
|
48
|
+
return {
|
|
49
|
+
conversationDetail,
|
|
50
|
+
};
|
|
51
|
+
};
|