@droppii-org/chat-sdk 0.0.4 → 0.0.5
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/tsconfig.tsbuildinfo +1 -0
- package/package.json +11 -4
- package/dist/components/AutoScrollAnchor.d.ts +0 -2
- package/dist/components/AutoScrollAnchor.d.ts.map +0 -1
- package/dist/components/AutoScrollAnchor.js +0 -12
- package/dist/components/AutoScrollAnchor.jsx +0 -11
- package/dist/components/ChatBubble.d.ts +0 -2
- package/dist/components/ChatBubble.d.ts.map +0 -1
- package/dist/components/ChatBubble.js +0 -18
- package/dist/components/ChatBubble.jsx +0 -80
- package/dist/components/ChatHeader.d.ts +0 -8
- package/dist/components/ChatHeader.d.ts.map +0 -1
- package/dist/components/ChatHeader.js +0 -32
- package/dist/components/ChatHeader.jsx +0 -72
- package/dist/components/ChatInput.d.ts +0 -3
- package/dist/components/ChatInput.d.ts.map +0 -1
- package/dist/components/ChatInput.js +0 -379
- package/dist/components/ChatInput.jsx +0 -444
- package/dist/components/ChatInputDemo.d.ts +0 -2
- package/dist/components/ChatInputDemo.d.ts.map +0 -1
- package/dist/components/ChatInputDemo.js +0 -38
- package/dist/components/ChatInputDemo.jsx +0 -53
- package/dist/components/ChatInputWithCustomIcon.d.ts +0 -16
- package/dist/components/ChatInputWithCustomIcon.d.ts.map +0 -1
- package/dist/components/ChatInputWithCustomIcon.js +0 -85
- package/dist/components/ChatInputWithCustomIcon.jsx +0 -167
- package/dist/components/ChatLayout.d.ts +0 -6
- package/dist/components/ChatLayout.d.ts.map +0 -1
- package/dist/components/ChatLayout.js +0 -48
- package/dist/components/ChatLayout.jsx +0 -122
- package/dist/components/ConversationItem.d.ts +0 -9
- package/dist/components/ConversationItem.d.ts.map +0 -1
- package/dist/components/ConversationItem.js +0 -27
- package/dist/components/ConversationItem.jsx +0 -51
- package/dist/components/ConversationList.d.ts +0 -8
- package/dist/components/ConversationList.d.ts.map +0 -1
- package/dist/components/ConversationList.js +0 -11
- package/dist/components/ConversationList.jsx +0 -22
- package/dist/components/DateDivider.d.ts +0 -7
- package/dist/components/DateDivider.d.ts.map +0 -1
- package/dist/components/DateDivider.js +0 -27
- package/dist/components/DateDivider.jsx +0 -28
- package/dist/components/EmojiPicker.d.ts +0 -4
- package/dist/components/EmojiPicker.d.ts.map +0 -1
- package/dist/components/EmojiPicker.js +0 -191
- package/dist/components/EmojiPicker.jsx +0 -229
- package/dist/components/ImageLightbox.d.ts +0 -8
- package/dist/components/ImageLightbox.d.ts.map +0 -1
- package/dist/components/ImageLightbox.js +0 -8
- package/dist/components/ImageLightbox.jsx +0 -16
- package/dist/components/ImagePreviewModal.d.ts +0 -12
- package/dist/components/ImagePreviewModal.d.ts.map +0 -1
- package/dist/components/ImagePreviewModal.js +0 -55
- package/dist/components/ImagePreviewModal.jsx +0 -84
- package/dist/components/MessageItem.d.ts +0 -3
- package/dist/components/MessageItem.d.ts.map +0 -1
- package/dist/components/MessageItem.js +0 -38
- package/dist/components/MessageItem.jsx +0 -99
- package/dist/components/MessageItemDemo.d.ts +0 -2
- package/dist/components/MessageItemDemo.d.ts.map +0 -1
- package/dist/components/MessageItemDemo.js +0 -166
- package/dist/components/MessageItemDemo.jsx +0 -179
- package/dist/components/MessageList.d.ts +0 -15
- package/dist/components/MessageList.d.ts.map +0 -1
- package/dist/components/MessageList.js +0 -243
- package/dist/components/MessageList.jsx +0 -306
- package/dist/components/MessageListDemo.d.ts +0 -2
- package/dist/components/MessageListDemo.d.ts.map +0 -1
- package/dist/components/MessageListDemo.js +0 -165
- package/dist/components/MessageListDemo.jsx +0 -183
- package/dist/components/StickerPicker.d.ts +0 -4
- package/dist/components/StickerPicker.d.ts.map +0 -1
- package/dist/components/StickerPicker.js +0 -68
- package/dist/components/StickerPicker.jsx +0 -106
- package/dist/components/SwipeIndicator.d.ts +0 -9
- package/dist/components/SwipeIndicator.d.ts.map +0 -1
- package/dist/components/SwipeIndicator.js +0 -24
- package/dist/components/SwipeIndicator.jsx +0 -28
- package/dist/components/TextFormattingToolbar.d.ts +0 -4
- package/dist/components/TextFormattingToolbar.d.ts.map +0 -1
- package/dist/components/TextFormattingToolbar.js +0 -29
- package/dist/components/TextFormattingToolbar.jsx +0 -52
- package/dist/components/TypingIndicator.d.ts +0 -6
- package/dist/components/TypingIndicator.d.ts.map +0 -1
- package/dist/components/TypingIndicator.js +0 -21
- package/dist/components/TypingIndicator.jsx +0 -27
- package/dist/components/VoiceWaveIcon.d.ts +0 -7
- package/dist/components/VoiceWaveIcon.d.ts.map +0 -1
- package/dist/components/VoiceWaveIcon.js +0 -5
- package/dist/components/VoiceWaveIcon.jsx +0 -11
- package/dist/context/ChatContext.d.ts +0 -72
- package/dist/context/ChatContext.d.ts.map +0 -1
- package/dist/context/ChatContext.js +0 -347
- package/dist/context/ChatContext.jsx +0 -346
- package/dist/hooks/useChat.d.ts +0 -5
- package/dist/hooks/useChat.d.ts.map +0 -1
- package/dist/hooks/useChat.js +0 -73
- package/dist/hooks/useConversationList.d.ts +0 -5
- package/dist/hooks/useConversationList.d.ts.map +0 -1
- package/dist/hooks/useConversationList.js +0 -9
- package/dist/hooks/useMessages.d.ts +0 -5
- package/dist/hooks/useMessages.d.ts.map +0 -1
- package/dist/hooks/useMessages.js +0 -192
- package/dist/hooks/useSocket.d.ts +0 -7
- package/dist/hooks/useSocket.d.ts.map +0 -1
- package/dist/hooks/useSocket.js +0 -120
- package/dist/hooks/useSwipeGesture.d.ts +0 -11
- package/dist/hooks/useSwipeGesture.d.ts.map +0 -1
- package/dist/hooks/useSwipeGesture.js +0 -54
- package/dist/hooks/useTextSelection.d.ts +0 -13
- package/dist/hooks/useTextSelection.d.ts.map +0 -1
- package/dist/hooks/useTextSelection.js +0 -132
- package/dist/hooks/useTyping.d.ts +0 -7
- package/dist/hooks/useTyping.d.ts.map +0 -1
- package/dist/hooks/useTyping.js +0 -64
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -29
- package/dist/types/chat.d.ts +0 -39
- package/dist/types/chat.d.ts.map +0 -1
- package/dist/types/chat.js +0 -1
- package/dist/types/index.d.ts +0 -86
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -1
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Bold, Italic, Strikethrough, List, ListOrdered, Link, Quote, Code, X } from "lucide-react";
|
|
4
|
-
const formatButtons = [
|
|
5
|
-
{ icon: Bold, label: "Đậm", format: "bold", shortcut: "Ctrl+B", symbol: "**" },
|
|
6
|
-
{ icon: Italic, label: "Nghiêng", format: "italic", shortcut: "Ctrl+I", symbol: "*" },
|
|
7
|
-
{ icon: Strikethrough, label: "Gạch ngang", format: "strikethrough", shortcut: "Ctrl+Shift+X", symbol: "~~" },
|
|
8
|
-
{ icon: ListOrdered, label: "Danh sách số", format: "numbered-list", shortcut: "Ctrl+Shift+7", symbol: "1." },
|
|
9
|
-
{ icon: List, label: "Danh sách dấu đầu dòng", format: "bullet-list", shortcut: "Ctrl+Shift+8", symbol: "•" },
|
|
10
|
-
{ icon: Link, label: "Liên kết", format: "link", shortcut: "Ctrl+K", symbol: "[]" },
|
|
11
|
-
{ icon: Quote, label: "Trích dẫn", format: "quote", shortcut: "Ctrl+Shift+>", symbol: ">" },
|
|
12
|
-
{ icon: Code, label: "Mã", format: "code", shortcut: "Ctrl+E", symbol: "`" },
|
|
13
|
-
];
|
|
14
|
-
export const TextFormattingToolbar = React.forwardRef(({ isOpen, onClose, onFormatSelect, selectedFormats = [], style }, ref) => {
|
|
15
|
-
if (!isOpen)
|
|
16
|
-
return null;
|
|
17
|
-
return (<div ref={ref} className="absolute bottom-full mb-1 bg-white border border-gray-200 rounded-lg shadow-lg z-50 w-full sm:max-w-xs md:w-80" style={style} // Apply dynamic style here
|
|
18
|
-
>
|
|
19
|
-
<div className="p-2">
|
|
20
|
-
{/* Header - Compact */}
|
|
21
|
-
<div className="flex items-center justify-between mb-2">
|
|
22
|
-
<h3 className="text-xs font-medium text-gray-900">Định dạng văn bản</h3>
|
|
23
|
-
<button onClick={onClose} className="p-1 text-gray-400 hover:text-gray-600 rounded-full hover:bg-gray-100">
|
|
24
|
-
<X className="w-3 h-3"/>
|
|
25
|
-
</button>
|
|
26
|
-
</div>
|
|
27
|
-
|
|
28
|
-
{/* Formatting Buttons - Compact Grid */}
|
|
29
|
-
<div className="grid grid-cols-4 gap-1">
|
|
30
|
-
{formatButtons.map((button) => {
|
|
31
|
-
const Icon = button.icon;
|
|
32
|
-
const isSelected = selectedFormats.includes(button.format);
|
|
33
|
-
return (<button key={button.format} onClick={() => onFormatSelect(button.format)} className={`
|
|
34
|
-
flex flex-col items-center p-2 rounded transition-all duration-200 hover:bg-gray-50 active:scale-95
|
|
35
|
-
${isSelected
|
|
36
|
-
? "bg-blue-50 text-blue-600 border border-blue-200"
|
|
37
|
-
: "text-gray-600 hover:text-gray-800 border border-gray-200"}
|
|
38
|
-
`} title={`${button.label} (${button.shortcut})`} aria-label={button.label}>
|
|
39
|
-
<Icon className="w-4 h-4 mb-1"/>
|
|
40
|
-
<span className="text-xs font-medium">{button.symbol}</span>
|
|
41
|
-
</button>);
|
|
42
|
-
})}
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
{/* Keyboard Shortcuts Info - Compact */}
|
|
46
|
-
<div className="mt-2 pt-2 border-t border-gray-100">
|
|
47
|
-
<p className="text-xs text-gray-500 text-center">💡 Sử dụng phím tắt để định dạng nhanh</p>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</div>);
|
|
51
|
-
});
|
|
52
|
-
TextFormattingToolbar.displayName = "TextFormattingToolbar";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TypingIndicator.d.ts","sourceRoot":"","sources":["../../src/components/TypingIndicator.tsx"],"names":[],"mappings":"AAGA,UAAU,oBAAoB;IAC5B,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,wBAAgB,eAAe,CAAC,EAAE,cAAc,EAAE,EAAE,oBAAoB,kDAgCvE"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useTyping } from "../hooks/useTyping";
|
|
4
|
-
export function TypingIndicator({ conversationId }) {
|
|
5
|
-
const { typingUsers, isTyping } = useTyping(conversationId);
|
|
6
|
-
if (!isTyping)
|
|
7
|
-
return null;
|
|
8
|
-
const getTypingText = () => {
|
|
9
|
-
if (typingUsers.length === 1) {
|
|
10
|
-
return `${typingUsers[0].name} is typing...`;
|
|
11
|
-
}
|
|
12
|
-
else if (typingUsers.length === 2) {
|
|
13
|
-
return `${typingUsers[0].name} and ${typingUsers[1].name} are typing...`;
|
|
14
|
-
}
|
|
15
|
-
else if (typingUsers.length > 2) {
|
|
16
|
-
return `${typingUsers[0].name} and ${typingUsers.length - 1} others are typing...`;
|
|
17
|
-
}
|
|
18
|
-
return "Someone is typing...";
|
|
19
|
-
};
|
|
20
|
-
return (_jsxs("div", { className: "flex items-center space-x-2 px-3 sm:px-4 py-2", children: [_jsxs("div", { className: "flex space-x-1", children: [_jsx("div", { className: "w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce" }), _jsx("div", { className: "w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce", style: { animationDelay: "0.1s" } }), _jsx("div", { className: "w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce", style: { animationDelay: "0.2s" } })] }), _jsx("span", { className: "text-xs sm:text-sm text-gray-500", children: getTypingText() })] }));
|
|
21
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useTyping } from "../hooks/useTyping";
|
|
3
|
-
export function TypingIndicator({ conversationId }) {
|
|
4
|
-
const { typingUsers, isTyping } = useTyping(conversationId);
|
|
5
|
-
if (!isTyping)
|
|
6
|
-
return null;
|
|
7
|
-
const getTypingText = () => {
|
|
8
|
-
if (typingUsers.length === 1) {
|
|
9
|
-
return `${typingUsers[0].name} is typing...`;
|
|
10
|
-
}
|
|
11
|
-
else if (typingUsers.length === 2) {
|
|
12
|
-
return `${typingUsers[0].name} and ${typingUsers[1].name} are typing...`;
|
|
13
|
-
}
|
|
14
|
-
else if (typingUsers.length > 2) {
|
|
15
|
-
return `${typingUsers[0].name} and ${typingUsers.length - 1} others are typing...`;
|
|
16
|
-
}
|
|
17
|
-
return "Someone is typing...";
|
|
18
|
-
};
|
|
19
|
-
return (<div className="flex items-center space-x-2 px-3 sm:px-4 py-2">
|
|
20
|
-
<div className="flex space-x-1">
|
|
21
|
-
<div className="w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce"></div>
|
|
22
|
-
<div className="w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce" style={{ animationDelay: "0.1s" }}></div>
|
|
23
|
-
<div className="w-1.5 h-1.5 sm:w-2 sm:h-2 bg-gray-400 rounded-full animate-bounce" style={{ animationDelay: "0.2s" }}></div>
|
|
24
|
-
</div>
|
|
25
|
-
<span className="text-xs sm:text-sm text-gray-500">{getTypingText()}</span>
|
|
26
|
-
</div>);
|
|
27
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceWaveIcon.d.ts","sourceRoot":"","sources":["../../src/components/VoiceWaveIcon.tsx"],"names":[],"mappings":"AAEA,UAAU,kBAAkB;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,aAAa,CAAC,EAAE,SAAqB,EAAE,QAAgB,EAAE,EAAE,kBAAkB,2CAmB5F"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
export function VoiceWaveIcon({ className = "w-5 h-5", animated = false }) {
|
|
4
|
-
return (_jsxs("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("path", { d: "M2 10v4", className: animated ? "animate-pulse" : "" }), _jsx("path", { d: "M6 6v12", className: animated ? "animate-pulse" : "", style: { animationDelay: "0.1s" } }), _jsx("path", { d: "M10 4v16", className: animated ? "animate-pulse" : "", style: { animationDelay: "0.2s" } }), _jsx("path", { d: "M14 4v16", className: animated ? "animate-pulse" : "", style: { animationDelay: "0.3s" } }), _jsx("path", { d: "M18 6v12", className: animated ? "animate-pulse" : "", style: { animationDelay: "0.4s" } }), _jsx("path", { d: "M22 10v4", className: animated ? "animate-pulse" : "", style: { animationDelay: "0.5s" } })] }));
|
|
5
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
export function VoiceWaveIcon({ className = "w-5 h-5", animated = false }) {
|
|
3
|
-
return (<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
4
|
-
<path d="M2 10v4" className={animated ? "animate-pulse" : ""}/>
|
|
5
|
-
<path d="M6 6v12" className={animated ? "animate-pulse" : ""} style={{ animationDelay: "0.1s" }}/>
|
|
6
|
-
<path d="M10 4v16" className={animated ? "animate-pulse" : ""} style={{ animationDelay: "0.2s" }}/>
|
|
7
|
-
<path d="M14 4v16" className={animated ? "animate-pulse" : ""} style={{ animationDelay: "0.3s" }}/>
|
|
8
|
-
<path d="M18 6v12" className={animated ? "animate-pulse" : ""} style={{ animationDelay: "0.4s" }}/>
|
|
9
|
-
<path d="M22 10v4" className={animated ? "animate-pulse" : ""} style={{ animationDelay: "0.5s" }}/>
|
|
10
|
-
</svg>);
|
|
11
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
import type React from "react";
|
|
3
|
-
import type { ChatConfig, Conversation, Message, User, TypingStatus } from "../types";
|
|
4
|
-
interface ChatState {
|
|
5
|
-
config: ChatConfig | null;
|
|
6
|
-
conversations: Conversation[];
|
|
7
|
-
messages: Record<string, Message[]>;
|
|
8
|
-
users: Record<string, User>;
|
|
9
|
-
typingStatuses: TypingStatus[];
|
|
10
|
-
currentUser: User | null;
|
|
11
|
-
isConnected: boolean;
|
|
12
|
-
}
|
|
13
|
-
type ChatAction = {
|
|
14
|
-
type: "SET_CONFIG";
|
|
15
|
-
payload: ChatConfig;
|
|
16
|
-
} | {
|
|
17
|
-
type: "SET_CONVERSATIONS";
|
|
18
|
-
payload: Conversation[];
|
|
19
|
-
} | {
|
|
20
|
-
type: "ADD_CONVERSATION";
|
|
21
|
-
payload: Conversation;
|
|
22
|
-
} | {
|
|
23
|
-
type: "UPDATE_CONVERSATION";
|
|
24
|
-
payload: Conversation;
|
|
25
|
-
} | {
|
|
26
|
-
type: "SET_MESSAGES";
|
|
27
|
-
payload: {
|
|
28
|
-
conversationId: string;
|
|
29
|
-
messages: Message[];
|
|
30
|
-
};
|
|
31
|
-
} | {
|
|
32
|
-
type: "ADD_MESSAGE";
|
|
33
|
-
payload: Message;
|
|
34
|
-
} | {
|
|
35
|
-
type: "UPDATE_MESSAGE";
|
|
36
|
-
payload: Message;
|
|
37
|
-
} | {
|
|
38
|
-
type: "SET_USERS";
|
|
39
|
-
payload: Record<string, User>;
|
|
40
|
-
} | {
|
|
41
|
-
type: "UPDATE_USER";
|
|
42
|
-
payload: User;
|
|
43
|
-
} | {
|
|
44
|
-
type: "SET_TYPING";
|
|
45
|
-
payload: TypingStatus;
|
|
46
|
-
} | {
|
|
47
|
-
type: "REMOVE_TYPING";
|
|
48
|
-
payload: {
|
|
49
|
-
userId: string;
|
|
50
|
-
conversationId: string;
|
|
51
|
-
};
|
|
52
|
-
} | {
|
|
53
|
-
type: "SET_CONNECTION_STATUS";
|
|
54
|
-
payload: boolean;
|
|
55
|
-
};
|
|
56
|
-
interface ChatContextType {
|
|
57
|
-
state: ChatState;
|
|
58
|
-
dispatch: React.Dispatch<ChatAction>;
|
|
59
|
-
}
|
|
60
|
-
export declare function useChatContext(): ChatContextType;
|
|
61
|
-
interface ChatProviderProps {
|
|
62
|
-
children: ReactNode;
|
|
63
|
-
userId: string;
|
|
64
|
-
token: string;
|
|
65
|
-
onTokenRefresh?: () => Promise<string>;
|
|
66
|
-
websocketUrl?: string;
|
|
67
|
-
enableWebSocket?: boolean;
|
|
68
|
-
}
|
|
69
|
-
export declare function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl, // Use "demo" as default to disable WebSocket
|
|
70
|
-
enableWebSocket, }: ChatProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
71
|
-
export {};
|
|
72
|
-
//# sourceMappingURL=ChatContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChatContext.d.ts","sourceRoot":"","sources":["../../src/context/ChatContext.tsx"],"names":[],"mappings":"AACA,OAAO,EAAoD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AACxF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAErF,UAAU,SAAS;IACjB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;IACzB,aAAa,EAAE,YAAY,EAAE,CAAA;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAC3B,cAAc,EAAE,YAAY,EAAE,CAAA;IAC9B,WAAW,EAAE,IAAI,GAAG,IAAI,CAAA;IACxB,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,KAAK,UAAU,GACX;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,YAAY,EAAE,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GACtD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;KAAE,CAAA;CAAE,GAClF;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GACtC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC9E;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAA;AAkGvD,UAAU,eAAe;IACvB,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;CACrC;AAID,wBAAgB,cAAc,oBAM7B;AAED,UAAU,iBAAiB;IACzB,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IACtC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAqB,EAAE,6CAA6C;AACpE,eAAuB,GACxB,EAAE,iBAAiB,2CAySnB"}
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useReducer, useEffect } from "react";
|
|
4
|
-
const initialState = {
|
|
5
|
-
config: null,
|
|
6
|
-
conversations: [],
|
|
7
|
-
messages: {},
|
|
8
|
-
users: {},
|
|
9
|
-
typingStatuses: [],
|
|
10
|
-
currentUser: null,
|
|
11
|
-
isConnected: false,
|
|
12
|
-
};
|
|
13
|
-
function chatReducer(state, action) {
|
|
14
|
-
switch (action.type) {
|
|
15
|
-
case "SET_CONFIG":
|
|
16
|
-
return Object.assign(Object.assign({}, state), { config: action.payload });
|
|
17
|
-
case "SET_CONVERSATIONS":
|
|
18
|
-
return Object.assign(Object.assign({}, state), { conversations: action.payload });
|
|
19
|
-
case "ADD_CONVERSATION":
|
|
20
|
-
return Object.assign(Object.assign({}, state), { conversations: [action.payload, ...state.conversations] });
|
|
21
|
-
case "UPDATE_CONVERSATION":
|
|
22
|
-
return Object.assign(Object.assign({}, state), { conversations: state.conversations.map((conv) => (conv.id === action.payload.id ? action.payload : conv)) });
|
|
23
|
-
case "SET_MESSAGES":
|
|
24
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: action.payload.messages }) });
|
|
25
|
-
case "ADD_MESSAGE":
|
|
26
|
-
const conversationId = action.payload.conversationId;
|
|
27
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [conversationId]: [...(state.messages[conversationId] || []), action.payload] }) });
|
|
28
|
-
case "UPDATE_MESSAGE":
|
|
29
|
-
return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: (state.messages[action.payload.conversationId] || []).map((msg) => msg.id === action.payload.id ? action.payload : msg) }) });
|
|
30
|
-
case "SET_USERS":
|
|
31
|
-
return Object.assign(Object.assign({}, state), { users: action.payload });
|
|
32
|
-
case "UPDATE_USER":
|
|
33
|
-
return Object.assign(Object.assign({}, state), { users: Object.assign(Object.assign({}, state.users), { [action.payload.id]: action.payload }) });
|
|
34
|
-
case "SET_TYPING":
|
|
35
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: [
|
|
36
|
-
...state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)),
|
|
37
|
-
action.payload,
|
|
38
|
-
] });
|
|
39
|
-
case "REMOVE_TYPING":
|
|
40
|
-
return Object.assign(Object.assign({}, state), { typingStatuses: state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)) });
|
|
41
|
-
case "SET_CONNECTION_STATUS":
|
|
42
|
-
return Object.assign(Object.assign({}, state), { isConnected: action.payload });
|
|
43
|
-
default:
|
|
44
|
-
return state;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const ChatContext = createContext(null);
|
|
48
|
-
export function useChatContext() {
|
|
49
|
-
const context = useContext(ChatContext);
|
|
50
|
-
if (!context) {
|
|
51
|
-
throw new Error("useChatContext must be used within a ChatProvider");
|
|
52
|
-
}
|
|
53
|
-
return context;
|
|
54
|
-
}
|
|
55
|
-
export function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl = "demo", // Use "demo" as default to disable WebSocket
|
|
56
|
-
enableWebSocket = false, // Disabled by default for demo
|
|
57
|
-
}) {
|
|
58
|
-
const [state, dispatch] = useReducer(chatReducer, initialState);
|
|
59
|
-
// Initialize config
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
const config = {
|
|
62
|
-
userId,
|
|
63
|
-
token,
|
|
64
|
-
wsUrl: enableWebSocket ? websocketUrl : "demo",
|
|
65
|
-
onTokenRefresh,
|
|
66
|
-
};
|
|
67
|
-
dispatch({ type: "SET_CONFIG", payload: config });
|
|
68
|
-
// Initialize current user
|
|
69
|
-
const currentUser = {
|
|
70
|
-
id: userId,
|
|
71
|
-
name: "You",
|
|
72
|
-
status: "online",
|
|
73
|
-
};
|
|
74
|
-
dispatch({ type: "UPDATE_USER", payload: currentUser });
|
|
75
|
-
}, [userId, token, websocketUrl, onTokenRefresh, enableWebSocket]);
|
|
76
|
-
// Initialize with mock data for demo - MORE CONVERSATIONS
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!state.config)
|
|
79
|
-
return;
|
|
80
|
-
const mockUsers = {
|
|
81
|
-
[userId]: {
|
|
82
|
-
id: userId,
|
|
83
|
-
name: "You",
|
|
84
|
-
status: "online",
|
|
85
|
-
},
|
|
86
|
-
"user-2": {
|
|
87
|
-
id: "user-2",
|
|
88
|
-
name: "Alice Johnson",
|
|
89
|
-
status: "online",
|
|
90
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
91
|
-
},
|
|
92
|
-
"user-3": {
|
|
93
|
-
id: "user-3",
|
|
94
|
-
name: "Bob Smith",
|
|
95
|
-
status: "offline",
|
|
96
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
97
|
-
lastSeen: new Date(Date.now() - 7200000),
|
|
98
|
-
},
|
|
99
|
-
"user-4": {
|
|
100
|
-
id: "user-4",
|
|
101
|
-
name: "Carol Davis",
|
|
102
|
-
status: "online",
|
|
103
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
104
|
-
},
|
|
105
|
-
"user-5": {
|
|
106
|
-
id: "user-5",
|
|
107
|
-
name: "David Wilson",
|
|
108
|
-
status: "away",
|
|
109
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
110
|
-
lastSeen: new Date(Date.now() - 1800000),
|
|
111
|
-
},
|
|
112
|
-
"user-6": {
|
|
113
|
-
id: "user-6",
|
|
114
|
-
name: "Emma Brown",
|
|
115
|
-
status: "online",
|
|
116
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
117
|
-
},
|
|
118
|
-
"user-7": {
|
|
119
|
-
id: "user-7",
|
|
120
|
-
name: "Frank Miller",
|
|
121
|
-
status: "offline",
|
|
122
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
123
|
-
lastSeen: new Date(Date.now() - 86400000),
|
|
124
|
-
},
|
|
125
|
-
"user-8": {
|
|
126
|
-
id: "user-8",
|
|
127
|
-
name: "Grace Lee",
|
|
128
|
-
status: "online",
|
|
129
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
130
|
-
},
|
|
131
|
-
"user-9": {
|
|
132
|
-
id: "user-9",
|
|
133
|
-
name: "Henry Taylor",
|
|
134
|
-
status: "away",
|
|
135
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
136
|
-
lastSeen: new Date(Date.now() - 3600000),
|
|
137
|
-
},
|
|
138
|
-
"user-10": {
|
|
139
|
-
id: "user-10",
|
|
140
|
-
name: "Ivy Chen",
|
|
141
|
-
status: "online",
|
|
142
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
143
|
-
},
|
|
144
|
-
"group-1": {
|
|
145
|
-
id: "group-1",
|
|
146
|
-
name: "Team Project",
|
|
147
|
-
status: "online",
|
|
148
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
149
|
-
},
|
|
150
|
-
"group-2": {
|
|
151
|
-
id: "group-2",
|
|
152
|
-
name: "Family Chat",
|
|
153
|
-
status: "online",
|
|
154
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
const mockConversations = [
|
|
158
|
-
{
|
|
159
|
-
id: "conv-1",
|
|
160
|
-
participants: [mockUsers["user-2"], mockUsers[userId]],
|
|
161
|
-
unreadCount: 2,
|
|
162
|
-
updatedAt: new Date(Date.now() - 300000), // 5 minutes ago
|
|
163
|
-
type: "direct",
|
|
164
|
-
lastMessage: {
|
|
165
|
-
id: "msg-1",
|
|
166
|
-
conversationId: "conv-1",
|
|
167
|
-
senderId: "user-2",
|
|
168
|
-
content: "Hey there! How are you doing? 😊",
|
|
169
|
-
type: "text",
|
|
170
|
-
timestamp: new Date(Date.now() - 300000),
|
|
171
|
-
status: "delivered",
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
id: "conv-2",
|
|
176
|
-
participants: [mockUsers["user-3"], mockUsers[userId]],
|
|
177
|
-
unreadCount: 0,
|
|
178
|
-
updatedAt: new Date(Date.now() - 1800000), // 30 minutes ago
|
|
179
|
-
type: "direct",
|
|
180
|
-
lastMessage: {
|
|
181
|
-
id: "msg-2",
|
|
182
|
-
conversationId: "conv-2",
|
|
183
|
-
senderId: userId,
|
|
184
|
-
content: "Thanks for the help earlier!",
|
|
185
|
-
type: "text",
|
|
186
|
-
timestamp: new Date(Date.now() - 1800000),
|
|
187
|
-
status: "read",
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
id: "conv-3",
|
|
192
|
-
participants: [mockUsers["user-4"], mockUsers[userId]],
|
|
193
|
-
unreadCount: 1,
|
|
194
|
-
updatedAt: new Date(Date.now() - 3600000), // 1 hour ago
|
|
195
|
-
type: "direct",
|
|
196
|
-
lastMessage: {
|
|
197
|
-
id: "msg-3",
|
|
198
|
-
conversationId: "conv-3",
|
|
199
|
-
senderId: "user-4",
|
|
200
|
-
content: "Can you review this document?",
|
|
201
|
-
type: "file",
|
|
202
|
-
timestamp: new Date(Date.now() - 3600000),
|
|
203
|
-
status: "delivered",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
id: "conv-4",
|
|
208
|
-
participants: [mockUsers["user-5"], mockUsers[userId]],
|
|
209
|
-
unreadCount: 0,
|
|
210
|
-
updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
|
|
211
|
-
type: "direct",
|
|
212
|
-
lastMessage: {
|
|
213
|
-
id: "msg-4",
|
|
214
|
-
conversationId: "conv-4",
|
|
215
|
-
senderId: userId,
|
|
216
|
-
content: "See you tomorrow!",
|
|
217
|
-
type: "text",
|
|
218
|
-
timestamp: new Date(Date.now() - 7200000),
|
|
219
|
-
status: "read",
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
id: "conv-5",
|
|
224
|
-
participants: [mockUsers["user-6"], mockUsers[userId]],
|
|
225
|
-
unreadCount: 3,
|
|
226
|
-
updatedAt: new Date(Date.now() - 10800000), // 3 hours ago
|
|
227
|
-
type: "direct",
|
|
228
|
-
lastMessage: {
|
|
229
|
-
id: "msg-5",
|
|
230
|
-
conversationId: "conv-5",
|
|
231
|
-
senderId: "user-6",
|
|
232
|
-
content: "Check out these photos from the event!",
|
|
233
|
-
type: "image",
|
|
234
|
-
timestamp: new Date(Date.now() - 10800000),
|
|
235
|
-
status: "delivered",
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
id: "conv-6",
|
|
240
|
-
participants: [mockUsers["user-7"], mockUsers[userId]],
|
|
241
|
-
unreadCount: 0,
|
|
242
|
-
updatedAt: new Date(Date.now() - 86400000), // 1 day ago
|
|
243
|
-
type: "direct",
|
|
244
|
-
lastMessage: {
|
|
245
|
-
id: "msg-6",
|
|
246
|
-
conversationId: "conv-6",
|
|
247
|
-
senderId: "user-7",
|
|
248
|
-
content: "Happy birthday! 🎉",
|
|
249
|
-
type: "text",
|
|
250
|
-
timestamp: new Date(Date.now() - 86400000),
|
|
251
|
-
status: "read",
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
id: "conv-7",
|
|
256
|
-
participants: [mockUsers["user-8"], mockUsers[userId]],
|
|
257
|
-
unreadCount: 0,
|
|
258
|
-
updatedAt: new Date(Date.now() - 172800000), // 2 days ago
|
|
259
|
-
type: "direct",
|
|
260
|
-
lastMessage: {
|
|
261
|
-
id: "msg-7",
|
|
262
|
-
conversationId: "conv-7",
|
|
263
|
-
senderId: userId,
|
|
264
|
-
content: "Thanks for the coffee recommendation!",
|
|
265
|
-
type: "text",
|
|
266
|
-
timestamp: new Date(Date.now() - 172800000),
|
|
267
|
-
status: "read",
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
id: "conv-8",
|
|
272
|
-
participants: [mockUsers["user-9"], mockUsers[userId]],
|
|
273
|
-
unreadCount: 1,
|
|
274
|
-
updatedAt: new Date(Date.now() - 259200000), // 3 days ago
|
|
275
|
-
type: "direct",
|
|
276
|
-
lastMessage: {
|
|
277
|
-
id: "msg-8",
|
|
278
|
-
conversationId: "conv-8",
|
|
279
|
-
senderId: "user-9",
|
|
280
|
-
content: "Let's schedule a meeting next week",
|
|
281
|
-
type: "text",
|
|
282
|
-
timestamp: new Date(Date.now() - 259200000),
|
|
283
|
-
status: "delivered",
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
id: "conv-9",
|
|
288
|
-
participants: [mockUsers["user-10"], mockUsers[userId]],
|
|
289
|
-
unreadCount: 0,
|
|
290
|
-
updatedAt: new Date(Date.now() - 345600000), // 4 days ago
|
|
291
|
-
type: "direct",
|
|
292
|
-
lastMessage: {
|
|
293
|
-
id: "msg-9",
|
|
294
|
-
conversationId: "conv-9",
|
|
295
|
-
senderId: userId,
|
|
296
|
-
content: "Great presentation today!",
|
|
297
|
-
type: "text",
|
|
298
|
-
timestamp: new Date(Date.now() - 345600000),
|
|
299
|
-
status: "read",
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
id: "group-conv-1",
|
|
304
|
-
participants: [mockUsers["group-1"], mockUsers[userId], mockUsers["user-2"], mockUsers["user-4"]],
|
|
305
|
-
unreadCount: 5,
|
|
306
|
-
updatedAt: new Date(Date.now() - 600000), // 10 minutes ago
|
|
307
|
-
type: "group",
|
|
308
|
-
name: "Team Project",
|
|
309
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
310
|
-
lastMessage: {
|
|
311
|
-
id: "msg-group-1",
|
|
312
|
-
conversationId: "group-conv-1",
|
|
313
|
-
senderId: "user-4",
|
|
314
|
-
content: "The deadline has been moved to Friday",
|
|
315
|
-
type: "text",
|
|
316
|
-
timestamp: new Date(Date.now() - 600000),
|
|
317
|
-
status: "delivered",
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
id: "group-conv-2",
|
|
322
|
-
participants: [mockUsers["group-2"], mockUsers[userId], mockUsers["user-6"], mockUsers["user-8"]],
|
|
323
|
-
unreadCount: 0,
|
|
324
|
-
updatedAt: new Date(Date.now() - 432000000), // 5 days ago
|
|
325
|
-
type: "group",
|
|
326
|
-
name: "Family Chat",
|
|
327
|
-
avatar: "/placeholder.svg?height=40&width=40",
|
|
328
|
-
lastMessage: {
|
|
329
|
-
id: "msg-group-2",
|
|
330
|
-
conversationId: "group-conv-2",
|
|
331
|
-
senderId: "user-6",
|
|
332
|
-
content: "Looking forward to the reunion!",
|
|
333
|
-
type: "text",
|
|
334
|
-
timestamp: new Date(Date.now() - 432000000),
|
|
335
|
-
status: "read",
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
];
|
|
339
|
-
dispatch({ type: "SET_USERS", payload: mockUsers });
|
|
340
|
-
dispatch({ type: "SET_CONVERSATIONS", payload: mockConversations });
|
|
341
|
-
}, [state.config, userId]);
|
|
342
|
-
const value = {
|
|
343
|
-
state,
|
|
344
|
-
dispatch,
|
|
345
|
-
};
|
|
346
|
-
return _jsx(ChatContext.Provider, { value: value, children: children });
|
|
347
|
-
}
|