@droppii-org/chat-sdk 0.0.4 → 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.
Files changed (153) hide show
  1. package/dist/assets/droppiiFontSelection.json +14521 -0
  2. package/dist/components/ChatBubble.d.ts +9 -1
  3. package/dist/components/ChatBubble.d.ts.map +1 -1
  4. package/dist/components/ChatBubble.js +23 -15
  5. package/dist/components/chat-bubble/ChatBubble.d.ts +9 -0
  6. package/dist/components/chat-bubble/ChatBubble.d.ts.map +1 -0
  7. package/dist/components/chat-bubble/ChatBubble.js +27 -0
  8. package/dist/components/conversation/DeskConversationList.d.ts +8 -0
  9. package/dist/components/conversation/DeskConversationList.d.ts.map +1 -0
  10. package/dist/components/conversation/DeskConversationList.js +168 -0
  11. package/dist/components/icon/index.d.ts +11 -0
  12. package/dist/components/icon/index.d.ts.map +1 -0
  13. package/dist/components/icon/index.js +18 -0
  14. package/dist/components/message/MessageList.d.ts +10 -0
  15. package/dist/components/message/MessageList.d.ts.map +1 -0
  16. package/dist/components/message/MessageList.js +91 -0
  17. package/dist/components/session/AssignedSessionFilter.d.ts +7 -0
  18. package/dist/components/session/AssignedSessionFilter.d.ts.map +1 -0
  19. package/dist/components/session/AssignedSessionFilter.js +90 -0
  20. package/dist/context/ChatContext.d.ts +4 -71
  21. package/dist/context/ChatContext.d.ts.map +1 -1
  22. package/dist/context/ChatContext.js +33 -344
  23. package/dist/hooks/conversation/useConversation.d.ts +11 -0
  24. package/dist/hooks/conversation/useConversation.d.ts.map +1 -0
  25. package/dist/hooks/conversation/useConversation.js +51 -0
  26. package/dist/hooks/message/useMessage.d.ts +9 -0
  27. package/dist/hooks/message/useMessage.d.ts.map +1 -0
  28. package/dist/hooks/message/useMessage.js +46 -0
  29. package/dist/hooks/message/useSendMessage.d.ts +10 -0
  30. package/dist/hooks/message/useSendMessage.d.ts.map +1 -0
  31. package/dist/hooks/message/useSendMessage.js +42 -0
  32. package/dist/index.d.ts +9 -26
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +10 -27
  35. package/dist/screens/desk-message/index.d.ts +3 -0
  36. package/dist/screens/desk-message/index.d.ts.map +1 -0
  37. package/dist/screens/desk-message/index.js +14 -0
  38. package/dist/types/chat.d.ts +6 -36
  39. package/dist/types/chat.d.ts.map +1 -1
  40. package/dist/types/index.d.ts +0 -85
  41. package/dist/types/index.d.ts.map +1 -1
  42. package/dist/types/index.js +1 -1
  43. package/dist/types/sdk.d.ts +1 -0
  44. package/dist/types/sdk.d.ts.map +1 -0
  45. package/dist/types/sdk.js +1 -0
  46. package/package.json +19 -3
  47. package/dist/components/AutoScrollAnchor.d.ts +0 -2
  48. package/dist/components/AutoScrollAnchor.d.ts.map +0 -1
  49. package/dist/components/AutoScrollAnchor.js +0 -12
  50. package/dist/components/AutoScrollAnchor.jsx +0 -11
  51. package/dist/components/ChatBubble.jsx +0 -80
  52. package/dist/components/ChatHeader.d.ts +0 -8
  53. package/dist/components/ChatHeader.d.ts.map +0 -1
  54. package/dist/components/ChatHeader.js +0 -32
  55. package/dist/components/ChatHeader.jsx +0 -72
  56. package/dist/components/ChatInput.d.ts +0 -3
  57. package/dist/components/ChatInput.d.ts.map +0 -1
  58. package/dist/components/ChatInput.js +0 -379
  59. package/dist/components/ChatInput.jsx +0 -444
  60. package/dist/components/ChatInputDemo.d.ts +0 -2
  61. package/dist/components/ChatInputDemo.d.ts.map +0 -1
  62. package/dist/components/ChatInputDemo.js +0 -38
  63. package/dist/components/ChatInputDemo.jsx +0 -53
  64. package/dist/components/ChatInputWithCustomIcon.d.ts +0 -16
  65. package/dist/components/ChatInputWithCustomIcon.d.ts.map +0 -1
  66. package/dist/components/ChatInputWithCustomIcon.js +0 -85
  67. package/dist/components/ChatInputWithCustomIcon.jsx +0 -167
  68. package/dist/components/ChatLayout.d.ts +0 -6
  69. package/dist/components/ChatLayout.d.ts.map +0 -1
  70. package/dist/components/ChatLayout.js +0 -48
  71. package/dist/components/ChatLayout.jsx +0 -122
  72. package/dist/components/ConversationItem.d.ts +0 -9
  73. package/dist/components/ConversationItem.d.ts.map +0 -1
  74. package/dist/components/ConversationItem.js +0 -27
  75. package/dist/components/ConversationItem.jsx +0 -51
  76. package/dist/components/ConversationList.d.ts +0 -8
  77. package/dist/components/ConversationList.d.ts.map +0 -1
  78. package/dist/components/ConversationList.js +0 -11
  79. package/dist/components/ConversationList.jsx +0 -22
  80. package/dist/components/DateDivider.d.ts +0 -7
  81. package/dist/components/DateDivider.d.ts.map +0 -1
  82. package/dist/components/DateDivider.js +0 -27
  83. package/dist/components/DateDivider.jsx +0 -28
  84. package/dist/components/EmojiPicker.d.ts +0 -4
  85. package/dist/components/EmojiPicker.d.ts.map +0 -1
  86. package/dist/components/EmojiPicker.js +0 -191
  87. package/dist/components/EmojiPicker.jsx +0 -229
  88. package/dist/components/ImageLightbox.d.ts +0 -8
  89. package/dist/components/ImageLightbox.d.ts.map +0 -1
  90. package/dist/components/ImageLightbox.js +0 -8
  91. package/dist/components/ImageLightbox.jsx +0 -16
  92. package/dist/components/ImagePreviewModal.d.ts +0 -12
  93. package/dist/components/ImagePreviewModal.d.ts.map +0 -1
  94. package/dist/components/ImagePreviewModal.js +0 -55
  95. package/dist/components/ImagePreviewModal.jsx +0 -84
  96. package/dist/components/MessageItem.d.ts +0 -3
  97. package/dist/components/MessageItem.d.ts.map +0 -1
  98. package/dist/components/MessageItem.js +0 -38
  99. package/dist/components/MessageItem.jsx +0 -99
  100. package/dist/components/MessageItemDemo.d.ts +0 -2
  101. package/dist/components/MessageItemDemo.d.ts.map +0 -1
  102. package/dist/components/MessageItemDemo.js +0 -166
  103. package/dist/components/MessageItemDemo.jsx +0 -179
  104. package/dist/components/MessageList.d.ts +0 -15
  105. package/dist/components/MessageList.d.ts.map +0 -1
  106. package/dist/components/MessageList.js +0 -243
  107. package/dist/components/MessageList.jsx +0 -306
  108. package/dist/components/MessageListDemo.d.ts +0 -2
  109. package/dist/components/MessageListDemo.d.ts.map +0 -1
  110. package/dist/components/MessageListDemo.js +0 -165
  111. package/dist/components/MessageListDemo.jsx +0 -183
  112. package/dist/components/StickerPicker.d.ts +0 -4
  113. package/dist/components/StickerPicker.d.ts.map +0 -1
  114. package/dist/components/StickerPicker.js +0 -68
  115. package/dist/components/StickerPicker.jsx +0 -106
  116. package/dist/components/SwipeIndicator.d.ts +0 -9
  117. package/dist/components/SwipeIndicator.d.ts.map +0 -1
  118. package/dist/components/SwipeIndicator.js +0 -24
  119. package/dist/components/SwipeIndicator.jsx +0 -28
  120. package/dist/components/TextFormattingToolbar.d.ts +0 -4
  121. package/dist/components/TextFormattingToolbar.d.ts.map +0 -1
  122. package/dist/components/TextFormattingToolbar.js +0 -29
  123. package/dist/components/TextFormattingToolbar.jsx +0 -52
  124. package/dist/components/TypingIndicator.d.ts +0 -6
  125. package/dist/components/TypingIndicator.d.ts.map +0 -1
  126. package/dist/components/TypingIndicator.js +0 -21
  127. package/dist/components/TypingIndicator.jsx +0 -27
  128. package/dist/components/VoiceWaveIcon.d.ts +0 -7
  129. package/dist/components/VoiceWaveIcon.d.ts.map +0 -1
  130. package/dist/components/VoiceWaveIcon.js +0 -5
  131. package/dist/components/VoiceWaveIcon.jsx +0 -11
  132. package/dist/context/ChatContext.jsx +0 -346
  133. package/dist/hooks/useChat.d.ts +0 -5
  134. package/dist/hooks/useChat.d.ts.map +0 -1
  135. package/dist/hooks/useChat.js +0 -73
  136. package/dist/hooks/useConversationList.d.ts +0 -5
  137. package/dist/hooks/useConversationList.d.ts.map +0 -1
  138. package/dist/hooks/useConversationList.js +0 -9
  139. package/dist/hooks/useMessages.d.ts +0 -5
  140. package/dist/hooks/useMessages.d.ts.map +0 -1
  141. package/dist/hooks/useMessages.js +0 -192
  142. package/dist/hooks/useSocket.d.ts +0 -7
  143. package/dist/hooks/useSocket.d.ts.map +0 -1
  144. package/dist/hooks/useSocket.js +0 -120
  145. package/dist/hooks/useSwipeGesture.d.ts +0 -11
  146. package/dist/hooks/useSwipeGesture.d.ts.map +0 -1
  147. package/dist/hooks/useSwipeGesture.js +0 -54
  148. package/dist/hooks/useTextSelection.d.ts +0 -13
  149. package/dist/hooks/useTextSelection.d.ts.map +0 -1
  150. package/dist/hooks/useTextSelection.js +0 -132
  151. package/dist/hooks/useTyping.d.ts +0 -7
  152. package/dist/hooks/useTyping.d.ts.map +0 -1
  153. package/dist/hooks/useTyping.js +0 -64
@@ -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,6 +0,0 @@
1
- interface TypingIndicatorProps {
2
- conversationId: string;
3
- }
4
- export declare function TypingIndicator({ conversationId }: TypingIndicatorProps): import("react/jsx-runtime").JSX.Element | null;
5
- export {};
6
- //# sourceMappingURL=TypingIndicator.d.ts.map
@@ -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,7 +0,0 @@
1
- interface VoiceWaveIconProps {
2
- className?: string;
3
- animated?: boolean;
4
- }
5
- export declare function VoiceWaveIcon({ className, animated }: VoiceWaveIconProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
7
- //# sourceMappingURL=VoiceWaveIcon.d.ts.map
@@ -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,346 +0,0 @@
1
- "use client";
2
- import { createContext, useContext, useReducer, useEffect } from "react";
3
- const initialState = {
4
- config: null,
5
- conversations: [],
6
- messages: {},
7
- users: {},
8
- typingStatuses: [],
9
- currentUser: null,
10
- isConnected: false,
11
- };
12
- function chatReducer(state, action) {
13
- switch (action.type) {
14
- case "SET_CONFIG":
15
- return Object.assign(Object.assign({}, state), { config: action.payload });
16
- case "SET_CONVERSATIONS":
17
- return Object.assign(Object.assign({}, state), { conversations: action.payload });
18
- case "ADD_CONVERSATION":
19
- return Object.assign(Object.assign({}, state), { conversations: [action.payload, ...state.conversations] });
20
- case "UPDATE_CONVERSATION":
21
- return Object.assign(Object.assign({}, state), { conversations: state.conversations.map((conv) => (conv.id === action.payload.id ? action.payload : conv)) });
22
- case "SET_MESSAGES":
23
- return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [action.payload.conversationId]: action.payload.messages }) });
24
- case "ADD_MESSAGE":
25
- const conversationId = action.payload.conversationId;
26
- return Object.assign(Object.assign({}, state), { messages: Object.assign(Object.assign({}, state.messages), { [conversationId]: [...(state.messages[conversationId] || []), action.payload] }) });
27
- case "UPDATE_MESSAGE":
28
- 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) }) });
29
- case "SET_USERS":
30
- return Object.assign(Object.assign({}, state), { users: action.payload });
31
- case "UPDATE_USER":
32
- return Object.assign(Object.assign({}, state), { users: Object.assign(Object.assign({}, state.users), { [action.payload.id]: action.payload }) });
33
- case "SET_TYPING":
34
- return Object.assign(Object.assign({}, state), { typingStatuses: [
35
- ...state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)),
36
- action.payload,
37
- ] });
38
- case "REMOVE_TYPING":
39
- return Object.assign(Object.assign({}, state), { typingStatuses: state.typingStatuses.filter((t) => !(t.userId === action.payload.userId && t.conversationId === action.payload.conversationId)) });
40
- case "SET_CONNECTION_STATUS":
41
- return Object.assign(Object.assign({}, state), { isConnected: action.payload });
42
- default:
43
- return state;
44
- }
45
- }
46
- const ChatContext = createContext(null);
47
- export function useChatContext() {
48
- const context = useContext(ChatContext);
49
- if (!context) {
50
- throw new Error("useChatContext must be used within a ChatProvider");
51
- }
52
- return context;
53
- }
54
- export function ChatProvider({ children, userId, token, onTokenRefresh, websocketUrl = "demo", // Use "demo" as default to disable WebSocket
55
- enableWebSocket = false, // Disabled by default for demo
56
- }) {
57
- const [state, dispatch] = useReducer(chatReducer, initialState);
58
- // Initialize config
59
- useEffect(() => {
60
- const config = {
61
- userId,
62
- token,
63
- wsUrl: enableWebSocket ? websocketUrl : "demo",
64
- onTokenRefresh,
65
- };
66
- dispatch({ type: "SET_CONFIG", payload: config });
67
- // Initialize current user
68
- const currentUser = {
69
- id: userId,
70
- name: "You",
71
- status: "online",
72
- };
73
- dispatch({ type: "UPDATE_USER", payload: currentUser });
74
- }, [userId, token, websocketUrl, onTokenRefresh, enableWebSocket]);
75
- // Initialize with mock data for demo - MORE CONVERSATIONS
76
- useEffect(() => {
77
- if (!state.config)
78
- return;
79
- const mockUsers = {
80
- [userId]: {
81
- id: userId,
82
- name: "You",
83
- status: "online",
84
- },
85
- "user-2": {
86
- id: "user-2",
87
- name: "Alice Johnson",
88
- status: "online",
89
- avatar: "/placeholder.svg?height=40&width=40",
90
- },
91
- "user-3": {
92
- id: "user-3",
93
- name: "Bob Smith",
94
- status: "offline",
95
- avatar: "/placeholder.svg?height=40&width=40",
96
- lastSeen: new Date(Date.now() - 7200000),
97
- },
98
- "user-4": {
99
- id: "user-4",
100
- name: "Carol Davis",
101
- status: "online",
102
- avatar: "/placeholder.svg?height=40&width=40",
103
- },
104
- "user-5": {
105
- id: "user-5",
106
- name: "David Wilson",
107
- status: "away",
108
- avatar: "/placeholder.svg?height=40&width=40",
109
- lastSeen: new Date(Date.now() - 1800000),
110
- },
111
- "user-6": {
112
- id: "user-6",
113
- name: "Emma Brown",
114
- status: "online",
115
- avatar: "/placeholder.svg?height=40&width=40",
116
- },
117
- "user-7": {
118
- id: "user-7",
119
- name: "Frank Miller",
120
- status: "offline",
121
- avatar: "/placeholder.svg?height=40&width=40",
122
- lastSeen: new Date(Date.now() - 86400000),
123
- },
124
- "user-8": {
125
- id: "user-8",
126
- name: "Grace Lee",
127
- status: "online",
128
- avatar: "/placeholder.svg?height=40&width=40",
129
- },
130
- "user-9": {
131
- id: "user-9",
132
- name: "Henry Taylor",
133
- status: "away",
134
- avatar: "/placeholder.svg?height=40&width=40",
135
- lastSeen: new Date(Date.now() - 3600000),
136
- },
137
- "user-10": {
138
- id: "user-10",
139
- name: "Ivy Chen",
140
- status: "online",
141
- avatar: "/placeholder.svg?height=40&width=40",
142
- },
143
- "group-1": {
144
- id: "group-1",
145
- name: "Team Project",
146
- status: "online",
147
- avatar: "/placeholder.svg?height=40&width=40",
148
- },
149
- "group-2": {
150
- id: "group-2",
151
- name: "Family Chat",
152
- status: "online",
153
- avatar: "/placeholder.svg?height=40&width=40",
154
- },
155
- };
156
- const mockConversations = [
157
- {
158
- id: "conv-1",
159
- participants: [mockUsers["user-2"], mockUsers[userId]],
160
- unreadCount: 2,
161
- updatedAt: new Date(Date.now() - 300000), // 5 minutes ago
162
- type: "direct",
163
- lastMessage: {
164
- id: "msg-1",
165
- conversationId: "conv-1",
166
- senderId: "user-2",
167
- content: "Hey there! How are you doing? 😊",
168
- type: "text",
169
- timestamp: new Date(Date.now() - 300000),
170
- status: "delivered",
171
- },
172
- },
173
- {
174
- id: "conv-2",
175
- participants: [mockUsers["user-3"], mockUsers[userId]],
176
- unreadCount: 0,
177
- updatedAt: new Date(Date.now() - 1800000), // 30 minutes ago
178
- type: "direct",
179
- lastMessage: {
180
- id: "msg-2",
181
- conversationId: "conv-2",
182
- senderId: userId,
183
- content: "Thanks for the help earlier!",
184
- type: "text",
185
- timestamp: new Date(Date.now() - 1800000),
186
- status: "read",
187
- },
188
- },
189
- {
190
- id: "conv-3",
191
- participants: [mockUsers["user-4"], mockUsers[userId]],
192
- unreadCount: 1,
193
- updatedAt: new Date(Date.now() - 3600000), // 1 hour ago
194
- type: "direct",
195
- lastMessage: {
196
- id: "msg-3",
197
- conversationId: "conv-3",
198
- senderId: "user-4",
199
- content: "Can you review this document?",
200
- type: "file",
201
- timestamp: new Date(Date.now() - 3600000),
202
- status: "delivered",
203
- },
204
- },
205
- {
206
- id: "conv-4",
207
- participants: [mockUsers["user-5"], mockUsers[userId]],
208
- unreadCount: 0,
209
- updatedAt: new Date(Date.now() - 7200000), // 2 hours ago
210
- type: "direct",
211
- lastMessage: {
212
- id: "msg-4",
213
- conversationId: "conv-4",
214
- senderId: userId,
215
- content: "See you tomorrow!",
216
- type: "text",
217
- timestamp: new Date(Date.now() - 7200000),
218
- status: "read",
219
- },
220
- },
221
- {
222
- id: "conv-5",
223
- participants: [mockUsers["user-6"], mockUsers[userId]],
224
- unreadCount: 3,
225
- updatedAt: new Date(Date.now() - 10800000), // 3 hours ago
226
- type: "direct",
227
- lastMessage: {
228
- id: "msg-5",
229
- conversationId: "conv-5",
230
- senderId: "user-6",
231
- content: "Check out these photos from the event!",
232
- type: "image",
233
- timestamp: new Date(Date.now() - 10800000),
234
- status: "delivered",
235
- },
236
- },
237
- {
238
- id: "conv-6",
239
- participants: [mockUsers["user-7"], mockUsers[userId]],
240
- unreadCount: 0,
241
- updatedAt: new Date(Date.now() - 86400000), // 1 day ago
242
- type: "direct",
243
- lastMessage: {
244
- id: "msg-6",
245
- conversationId: "conv-6",
246
- senderId: "user-7",
247
- content: "Happy birthday! 🎉",
248
- type: "text",
249
- timestamp: new Date(Date.now() - 86400000),
250
- status: "read",
251
- },
252
- },
253
- {
254
- id: "conv-7",
255
- participants: [mockUsers["user-8"], mockUsers[userId]],
256
- unreadCount: 0,
257
- updatedAt: new Date(Date.now() - 172800000), // 2 days ago
258
- type: "direct",
259
- lastMessage: {
260
- id: "msg-7",
261
- conversationId: "conv-7",
262
- senderId: userId,
263
- content: "Thanks for the coffee recommendation!",
264
- type: "text",
265
- timestamp: new Date(Date.now() - 172800000),
266
- status: "read",
267
- },
268
- },
269
- {
270
- id: "conv-8",
271
- participants: [mockUsers["user-9"], mockUsers[userId]],
272
- unreadCount: 1,
273
- updatedAt: new Date(Date.now() - 259200000), // 3 days ago
274
- type: "direct",
275
- lastMessage: {
276
- id: "msg-8",
277
- conversationId: "conv-8",
278
- senderId: "user-9",
279
- content: "Let's schedule a meeting next week",
280
- type: "text",
281
- timestamp: new Date(Date.now() - 259200000),
282
- status: "delivered",
283
- },
284
- },
285
- {
286
- id: "conv-9",
287
- participants: [mockUsers["user-10"], mockUsers[userId]],
288
- unreadCount: 0,
289
- updatedAt: new Date(Date.now() - 345600000), // 4 days ago
290
- type: "direct",
291
- lastMessage: {
292
- id: "msg-9",
293
- conversationId: "conv-9",
294
- senderId: userId,
295
- content: "Great presentation today!",
296
- type: "text",
297
- timestamp: new Date(Date.now() - 345600000),
298
- status: "read",
299
- },
300
- },
301
- {
302
- id: "group-conv-1",
303
- participants: [mockUsers["group-1"], mockUsers[userId], mockUsers["user-2"], mockUsers["user-4"]],
304
- unreadCount: 5,
305
- updatedAt: new Date(Date.now() - 600000), // 10 minutes ago
306
- type: "group",
307
- name: "Team Project",
308
- avatar: "/placeholder.svg?height=40&width=40",
309
- lastMessage: {
310
- id: "msg-group-1",
311
- conversationId: "group-conv-1",
312
- senderId: "user-4",
313
- content: "The deadline has been moved to Friday",
314
- type: "text",
315
- timestamp: new Date(Date.now() - 600000),
316
- status: "delivered",
317
- },
318
- },
319
- {
320
- id: "group-conv-2",
321
- participants: [mockUsers["group-2"], mockUsers[userId], mockUsers["user-6"], mockUsers["user-8"]],
322
- unreadCount: 0,
323
- updatedAt: new Date(Date.now() - 432000000), // 5 days ago
324
- type: "group",
325
- name: "Family Chat",
326
- avatar: "/placeholder.svg?height=40&width=40",
327
- lastMessage: {
328
- id: "msg-group-2",
329
- conversationId: "group-conv-2",
330
- senderId: "user-6",
331
- content: "Looking forward to the reunion!",
332
- type: "text",
333
- timestamp: new Date(Date.now() - 432000000),
334
- status: "read",
335
- },
336
- },
337
- ];
338
- dispatch({ type: "SET_USERS", payload: mockUsers });
339
- dispatch({ type: "SET_CONVERSATIONS", payload: mockConversations });
340
- }, [state.config, userId]);
341
- const value = {
342
- state,
343
- dispatch,
344
- };
345
- return <ChatContext.Provider value={value}>{children}</ChatContext.Provider>;
346
- }
@@ -1,5 +0,0 @@
1
- export declare function useChat(conversationId: string): {
2
- sendMessage: (content: string, type?: "text" | "image" | "file") => Promise<void>;
3
- markAsRead: (messageId: string) => Promise<void>;
4
- };
5
- //# sourceMappingURL=useChat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":"AAOA,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM;2BAK1B,MAAM,SAAQ,MAAM,GAAG,OAAO,GAAG,MAAM;4BA6DrC,MAAM;EAmB3B"}
@@ -1,73 +0,0 @@
1
- "use client";
2
- import { useCallback } from "react";
3
- import { useChatContext } from "../context/ChatContext";
4
- import { useSocket } from "./useSocket";
5
- export function useChat(conversationId) {
6
- const { state, dispatch } = useChatContext();
7
- const { sendMessage: sendSocketMessage, isConnected } = useSocket();
8
- const sendMessage = useCallback(async (content, type = "text") => {
9
- var _a;
10
- if (!((_a = state.config) === null || _a === void 0 ? void 0 : _a.userId) || !conversationId)
11
- return;
12
- const message = {
13
- id: `msg-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
14
- conversationId,
15
- senderId: state.config.userId,
16
- content,
17
- type,
18
- timestamp: new Date(),
19
- status: "sending",
20
- };
21
- // Add message optimistically
22
- dispatch({ type: "ADD_MESSAGE", payload: message });
23
- try {
24
- // Try to send via WebSocket if connected
25
- const socketSent = sendSocketMessage({
26
- type: "message",
27
- data: message,
28
- });
29
- // Update message status
30
- const updatedMessage = Object.assign(Object.assign({}, message), { status: (socketSent && isConnected ? "sent" : "delivered") });
31
- // Simulate a small delay for better UX
32
- setTimeout(() => {
33
- dispatch({
34
- type: "UPDATE_MESSAGE",
35
- payload: updatedMessage,
36
- });
37
- }, 100);
38
- // Update conversation's last message
39
- const conversation = state.conversations.find((c) => c.id === conversationId);
40
- if (conversation) {
41
- dispatch({
42
- type: "UPDATE_CONVERSATION",
43
- payload: Object.assign(Object.assign({}, conversation), { lastMessage: updatedMessage, updatedAt: new Date() }),
44
- });
45
- }
46
- }
47
- catch (error) {
48
- console.error("Failed to send message:", error);
49
- dispatch({
50
- type: "UPDATE_MESSAGE",
51
- payload: Object.assign(Object.assign({}, message), { status: "delivered" }), // Still mark as delivered for demo
52
- });
53
- }
54
- }, [state.config, conversationId, dispatch, sendSocketMessage, isConnected, state.conversations]);
55
- const markAsRead = useCallback(async (messageId) => {
56
- var _a;
57
- if (!((_a = state.config) === null || _a === void 0 ? void 0 : _a.token))
58
- return;
59
- try {
60
- sendSocketMessage({
61
- type: "read",
62
- data: { messageId, conversationId },
63
- });
64
- }
65
- catch (error) {
66
- console.error("Failed to mark message as read:", error);
67
- }
68
- }, [state.config, conversationId, sendSocketMessage]);
69
- return {
70
- sendMessage,
71
- markAsRead,
72
- };
73
- }
@@ -1,5 +0,0 @@
1
- export declare function useConversationList(): {
2
- conversations: import("..").Conversation[];
3
- isLoading: boolean;
4
- };
5
- //# sourceMappingURL=useConversationList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useConversationList.d.ts","sourceRoot":"","sources":["../../src/hooks/useConversationList.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB;;;EAOlC"}
@@ -1,9 +0,0 @@
1
- "use client";
2
- import { useChatContext } from "../context/ChatContext";
3
- export function useConversationList() {
4
- const { state } = useChatContext();
5
- return {
6
- conversations: state.conversations || [],
7
- isLoading: false,
8
- };
9
- }
@@ -1,5 +0,0 @@
1
- export declare function useMessages(conversationId: string): {
2
- messages: import("..").Message[];
3
- isLoading: boolean;
4
- };
5
- //# sourceMappingURL=useMessages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMessages.d.ts","sourceRoot":"","sources":["../../src/hooks/useMessages.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM;;;EA+LjD"}