@messenger-box/tailwind-ui-inbox 10.0.3-alpha.100

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 (373) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/LICENSE +21 -0
  3. package/jest.config.js +9 -0
  4. package/lib/cdm-locales/en/translations.json +31 -0
  5. package/lib/cdm-locales/es/translations.json +31 -0
  6. package/lib/components/AIAgent/AIAgent.d.ts +21 -0
  7. package/lib/components/AIAgent/AIAgent.d.ts.map +1 -0
  8. package/lib/components/AIAgent/AIAgent.js +904 -0
  9. package/lib/components/AIAgent/AIAgent.js.map +1 -0
  10. package/lib/components/AIAgent/index.d.ts +2 -0
  11. package/lib/components/AIAgent/index.d.ts.map +1 -0
  12. package/lib/components/InboxMessage/CommonMessage.d.ts +8 -0
  13. package/lib/components/InboxMessage/CommonMessage.d.ts.map +1 -0
  14. package/lib/components/InboxMessage/CommonMessage.js +35 -0
  15. package/lib/components/InboxMessage/CommonMessage.js.map +1 -0
  16. package/lib/components/InboxMessage/ConversationItem.d.ts +14 -0
  17. package/lib/components/InboxMessage/ConversationItem.d.ts.map +1 -0
  18. package/lib/components/InboxMessage/ConversationItem.js +200 -0
  19. package/lib/components/InboxMessage/ConversationItem.js.map +1 -0
  20. package/lib/components/InboxMessage/InputComponent.d.ts +12 -0
  21. package/lib/components/InboxMessage/InputComponent.d.ts.map +1 -0
  22. package/lib/components/InboxMessage/InputComponent.js +359 -0
  23. package/lib/components/InboxMessage/InputComponent.js.map +1 -0
  24. package/lib/components/InboxMessage/LeftSidebar.d.ts +20 -0
  25. package/lib/components/InboxMessage/LeftSidebar.d.ts.map +1 -0
  26. package/lib/components/InboxMessage/LeftSidebar.js +102 -0
  27. package/lib/components/InboxMessage/LeftSidebar.js.map +1 -0
  28. package/lib/components/InboxMessage/MessageInput.d.ts +9 -0
  29. package/lib/components/InboxMessage/MessageInput.d.ts.map +1 -0
  30. package/lib/components/InboxMessage/MessageInput.js +154 -0
  31. package/lib/components/InboxMessage/MessageInput.js.map +1 -0
  32. package/lib/components/InboxMessage/MessageInputComponent.d.ts +9 -0
  33. package/lib/components/InboxMessage/MessageInputComponent.d.ts.map +1 -0
  34. package/lib/components/InboxMessage/Messages.d.ts +17 -0
  35. package/lib/components/InboxMessage/Messages.d.ts.map +1 -0
  36. package/lib/components/InboxMessage/Messages.js +99 -0
  37. package/lib/components/InboxMessage/Messages.js.map +1 -0
  38. package/lib/components/InboxMessage/MessagesBuilderUi.d.ts +17 -0
  39. package/lib/components/InboxMessage/MessagesBuilderUi.d.ts.map +1 -0
  40. package/lib/components/InboxMessage/Popover.d.ts +3 -0
  41. package/lib/components/InboxMessage/Popover.d.ts.map +1 -0
  42. package/lib/components/InboxMessage/Popover.js +31 -0
  43. package/lib/components/InboxMessage/Popover.js.map +1 -0
  44. package/lib/components/InboxMessage/RightSidebar.d.ts +9 -0
  45. package/lib/components/InboxMessage/RightSidebar.d.ts.map +1 -0
  46. package/lib/components/InboxMessage/RightSidebar.js +9 -0
  47. package/lib/components/InboxMessage/RightSidebar.js.map +1 -0
  48. package/lib/components/InboxMessage/RightSidebarAi.d.ts +23 -0
  49. package/lib/components/InboxMessage/RightSidebarAi.d.ts.map +1 -0
  50. package/lib/components/InboxMessage/RightSidebarAi.js +9 -0
  51. package/lib/components/InboxMessage/RightSidebarAi.js.map +1 -0
  52. package/lib/components/InboxMessage/ServiceConversationItem.d.ts +12 -0
  53. package/lib/components/InboxMessage/ServiceConversationItem.d.ts.map +1 -0
  54. package/lib/components/InboxMessage/ServiceConversationItem.js +185 -0
  55. package/lib/components/InboxMessage/ServiceConversationItem.js.map +1 -0
  56. package/lib/components/InboxMessage/ServiceInboxItem.d.ts +12 -0
  57. package/lib/components/InboxMessage/ServiceInboxItem.d.ts.map +1 -0
  58. package/lib/components/InboxMessage/ServiceInboxItem.js +182 -0
  59. package/lib/components/InboxMessage/ServiceInboxItem.js.map +1 -0
  60. package/lib/components/InboxMessage/SubscriptionHandler.d.ts +19 -0
  61. package/lib/components/InboxMessage/SubscriptionHandler.d.ts.map +1 -0
  62. package/lib/components/InboxMessage/SubscriptionHandler.js +41 -0
  63. package/lib/components/InboxMessage/SubscriptionHandler.js.map +1 -0
  64. package/lib/components/InboxMessage/UploadImageButton.d.ts +7 -0
  65. package/lib/components/InboxMessage/UploadImageButton.d.ts.map +1 -0
  66. package/lib/components/InboxMessage/UploadImageButton.js +34 -0
  67. package/lib/components/InboxMessage/UploadImageButton.js.map +1 -0
  68. package/lib/components/InboxMessage/UserModalContent.d.ts +3 -0
  69. package/lib/components/InboxMessage/UserModalContent.d.ts.map +1 -0
  70. package/lib/components/InboxMessage/UserModalContent.js +60 -0
  71. package/lib/components/InboxMessage/UserModalContent.js.map +1 -0
  72. package/lib/components/InboxMessage/index.d.ts +17 -0
  73. package/lib/components/InboxMessage/index.d.ts.map +1 -0
  74. package/lib/components/InboxMessage/message-widgets/CommonMessage.d.ts +11 -0
  75. package/lib/components/InboxMessage/message-widgets/CommonMessage.d.ts.map +1 -0
  76. package/lib/components/InboxMessage/message-widgets/CommonMessage.js +44 -0
  77. package/lib/components/InboxMessage/message-widgets/CommonMessage.js.map +1 -0
  78. package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts +11 -0
  79. package/lib/components/InboxMessage/message-widgets/ErrorFixCard.d.ts.map +1 -0
  80. package/lib/components/InboxMessage/message-widgets/ErrorFixCard.js +194 -0
  81. package/lib/components/InboxMessage/message-widgets/ErrorFixCard.js.map +1 -0
  82. package/lib/components/InboxMessage/message-widgets/MessageCard.d.ts +8 -0
  83. package/lib/components/InboxMessage/message-widgets/MessageCard.d.ts.map +1 -0
  84. package/lib/components/InboxMessage/message-widgets/MessageSliceRenderer.d.ts +12 -0
  85. package/lib/components/InboxMessage/message-widgets/MessageSliceRenderer.d.ts.map +1 -0
  86. package/lib/components/InboxMessage/message-widgets/MessageSliceRenderer.js +37 -0
  87. package/lib/components/InboxMessage/message-widgets/MessageSliceRenderer.js.map +1 -0
  88. package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts +18 -0
  89. package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.d.ts.map +1 -0
  90. package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js +1082 -0
  91. package/lib/components/InboxMessage/message-widgets/ModernMessageGroup.js.map +1 -0
  92. package/lib/components/InboxMessage/message-widgets/PlainMessage.d.ts +8 -0
  93. package/lib/components/InboxMessage/message-widgets/PlainMessage.d.ts.map +1 -0
  94. package/lib/components/InboxMessage/message-widgets/PlainMessage.js +14 -0
  95. package/lib/components/InboxMessage/message-widgets/PlainMessage.js.map +1 -0
  96. package/lib/components/InboxMessage/message-widgets/PropertyMessageWidget.d.ts +9 -0
  97. package/lib/components/InboxMessage/message-widgets/PropertyMessageWidget.d.ts.map +1 -0
  98. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts +14 -0
  99. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts.map +1 -0
  100. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js +333 -0
  101. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js.map +1 -0
  102. package/lib/components/InboxMessage/message-widgets/index.d.ts +4 -0
  103. package/lib/components/InboxMessage/message-widgets/index.d.ts.map +1 -0
  104. package/lib/components/ModelConfigPanel.d.ts +37 -0
  105. package/lib/components/ModelConfigPanel.d.ts.map +1 -0
  106. package/lib/components/ModelConfigPanel.js +317 -0
  107. package/lib/components/ModelConfigPanel.js.map +1 -0
  108. package/lib/components/filler-components/RightSiderBar.d.ts +24 -0
  109. package/lib/components/filler-components/RightSiderBar.d.ts.map +1 -0
  110. package/lib/components/filler-components/RightSiderBar.js +335 -0
  111. package/lib/components/filler-components/RightSiderBar.js.map +1 -0
  112. package/lib/components/inbox/FilesList.d.ts +20 -0
  113. package/lib/components/inbox/FilesList.d.ts.map +1 -0
  114. package/lib/components/inbox/FilesList.js +68 -0
  115. package/lib/components/inbox/FilesList.js.map +1 -0
  116. package/lib/components/inbox/MessageItem.d.ts +17 -0
  117. package/lib/components/inbox/MessageItem.d.ts.map +1 -0
  118. package/lib/components/inbox/MessageItem.js +50 -0
  119. package/lib/components/inbox/MessageItem.js.map +1 -0
  120. package/lib/components/inbox/ThreadItem.d.ts +11 -0
  121. package/lib/components/inbox/ThreadItem.d.ts.map +1 -0
  122. package/lib/components/inbox/ThreadItem.js +147 -0
  123. package/lib/components/inbox/ThreadItem.js.map +1 -0
  124. package/lib/components/inbox/index.d.ts +4 -0
  125. package/lib/components/inbox/index.d.ts.map +1 -0
  126. package/lib/components/index.d.ts +7 -0
  127. package/lib/components/index.d.ts.map +1 -0
  128. package/lib/components/live-code-editor/hybrid-live-editor.d.ts +20 -0
  129. package/lib/components/live-code-editor/hybrid-live-editor.d.ts.map +1 -0
  130. package/lib/components/live-code-editor/hybrid-live-editor.js +68 -0
  131. package/lib/components/live-code-editor/hybrid-live-editor.js.map +1 -0
  132. package/lib/components/live-code-editor/index.d.ts +4 -0
  133. package/lib/components/live-code-editor/index.d.ts.map +1 -0
  134. package/lib/components/live-code-editor/live-code-editor.d.ts +14 -0
  135. package/lib/components/live-code-editor/live-code-editor.d.ts.map +1 -0
  136. package/lib/components/live-code-editor/live-code-editor.js +207 -0
  137. package/lib/components/live-code-editor/live-code-editor.js.map +1 -0
  138. package/lib/components/slot-fill/chat-message-filler.d.ts +4 -0
  139. package/lib/components/slot-fill/chat-message-filler.d.ts.map +1 -0
  140. package/lib/components/slot-fill/chat-message-filler.js +5 -0
  141. package/lib/components/slot-fill/chat-message-filler.js.map +1 -0
  142. package/lib/components/slot-fill/chat-message-slot.d.ts +11 -0
  143. package/lib/components/slot-fill/chat-message-slot.d.ts.map +1 -0
  144. package/lib/components/slot-fill/chat-message-slot.js +6 -0
  145. package/lib/components/slot-fill/chat-message-slot.js.map +1 -0
  146. package/lib/components/slot-fill/index.d.ts +4 -0
  147. package/lib/components/slot-fill/index.d.ts.map +1 -0
  148. package/lib/components/slot-fill/right-sidebar-filler.d.ts +4 -0
  149. package/lib/components/slot-fill/right-sidebar-filler.d.ts.map +1 -0
  150. package/lib/components/slot-fill/right-sidebar-filler.js +13 -0
  151. package/lib/components/slot-fill/right-sidebar-filler.js.map +1 -0
  152. package/lib/components/ui/button.d.ts +9 -0
  153. package/lib/components/ui/button.d.ts.map +1 -0
  154. package/lib/compute.d.ts +8 -0
  155. package/lib/compute.d.ts.map +1 -0
  156. package/lib/compute.js +137 -0
  157. package/lib/compute.js.map +1 -0
  158. package/lib/config/env-config.d.ts +13 -0
  159. package/lib/config/env-config.d.ts.map +1 -0
  160. package/lib/config/env-config.js +34 -0
  161. package/lib/config/env-config.js.map +1 -0
  162. package/lib/config/index.d.ts +2 -0
  163. package/lib/config/index.d.ts.map +1 -0
  164. package/lib/constants/breakpoints.d.ts +8 -0
  165. package/lib/constants/breakpoints.d.ts.map +1 -0
  166. package/lib/constants/index.d.ts +3 -0
  167. package/lib/constants/index.d.ts.map +1 -0
  168. package/lib/container/AiInbox.d.ts +15 -0
  169. package/lib/container/AiInbox.d.ts.map +1 -0
  170. package/lib/container/AiInboxWithLoader.d.ts +36 -0
  171. package/lib/container/AiInboxWithLoader.d.ts.map +1 -0
  172. package/lib/container/AiLandingInput.d.ts +4 -0
  173. package/lib/container/AiLandingInput.d.ts.map +1 -0
  174. package/lib/container/AiLandingInput.js +101 -0
  175. package/lib/container/AiLandingInput.js.map +1 -0
  176. package/lib/container/Inbox.d.ts +15 -0
  177. package/lib/container/Inbox.d.ts.map +1 -0
  178. package/lib/container/Inbox.js +955 -0
  179. package/lib/container/Inbox.js.map +1 -0
  180. package/lib/container/InboxAiMessagesLoader.d.ts +15 -0
  181. package/lib/container/InboxAiMessagesLoader.d.ts.map +1 -0
  182. package/lib/container/InboxAiMessagesLoader.js +30 -0
  183. package/lib/container/InboxAiMessagesLoader.js.map +1 -0
  184. package/lib/container/InboxContainer.d.ts +12 -0
  185. package/lib/container/InboxContainer.d.ts.map +1 -0
  186. package/lib/container/InboxContainer.js +31 -0
  187. package/lib/container/InboxContainer.js.map +1 -0
  188. package/lib/container/InboxTemplate1.d.ts +15 -0
  189. package/lib/container/InboxTemplate1.d.ts.map +1 -0
  190. package/lib/container/InboxTemplate1WithLoader.d.ts +36 -0
  191. package/lib/container/InboxTemplate1WithLoader.d.ts.map +1 -0
  192. package/lib/container/InboxTemplate2.d.ts +15 -0
  193. package/lib/container/InboxTemplate2.d.ts.map +1 -0
  194. package/lib/container/InboxWithAiLoader.d.ts +15 -0
  195. package/lib/container/InboxWithAiLoader.d.ts.map +1 -0
  196. package/lib/container/InboxWithAiLoader.js +56 -0
  197. package/lib/container/InboxWithAiLoader.js.map +1 -0
  198. package/lib/container/InboxWithLoader.d.ts +36 -0
  199. package/lib/container/InboxWithLoader.d.ts.map +1 -0
  200. package/lib/container/InboxWithLoader.js +277 -0
  201. package/lib/container/InboxWithLoader.js.map +1 -0
  202. package/lib/container/ServiceInbox.d.ts +9 -0
  203. package/lib/container/ServiceInbox.d.ts.map +1 -0
  204. package/lib/container/ServiceInbox.js +144 -0
  205. package/lib/container/ServiceInbox.js.map +1 -0
  206. package/lib/container/ThreadMessages.d.ts +13 -0
  207. package/lib/container/ThreadMessages.d.ts.map +1 -0
  208. package/lib/container/ThreadMessages.js +314 -0
  209. package/lib/container/ThreadMessages.js.map +1 -0
  210. package/lib/container/ThreadMessagesInbox.d.ts +14 -0
  211. package/lib/container/ThreadMessagesInbox.d.ts.map +1 -0
  212. package/lib/container/ThreadMessagesInbox.js +341 -0
  213. package/lib/container/ThreadMessagesInbox.js.map +1 -0
  214. package/lib/container/Threads.d.ts +8 -0
  215. package/lib/container/Threads.d.ts.map +1 -0
  216. package/lib/container/Threads.js +231 -0
  217. package/lib/container/Threads.js.map +1 -0
  218. package/lib/container/ThreadsInbox.d.ts +21 -0
  219. package/lib/container/ThreadsInbox.d.ts.map +1 -0
  220. package/lib/container/ThreadsInbox.js +244 -0
  221. package/lib/container/ThreadsInbox.js.map +1 -0
  222. package/lib/container/apply-footer-styles.d.ts +2 -0
  223. package/lib/container/apply-footer-styles.d.ts.map +1 -0
  224. package/lib/container/apply-footer-styles.js +16 -0
  225. package/lib/container/apply-footer-styles.js.map +1 -0
  226. package/lib/container/index.d.ts +13 -0
  227. package/lib/container/index.d.ts.map +1 -0
  228. package/lib/enums/index.d.ts +2 -0
  229. package/lib/enums/index.d.ts.map +1 -0
  230. package/lib/enums/messenger-slot-fill-name-enum.d.ts +5 -0
  231. package/lib/enums/messenger-slot-fill-name-enum.d.ts.map +1 -0
  232. package/lib/enums/messenger-slot-fill-name-enum.js +5 -0
  233. package/lib/enums/messenger-slot-fill-name-enum.js.map +1 -0
  234. package/lib/hooks/index.d.ts +3 -0
  235. package/lib/hooks/index.d.ts.map +1 -0
  236. package/lib/hooks/use-file-sync.d.ts +16 -0
  237. package/lib/hooks/use-file-sync.d.ts.map +1 -0
  238. package/lib/hooks/use-file-sync.js +63 -0
  239. package/lib/hooks/use-file-sync.js.map +1 -0
  240. package/lib/hooks/usePersistentModelConfig.d.ts +15 -0
  241. package/lib/hooks/usePersistentModelConfig.d.ts.map +1 -0
  242. package/lib/hooks/usePersistentModelConfig.js +46 -0
  243. package/lib/hooks/usePersistentModelConfig.js.map +1 -0
  244. package/lib/index.d.ts +10 -0
  245. package/lib/index.d.ts.map +1 -0
  246. package/lib/index.js +1 -0
  247. package/lib/index.js.map +1 -0
  248. package/lib/interfaces/index.d.ts +2 -0
  249. package/lib/interfaces/index.d.ts.map +1 -0
  250. package/lib/interfaces/message-widgets.interface.d.ts +21 -0
  251. package/lib/interfaces/message-widgets.interface.d.ts.map +1 -0
  252. package/lib/machines/aiAgentMachine.d.ts +3 -0
  253. package/lib/machines/aiAgentMachine.d.ts.map +1 -0
  254. package/lib/machines/aiAgentMachine.js +1083 -0
  255. package/lib/machines/aiAgentMachine.js.map +1 -0
  256. package/lib/machines/aiAgentMachine.simple.d.ts +3 -0
  257. package/lib/machines/aiAgentMachine.simple.d.ts.map +1 -0
  258. package/lib/machines/aiAgentMachine.simple.js +108 -0
  259. package/lib/machines/aiAgentMachine.simple.js.map +1 -0
  260. package/lib/machines/index.d.ts +3 -0
  261. package/lib/machines/index.d.ts.map +1 -0
  262. package/lib/machines/types.d.ts +77 -0
  263. package/lib/machines/types.d.ts.map +1 -0
  264. package/lib/module.d.ts +7 -0
  265. package/lib/module.d.ts.map +1 -0
  266. package/lib/module.js +26 -0
  267. package/lib/module.js.map +1 -0
  268. package/lib/routes.json +98 -0
  269. package/lib/styles/responsive.css +76 -0
  270. package/lib/templates/InboxWithAi.d.ts +15 -0
  271. package/lib/templates/InboxWithAi.d.ts.map +1 -0
  272. package/lib/templates/InboxWithAi.js +440 -0
  273. package/lib/templates/InboxWithAi.js.map +1 -0
  274. package/lib/templates/InboxWithAi.tsx +533 -0
  275. package/lib/templates/index.d.ts +2 -0
  276. package/lib/templates/index.d.ts.map +1 -0
  277. package/lib/templates/index.ts +1 -0
  278. package/lib/utils/utils.d.ts +2 -0
  279. package/lib/utils/utils.d.ts.map +1 -0
  280. package/lib/utils/utils.js +3 -0
  281. package/lib/utils/utils.js.map +1 -0
  282. package/package.json +62 -0
  283. package/rollup.config.mjs +35 -0
  284. package/src/cdm-locales/en/translations.json +31 -0
  285. package/src/cdm-locales/es/translations.json +31 -0
  286. package/src/components/AIAgent/AIAgent.tsx +1103 -0
  287. package/src/components/AIAgent/AIAgent.tsx.bk +1365 -0
  288. package/src/components/AIAgent/README.md +82 -0
  289. package/src/components/AIAgent/index.ts +1 -0
  290. package/src/components/InboxMessage/CommonMessage.tsx +40 -0
  291. package/src/components/InboxMessage/ConversationItem.tsx +255 -0
  292. package/src/components/InboxMessage/InputComponent.tsx +462 -0
  293. package/src/components/InboxMessage/LeftSidebar.tsx +140 -0
  294. package/src/components/InboxMessage/MessageInput.tsx +209 -0
  295. package/src/components/InboxMessage/MessageInputComponent.tsx +245 -0
  296. package/src/components/InboxMessage/Messages.tsx +137 -0
  297. package/src/components/InboxMessage/MessagesBuilderUi.tsx +205 -0
  298. package/src/components/InboxMessage/Popover.tsx +42 -0
  299. package/src/components/InboxMessage/RightSidebar.tsx +22 -0
  300. package/src/components/InboxMessage/RightSidebarAi.tsx +37 -0
  301. package/src/components/InboxMessage/ServiceConversationItem.tsx +234 -0
  302. package/src/components/InboxMessage/ServiceInboxItem.tsx +223 -0
  303. package/src/components/InboxMessage/SubscriptionHandler.tsx +55 -0
  304. package/src/components/InboxMessage/UploadImageButton.tsx +46 -0
  305. package/src/components/InboxMessage/UserModalContent.tsx +60 -0
  306. package/src/components/InboxMessage/index.ts +16 -0
  307. package/src/components/InboxMessage/message-widgets/CommonMessage.tsx +69 -0
  308. package/src/components/InboxMessage/message-widgets/ErrorFixCard.tsx +240 -0
  309. package/src/components/InboxMessage/message-widgets/MessageCard.tsx +127 -0
  310. package/src/components/InboxMessage/message-widgets/MessageSliceRenderer.tsx +40 -0
  311. package/src/components/InboxMessage/message-widgets/ModernMessageGroup.tsx +1295 -0
  312. package/src/components/InboxMessage/message-widgets/PlainMessage.tsx +18 -0
  313. package/src/components/InboxMessage/message-widgets/PropertyMessageWidget.tsx +29 -0
  314. package/src/components/InboxMessage/message-widgets/SlackLikeMessageGroup.tsx +492 -0
  315. package/src/components/InboxMessage/message-widgets/index.ts +3 -0
  316. package/src/components/ModelConfigPanel.tsx +345 -0
  317. package/src/components/filler-components/RightSiderBar.tsx +408 -0
  318. package/src/components/inbox/FilesList.tsx +89 -0
  319. package/src/components/inbox/MessageItem.tsx +50 -0
  320. package/src/components/inbox/ThreadItem.tsx +295 -0
  321. package/src/components/inbox/index.ts +3 -0
  322. package/src/components/index.ts +22 -0
  323. package/src/components/live-code-editor/hybrid-live-editor.tsx +105 -0
  324. package/src/components/live-code-editor/index.ts +3 -0
  325. package/src/components/live-code-editor/live-code-editor.tsx +257 -0
  326. package/src/components/slot-fill/chat-message-filler.tsx +18 -0
  327. package/src/components/slot-fill/chat-message-slot.tsx +18 -0
  328. package/src/components/slot-fill/index.ts +3 -0
  329. package/src/components/slot-fill/right-sidebar-filler.tsx +39 -0
  330. package/src/components/ui/button.tsx +32 -0
  331. package/src/compute.ts +134 -0
  332. package/src/config/env-config.ts +17 -0
  333. package/src/config/index.ts +1 -0
  334. package/src/constants/breakpoints.ts +7 -0
  335. package/src/constants/index.ts +5 -0
  336. package/src/container/AiInbox.tsx +1819 -0
  337. package/src/container/AiInboxWithLoader.tsx +356 -0
  338. package/src/container/AiLandingInput.tsx +221 -0
  339. package/src/container/Inbox.tsx +1092 -0
  340. package/src/container/InboxAiMessagesLoader.tsx +44 -0
  341. package/src/container/InboxContainer.tsx +35 -0
  342. package/src/container/InboxTemplate1.tsx +1542 -0
  343. package/src/container/InboxTemplate1WithLoader.tsx +338 -0
  344. package/src/container/InboxTemplate2.tsx +1606 -0
  345. package/src/container/InboxWithAiLoader.tsx +76 -0
  346. package/src/container/InboxWithLoader.tsx +341 -0
  347. package/src/container/ServiceInbox.tsx +190 -0
  348. package/src/container/ThreadMessages.tsx +371 -0
  349. package/src/container/ThreadMessagesInbox.tsx +450 -0
  350. package/src/container/Threads.tsx +270 -0
  351. package/src/container/ThreadsInbox.tsx +354 -0
  352. package/src/container/apply-footer-styles.ts +17 -0
  353. package/src/container/index.ts +31 -0
  354. package/src/enums/index.ts +1 -0
  355. package/src/enums/messenger-slot-fill-name-enum.ts +4 -0
  356. package/src/hooks/index.ts +2 -0
  357. package/src/hooks/use-file-sync.ts +91 -0
  358. package/src/hooks/usePersistentModelConfig.ts +63 -0
  359. package/src/index.ts +37 -0
  360. package/src/interfaces/index.ts +1 -0
  361. package/src/interfaces/message-widgets.interface.ts +21 -0
  362. package/src/machines/aiAgentMachine.simple.ts +89 -0
  363. package/src/machines/aiAgentMachine.ts +1296 -0
  364. package/src/machines/aiAgentMachine.ts.bk +1296 -0
  365. package/src/machines/index.ts +2 -0
  366. package/src/machines/types.ts +59 -0
  367. package/src/module.tsx +32 -0
  368. package/src/styles/responsive.css +76 -0
  369. package/src/templates/InboxWithAi.tsx +533 -0
  370. package/src/templates/index.ts +1 -0
  371. package/src/utils/utils.ts +3 -0
  372. package/tsconfig.json +14 -0
  373. package/webpack.config.js +92 -0
@@ -0,0 +1,1819 @@
1
+ import React, { ReactNode, useCallback, useEffect, useMemo, useReducer, useRef } from 'react';
2
+ import { orderBy, uniqBy } from 'lodash-es';
3
+ import {
4
+ OnChatMessageAddedDocument as CHAT_MESSAGE_ADDED,
5
+ useSendMessagesMutation,
6
+ GetChannelsByUserDocument,
7
+ MessagesDocument,
8
+ } from 'common/graphql';
9
+ import { useUploadFiles } from '@messenger-box/platform-client';
10
+ import { IFileInfo, RoomType, PostTypeEnum } from 'common';
11
+ import { useSelector, shallowEqual } from 'react-redux';
12
+ import { useNavigate, useParams } from '@remix-run/react';
13
+ import { LeftSidebar, Messages, RightSidebar, MessageInputComponent } from '../components';
14
+ import { Store, userSelector } from '@adminide-stack/user-auth0-client';
15
+ import { IUserState } from '@adminide-stack/core';
16
+ import { config } from '../config';
17
+ import { applyFooterStyles } from './apply-footer-styles';
18
+ import { objectId } from '@messenger-box/core';
19
+ import { ThreadsInbox } from './ThreadsInbox';
20
+ import { ThreadMessagesInbox } from './ThreadMessagesInbox';
21
+ import { useApolloClient } from '@apollo/client';
22
+ import { SubscriptionHandler } from '../components/InboxMessage/SubscriptionHandler';
23
+
24
+ const { MESSAGES_PER_PAGE } = config;
25
+
26
+ // Types
27
+ interface DrawerProps {
28
+ isOpen: boolean;
29
+ onClose: () => void;
30
+ children: ReactNode;
31
+ title?: string;
32
+ }
33
+
34
+ export interface InboxProps {
35
+ channelFilters?: Record<string, unknown>;
36
+ channelRole?: string;
37
+ supportServices?: boolean;
38
+ pathPrefix?: string;
39
+ data?: any;
40
+ orgName?: string;
41
+ }
42
+
43
+ interface MobilePreviewState {
44
+ mobilePreviewVisibility: boolean;
45
+ mobilePreviewText: string | ReactNode;
46
+ mobilePreviewCTAText: string | ReactNode;
47
+ }
48
+
49
+ // Static utility hooks and components
50
+ const useMediaQuery = (query: string) => {
51
+ const [matches, setMatches] = React.useState(false);
52
+
53
+ useEffect(() => {
54
+ if (typeof window === 'undefined') return;
55
+
56
+ const mediaQuery = window.matchMedia(query);
57
+ const updateMatches = () => setMatches(mediaQuery.matches);
58
+
59
+ updateMatches();
60
+ mediaQuery.addEventListener('change', updateMatches);
61
+ return () => mediaQuery.removeEventListener('change', updateMatches);
62
+ }, [query]);
63
+
64
+ return matches;
65
+ };
66
+
67
+ // Hook to get window dimensions
68
+ const useWindowDimensions = () => {
69
+ const [windowDimensions, setWindowDimensions] = React.useState({
70
+ width: typeof window !== 'undefined' ? window.innerWidth : 1024,
71
+ height: typeof window !== 'undefined' ? window.innerHeight : 768,
72
+ });
73
+
74
+ useEffect(() => {
75
+ if (typeof window === 'undefined') return;
76
+
77
+ const handleResize = () => {
78
+ setWindowDimensions({
79
+ width: window.innerWidth,
80
+ height: window.innerHeight,
81
+ });
82
+ };
83
+
84
+ window.addEventListener('resize', handleResize);
85
+ handleResize(); // Set initial dimensions
86
+
87
+ return () => window.removeEventListener('resize', handleResize);
88
+ }, []);
89
+
90
+ return windowDimensions;
91
+ };
92
+
93
+ // Static components
94
+ const Spinner = React.memo(({ className = '' }: { className?: string }) => (
95
+ <div className={`animate-spin rounded-full border-4 border-gray-200 border-t-blue-500 ${className}`}>
96
+ <span className="sr-only">Loading...</span>
97
+ </div>
98
+ ));
99
+
100
+ const Drawer = React.memo(({ isOpen, onClose, children, title }: DrawerProps) => {
101
+ if (!isOpen) return null;
102
+
103
+ return (
104
+ <div className="fixed inset-0 z-50 overflow-hidden">
105
+ <div className="absolute inset-0 bg-black bg-opacity-50" onClick={onClose} />
106
+ <div className="absolute bottom-0 left-0 right-0 bg-white rounded-t-lg shadow-lg max-h-[80vh] flex flex-col overflow-hidden">
107
+ <div className="flex items-center justify-between p-4 border-b border-gray-200 flex-shrink-0">
108
+ <h2 className="text-lg font-semibold truncate">{title}</h2>
109
+ <button
110
+ onClick={onClose}
111
+ className="p-1 hover:bg-gray-100 rounded-full transition-colors flex-shrink-0 ml-2"
112
+ >
113
+ <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
114
+ <path
115
+ strokeLinecap="round"
116
+ strokeLinejoin="round"
117
+ strokeWidth={2}
118
+ d="M6 18L18 6M6 6l12 12"
119
+ />
120
+ </svg>
121
+ </button>
122
+ </div>
123
+ <div className="flex-1 p-4 overflow-y-auto" style={{ minHeight: 0 }}>
124
+ {children}
125
+ </div>
126
+ </div>
127
+ </div>
128
+ );
129
+ });
130
+
131
+ const EmptyState = React.memo(() => (
132
+ <div className="h-full flex items-center justify-center bg-gray-100 p-4 sm:p-6 overflow-hidden">
133
+ <div className="text-center max-w-sm mx-auto">
134
+ <div className="text-3xl sm:text-4xl text-gray-400 mb-4">💬</div>
135
+ <h3 className="text-lg sm:text-xl font-semibold text-gray-600 mb-2">Welcome to Messenger</h3>
136
+ <p className="text-sm sm:text-base text-gray-500 leading-relaxed">
137
+ Select a conversation from the sidebar to start messaging
138
+ </p>
139
+ </div>
140
+ </div>
141
+ ));
142
+
143
+ // Mobile preview reducer
144
+ const mobilePreviewReducer = (
145
+ state: MobilePreviewState,
146
+ action: { payload: Partial<MobilePreviewState>; type: string },
147
+ ) => {
148
+ if (action.type === 'update') {
149
+ return { ...state, ...action.payload };
150
+ }
151
+ return state;
152
+ };
153
+
154
+ const Inbox = (props: InboxProps) => {
155
+ const { channelFilters: channelFilterProp, channelRole, supportServices, data, orgName, pathPrefix = null } = props;
156
+ const { id: pathChannelId, postId: pathPostId } = useParams();
157
+ const navigate = useNavigate();
158
+ const apolloClient = useApolloClient();
159
+
160
+ // Reduced state - only UI state remains, data comes from Apollo cache
161
+ const [isBottomDrawerOpen, setBottomDrawer] = React.useState(false);
162
+ const [mobilePreviewState, localDispatch] = useReducer(mobilePreviewReducer, {
163
+ mobilePreviewVisibility: false,
164
+ mobilePreviewText: false,
165
+ mobilePreviewCTAText: false,
166
+ });
167
+
168
+ // Hooks - improved responsive breakpoints with better granularity
169
+ const { width: windowWidth, height: windowHeight } = useWindowDimensions();
170
+ const isMobileView = useMediaQuery('(max-width: 640px)');
171
+ const isSmallTabletView = useMediaQuery('(min-width: 641px) and (max-width: 900px)');
172
+ const isTabletView = useMediaQuery('(min-width: 901px) and (max-width: 1024px)');
173
+ const isDesktopView = useMediaQuery('(min-width: 1025px)');
174
+ const isLargeDesktopView = useMediaQuery('(min-width: 1440px)');
175
+ const isSmallScreen = useMediaQuery('(max-width: 900px)');
176
+ // const auth = useSelector(userSelector);
177
+ const auth: any = useSelector<Store.Auth, IUserState>(userSelector, shallowEqual);
178
+ // const user = useSelector((state: any) => state.user, shallowEqual);
179
+
180
+ // Data destructuring from Apollo queries
181
+ const GetChannelsByUserQuery = data?.[0];
182
+ const {
183
+ data: userChannels,
184
+ loading: userChannelsLoading,
185
+ refetch: getChannelsRefetch,
186
+ } = GetChannelsByUserQuery || {};
187
+
188
+ // Get data directly from Apollo cache instead of local state
189
+ const channels = useMemo(() => {
190
+ if (!userChannels?.channelsByUser && !userChannels?.supportServiceChannels) return [];
191
+
192
+ return uniqBy([...(userChannels?.supportServiceChannels ?? []), ...(userChannels?.channelsByUser ?? [])], 'id');
193
+ }, [userChannels]);
194
+
195
+ // Memoize stable channel array to prevent unnecessary re-renders
196
+ const stableChannels = useMemo(() => {
197
+ return channels || [];
198
+ }, [channels]);
199
+
200
+ // Memoized values derived from Apollo cache data
201
+ const channelFilters = useMemo(() => {
202
+ const filters = { ...channelFilterProp };
203
+ const channelType = filters?.type ?? RoomType.Direct;
204
+ filters.type = supportServices ? [channelType, RoomType.Service] : channelType;
205
+ return filters;
206
+ }, [channelFilterProp, supportServices]);
207
+
208
+ const users = useMemo(() => {
209
+ return (
210
+ channels?.reduce((acc, curr) => {
211
+ const newMembers = curr.members?.filter(({ user }) => !acc.find(({ id }) => id === user.id)) || [];
212
+ return [...acc, ...newMembers.map(({ user }) => user)];
213
+ }, []) || []
214
+ );
215
+ }, [channels]);
216
+
217
+ // const currentUser = useMemo(
218
+ // () => users?.find((user) => user && user.alias?.includes(auth?.authUserId)),
219
+ // [users, auth?.authUserId],
220
+ // );
221
+ const currentUser = auth;
222
+
223
+ const channelName = useMemo(() => {
224
+ if (!channels || !pathChannelId) return '';
225
+
226
+ const currChannel = channels?.find((ch) => ch.id === pathChannelId);
227
+ if (!currChannel) return '';
228
+
229
+ const { members, title, type } = currChannel;
230
+
231
+ if (type === RoomType.Direct && members?.length >= 2) {
232
+ const otherUser = members.find((member) => member.user.id !== currentUser?.id);
233
+ if (otherUser?.user) {
234
+ const { givenName, familyName } = otherUser.user;
235
+ if (givenName && familyName) return `${givenName} ${familyName}`;
236
+ return givenName || familyName || title || 'Direct Message';
237
+ }
238
+ return title || 'Direct Message';
239
+ }
240
+
241
+ if (type === RoomType.Direct && members?.length === 1) {
242
+ if (members[0].user?.givenName && members[0]?.user?.familyName) {
243
+ return `${members[0].user?.givenName} ${members[0].user?.familyName}`;
244
+ }
245
+ return members[0].user?.givenName || members[0].user?.familyName || 'Direct Message';
246
+ }
247
+
248
+ return title || 'Channel';
249
+ }, [channels, pathChannelId, currentUser]);
250
+
251
+ // Effects
252
+ useEffect(() => {
253
+ applyFooterStyles();
254
+
255
+ // Optimistic refetch with cache update
256
+ const timeout = setTimeout(() => {
257
+ getChannelsRefetch?.({
258
+ role: channelRole,
259
+ criteria: orgName
260
+ ? { ...channelFilters, orgName: channelFilters?.orgName || orgName || '' }
261
+ : channelFilters,
262
+ supportServices: !!supportServices,
263
+ supportServiceCriteria: { type: RoomType.Service },
264
+ });
265
+ }, 0);
266
+ return () => clearTimeout(timeout);
267
+ }, [channelRole, channelFilters, supportServices, getChannelsRefetch]);
268
+
269
+ // Optimistic navigation with cache updates
270
+ const handleSelectChannel = useCallback(
271
+ async (channelId: string, pId: string | null = null) => {
272
+ // Optimistic UI update
273
+ const mainPath = orgName
274
+ ? pId
275
+ ? `/o/${orgName}/ai-messenger/${channelId}/${pId}`
276
+ : `/o/${orgName}/ai-messenger/${channelId}`
277
+ : pId
278
+ ? `/inbox/${channelId}/${pId}`
279
+ : `/inbox/${channelId}`;
280
+ const basePath = pathPrefix ? `${pathPrefix}${mainPath}` : mainPath;
281
+
282
+ const searchParams = new URLSearchParams();
283
+ // if (channelRole) searchParams.set('channelRole', channelRole);
284
+ // if (orgName) searchParams.set('orgName', orgName);
285
+
286
+ const newPath = searchParams.toString() ? `${basePath}?${searchParams.toString()}` : basePath;
287
+ navigate(newPath, { replace: true });
288
+
289
+ // Optimistically update Apollo cache for immediate UI feedback
290
+ try {
291
+ apolloClient.writeQuery({
292
+ query: MessagesDocument,
293
+ variables: {
294
+ channelId: channelId.toString(),
295
+ parentId: null,
296
+ limit: MESSAGES_PER_PAGE,
297
+ },
298
+ data: {
299
+ messages: {
300
+ __typename: 'Messages',
301
+ data: [],
302
+ totalCount: 0,
303
+ messagesRefId: channelId,
304
+ },
305
+ },
306
+ });
307
+ } catch (error) {
308
+ // Cache write might fail if query hasn't been executed yet, that's OK
309
+ console.debug('Cache write failed (expected on first load):', error);
310
+ }
311
+ },
312
+ [navigate, apolloClient, orgName, channelRole, pathPrefix],
313
+ );
314
+
315
+ const detailSidebarOptions = useMemo(
316
+ () => ({
317
+ isMobileView,
318
+ isSmallTabletView,
319
+ isTabletView,
320
+ isDesktopView,
321
+ isLargeDesktopView,
322
+ isSmallScreen,
323
+ setMobilePreviewCTAText: (v: string | ReactNode) =>
324
+ localDispatch({ payload: { mobilePreviewCTAText: v }, type: 'update' }),
325
+ setMobilePreviewText: (v: string | ReactNode) =>
326
+ localDispatch({ payload: { mobilePreviewText: v }, type: 'update' }),
327
+ setMobilePreviewVisibility: (v: boolean) =>
328
+ localDispatch({ payload: { mobilePreviewVisibility: v }, type: 'update' }),
329
+ }),
330
+ [isMobileView, isSmallTabletView, isTabletView, isDesktopView, isLargeDesktopView, isSmallScreen],
331
+ );
332
+
333
+ return (
334
+ <div
335
+ className="border-t border-gray-300 flex overflow-hidden"
336
+ style={{
337
+ height: `${windowHeight}px`,
338
+ maxHeight: '100vh',
339
+ }}
340
+ >
341
+ {/* Left Sidebar - Responsive Design */}
342
+ <div
343
+ className={`
344
+ flex-shrink-0 bg-gray-50 border-r border-gray-300 overflow-hidden transition-all duration-300 ease-in-out
345
+ ${isMobileView && pathChannelId ? 'hidden' : ''}
346
+ `}
347
+ style={{
348
+ width:
349
+ isMobileView && !pathChannelId
350
+ ? '100%'
351
+ : isMobileView && pathChannelId
352
+ ? '0px'
353
+ : isSmallTabletView
354
+ ? `${Math.min(288, windowWidth * 0.35)}px` // w-72 or 35% of window
355
+ : isTabletView
356
+ ? `${Math.min(320, windowWidth * 0.3)}px` // w-80 or 30% of window
357
+ : isLargeDesktopView
358
+ ? `${Math.min(384, windowWidth * 0.25)}px` // w-96 or 25% of window
359
+ : `${Math.min(320, windowWidth * 0.28)}px`, // w-80 or 28% of window
360
+ height: `${windowHeight}px`,
361
+ maxHeight: '100vh',
362
+ }}
363
+ >
364
+ <LeftSidebar
365
+ currentUser={currentUser}
366
+ userChannels={stableChannels}
367
+ userChannelsLoading={userChannelsLoading}
368
+ users={users}
369
+ handleSelectChannel={handleSelectChannel}
370
+ selectedChannelId={pathChannelId}
371
+ channelToTop={0}
372
+ getChannelsRefetch={getChannelsRefetch}
373
+ role={channelRole}
374
+ messagesQuery={data?.[1]}
375
+ windowHeight={windowHeight}
376
+ windowWidth={windowWidth}
377
+ />
378
+ </div>
379
+
380
+ {/* Main Content Area - Responsive */}
381
+ <div
382
+ className={`
383
+ flex-1 min-w-0 flex flex-col overflow-hidden transition-all duration-300 ease-in-out
384
+ ${isMobileView && !pathChannelId ? 'hidden' : 'flex'}
385
+ `}
386
+ style={{
387
+ minWidth: isSmallScreen ? '300px' : isDesktopView ? '500px' : '400px',
388
+ width: 'auto',
389
+ height: `${windowHeight}px`,
390
+ maxHeight: '100vh',
391
+ }}
392
+ >
393
+ {pathChannelId ? (
394
+ <ContentComponent
395
+ channelId={pathChannelId}
396
+ postId={pathPostId}
397
+ channelRole={channelRole}
398
+ pathPrefix={props.pathPrefix}
399
+ isMobileView={isMobileView}
400
+ isSmallTabletView={isSmallTabletView}
401
+ isTabletView={isTabletView}
402
+ isDesktopView={isDesktopView}
403
+ isLargeDesktopView={isLargeDesktopView}
404
+ isSmallScreen={isSmallScreen}
405
+ windowWidth={windowWidth}
406
+ windowHeight={windowHeight}
407
+ mobilePreviewState={mobilePreviewState}
408
+ detailSidebarOptions={detailSidebarOptions}
409
+ isBottomDrawerOpen={isBottomDrawerOpen}
410
+ setBottomDrawer={setBottomDrawer}
411
+ channelName={channelName}
412
+ loaderdata={data}
413
+ />
414
+ ) : (
415
+ <EmptyState />
416
+ )}
417
+ </div>
418
+
419
+ {/* Right Sidebar - Desktop Only */}
420
+ {pathChannelId && data?.[1] && isDesktopView && (
421
+ <div
422
+ className="border-l border-gray-200 bg-white flex-shrink-0 overflow-hidden"
423
+ style={{
424
+ width: `${windowWidth * 0.35}px`, // 40% of window width
425
+ height: `${windowHeight}px`,
426
+ maxHeight: '100vh',
427
+ }}
428
+ >
429
+ <RightSidebarWrapper
430
+ MessagesLoaderQuery={data?.[1]}
431
+ selectedPost={null}
432
+ detailSidebarOptions={detailSidebarOptions}
433
+ />
434
+ </div>
435
+ )}
436
+ </div>
437
+ );
438
+ };
439
+
440
+ const ContentComponent = React.memo((props: any) => {
441
+ const {
442
+ channelId,
443
+ channelRole,
444
+ pathPrefix,
445
+ postId,
446
+ isMobileView,
447
+ isSmallTabletView,
448
+ isTabletView,
449
+ isDesktopView,
450
+ isLargeDesktopView,
451
+ isSmallScreen,
452
+ windowWidth,
453
+ windowHeight,
454
+ mobilePreviewState,
455
+ detailSidebarOptions,
456
+ isBottomDrawerOpen,
457
+ setBottomDrawer,
458
+ channelName,
459
+ loaderdata,
460
+ } = props;
461
+
462
+ const ViewChannelDetailLoaderQuery = loaderdata?.[2];
463
+ const MessagesLoaderQuery = loaderdata?.[1];
464
+
465
+ const [selectedPost, setSelectedPost] = React.useState(null);
466
+ const { data: channelData, loading: channelLoading } = ViewChannelDetailLoaderQuery || {};
467
+
468
+ const onMessageClick = useCallback((msg: any) => {
469
+ setSelectedPost(msg);
470
+ }, []);
471
+
472
+ const channelsDetail = useMemo(() => {
473
+ return channelData?.viewChannelDetail || null;
474
+ }, [channelData]);
475
+
476
+ return (
477
+ <div className="flex overflow-hidden" style={{ height: `${windowHeight}px`, maxHeight: '100vh' }}>
478
+ {/* Main Chat Content */}
479
+ <div className="flex-1 flex flex-col min-w-0 overflow-hidden">
480
+ {/* Channel Header */}
481
+ {channelId && (
482
+ <div
483
+ className={`border-b border-gray-200 bg-white flex-shrink-0 z-10 ${
484
+ isSmallScreen ? 'px-3 py-3' : 'px-4 sm:px-6 py-4'
485
+ }`}
486
+ >
487
+ <div className="flex items-center justify-between">
488
+ <div className="flex items-center space-x-2 min-w-0 flex-1">
489
+ {/* Mobile/Small Screen Back Button */}
490
+ {(isMobileView || isSmallTabletView) && (
491
+ <button
492
+ className="p-2 hover:bg-gray-100 rounded-full transition-colors flex-shrink-0"
493
+ onClick={() => window.history.back()}
494
+ aria-label="Go back"
495
+ >
496
+ <svg
497
+ className="w-5 h-5 text-gray-600"
498
+ fill="none"
499
+ stroke="currentColor"
500
+ viewBox="0 0 24 24"
501
+ >
502
+ <path
503
+ strokeLinecap="round"
504
+ strokeLinejoin="round"
505
+ strokeWidth={2}
506
+ d="M15 19l-7-7 7-7"
507
+ />
508
+ </svg>
509
+ </button>
510
+ )}
511
+ <h2
512
+ className={`font-semibold text-gray-800 truncate ${
513
+ isSmallScreen ? 'text-base' : 'text-lg'
514
+ }`}
515
+ >
516
+ {channelName}
517
+ </h2>
518
+ </div>
519
+ {(isMobileView || isSmallTabletView) && mobilePreviewState?.mobilePreviewVisibility && (
520
+ <button
521
+ className="text-sm px-3 py-1 bg-teal-500 hover:bg-teal-600 text-white rounded-md transition-colors flex-shrink-0"
522
+ onClick={() => setBottomDrawer(true)}
523
+ >
524
+ {mobilePreviewState?.mobilePreviewCTAText}
525
+ </button>
526
+ )}
527
+ </div>
528
+ </div>
529
+ )}
530
+
531
+ {/* Mobile Preview */}
532
+ {(isMobileView || isSmallTabletView) && channelId && mobilePreviewState?.mobilePreviewVisibility && (
533
+ <div className={`mt-4 ${isSmallScreen ? 'mx-3' : 'mx-4'}`}>
534
+ <div className="mb-2">
535
+ <div className="w-full flex justify-between items-center gap-2 mb-[5px]">
536
+ <span className="truncate flex-1 text-sm">{mobilePreviewState?.mobilePreviewText}</span>
537
+ <button
538
+ className="text-sm px-3 py-2 bg-teal-500 hover:bg-teal-600 text-white rounded-md transition-colors flex-shrink-0"
539
+ onClick={() => setBottomDrawer(true)}
540
+ >
541
+ {mobilePreviewState?.mobilePreviewCTAText}
542
+ </button>
543
+ </div>
544
+ </div>
545
+ <hr className="border-gray-200" />
546
+ </div>
547
+ )}
548
+
549
+ {/* Content based on postId */}
550
+ <div className="flex-1 flex flex-col min-h-0 overflow-hidden">
551
+ {channelId && (
552
+ <>
553
+ {postId ? (
554
+ postId === '1' ? (
555
+ <ThreadsInbox
556
+ channelId={channelId}
557
+ role={channelRole}
558
+ pathPrefix={pathPrefix}
559
+ setChannelId={() => {}}
560
+ setPostId={() => {}}
561
+ setGoBack={() => {}}
562
+ />
563
+ ) : (
564
+ <ThreadMessagesInbox
565
+ channelId={channelId}
566
+ postId={postId}
567
+ role={channelRole}
568
+ goBack={false}
569
+ pathPrefix={pathPrefix}
570
+ setPostId={() => {}}
571
+ setChannelId={() => {}}
572
+ onMessageClick={onMessageClick}
573
+ />
574
+ )
575
+ ) : (
576
+ <MessagesComponent
577
+ channelId={channelId}
578
+ MessagesLoaderQuery={MessagesLoaderQuery}
579
+ channelsDetail={channelsDetail}
580
+ channelLoading={channelLoading}
581
+ onMessageClick={onMessageClick}
582
+ isSmallScreen={isSmallScreen}
583
+ isDesktopView={isDesktopView}
584
+ windowHeight={windowHeight}
585
+ windowWidth={windowWidth}
586
+ />
587
+ )}
588
+ </>
589
+ )}
590
+ </div>
591
+ </div>
592
+
593
+ {/* Mobile/Small Screen Drawer */}
594
+ {(isMobileView || isSmallTabletView) && (
595
+ <Drawer
596
+ isOpen={isBottomDrawerOpen}
597
+ onClose={() => setBottomDrawer(false)}
598
+ title={mobilePreviewState.mobilePreviewText as string}
599
+ >
600
+ <RightSidebarWrapper
601
+ MessagesLoaderQuery={MessagesLoaderQuery}
602
+ selectedPost={selectedPost}
603
+ detailSidebarOptions={detailSidebarOptions}
604
+ />
605
+ </Drawer>
606
+ )}
607
+ </div>
608
+ );
609
+ });
610
+
611
+ const RightSidebarWrapper = React.memo(({ MessagesLoaderQuery, selectedPost, detailSidebarOptions }: any) => {
612
+ const { data } = MessagesLoaderQuery || {};
613
+ const [activeTab, setActiveTab] = React.useState('preview');
614
+
615
+ const sortedMessages = useMemo(() => {
616
+ const messages = data?.messages?.data || [];
617
+ return orderBy(uniqBy(messages, 'id'), ['createdAt'], ['asc']);
618
+ }, [data?.messages?.data]);
619
+
620
+ const handleRefreshSandbox = useCallback(() => {
621
+ // Refresh sandbox functionality
622
+ console.log('Refreshing sandbox...');
623
+ // Add actual refresh logic here
624
+ }, []);
625
+
626
+ if (!sortedMessages.length) return null;
627
+
628
+ return (
629
+ <div className="h-full flex flex-col overflow-hidden bg-white">
630
+ {/* Header with tabs and refresh icon */}
631
+ <div className="flex-shrink-0 border-b border-gray-200">
632
+ <div className="flex items-center justify-between px-4 py-3">
633
+ <div className="flex items-center space-x-1">
634
+ <button
635
+ onClick={() => setActiveTab('preview')}
636
+ className={`flex items-center space-x-2 px-3 py-2 text-sm font-medium rounded-lg transition-colors ${
637
+ activeTab === 'preview'
638
+ ? 'bg-gray-100 text-gray-900'
639
+ : 'text-gray-600 hover:text-gray-900 hover:bg-gray-50'
640
+ }`}
641
+ >
642
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
643
+ <path
644
+ strokeLinecap="round"
645
+ strokeLinejoin="round"
646
+ strokeWidth={2}
647
+ d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
648
+ />
649
+ <path
650
+ strokeLinecap="round"
651
+ strokeLinejoin="round"
652
+ strokeWidth={2}
653
+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
654
+ />
655
+ </svg>
656
+ <span>Preview</span>
657
+ </button>
658
+ <button
659
+ onClick={() => setActiveTab('code')}
660
+ className={`flex items-center space-x-2 px-3 py-2 text-sm font-medium rounded-lg transition-colors ${
661
+ activeTab === 'code'
662
+ ? 'bg-gray-100 text-gray-900'
663
+ : 'text-gray-600 hover:text-gray-900 hover:bg-gray-50'
664
+ }`}
665
+ >
666
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
667
+ <path
668
+ strokeLinecap="round"
669
+ strokeLinejoin="round"
670
+ strokeWidth={2}
671
+ d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"
672
+ />
673
+ </svg>
674
+ <span>Code</span>
675
+ </button>
676
+ </div>
677
+
678
+ {/* Refresh icon on the right */}
679
+ <button
680
+ onClick={handleRefreshSandbox}
681
+ className="p-2 text-gray-600 hover:text-gray-900 hover:bg-gray-50 rounded-lg transition-colors"
682
+ title="Refresh Sandbox"
683
+ >
684
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
685
+ <path
686
+ strokeLinecap="round"
687
+ strokeLinejoin="round"
688
+ strokeWidth={2}
689
+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
690
+ />
691
+ </svg>
692
+ </button>
693
+ </div>
694
+ <hr className="border-gray-300 my-6" />
695
+ {/* Refresh Sandbox Button - Below tabs, aligned right */}
696
+ <div className="px-4 pb-3 flex justify-end">
697
+ <button
698
+ onClick={handleRefreshSandbox}
699
+ className="flex items-center space-x-2 px-4 py-2 text-sm font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-50 rounded-lg transition-colors border border-gray-200"
700
+ title="Refresh Sandbox"
701
+ >
702
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
703
+ <path
704
+ strokeLinecap="round"
705
+ strokeLinejoin="round"
706
+ strokeWidth={2}
707
+ d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
708
+ />
709
+ </svg>
710
+ <span>Refresh Sandbox</span>
711
+ </button>
712
+ </div>
713
+ </div>
714
+
715
+ {/* Content Area */}
716
+ <div className="flex-1 overflow-hidden">
717
+ {activeTab === 'preview' ? (
718
+ <div className="h-full flex items-center justify-center bg-gray-50">
719
+ <div className="text-center">
720
+ {/* Next.js Logo */}
721
+ <div className="mb-8">
722
+ <svg className="w-32 h-16 mx-auto text-black" viewBox="0 0 394 80" fill="currentColor">
723
+ <path d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.4zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.7h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z" />
724
+ <path d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.2 3.4 1 1.4 1.5 3 1.5 5h-5.8z" />
725
+ </svg>
726
+ </div>
727
+
728
+ <div className="space-y-4 text-gray-600">
729
+ <h3 className="text-lg font-semibold text-gray-900">Get started by editing</h3>
730
+ <p className="font-mono text-sm bg-gray-100 px-3 py-1 rounded">app/page.tsx</p>
731
+ <p>Save and see your changes instantly.</p>
732
+ </div>
733
+
734
+ <div className="mt-8 space-y-4">
735
+ <button className="bg-black text-white px-6 py-3 rounded-full hover:bg-gray-800 transition-colors flex items-center space-x-2 mx-auto">
736
+ <svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
737
+ <path d="M12 2L2 7v10c0 5.55 3.84 9.739 9 11 5.16-1.261 9-5.45 9-11V7l-10-5z" />
738
+ </svg>
739
+ <span>Deploy now</span>
740
+ </button>
741
+ <p className="text-sm text-gray-500 underline cursor-pointer hover:text-gray-700">
742
+ Read our docs
743
+ </p>
744
+ </div>
745
+ </div>
746
+ </div>
747
+ ) : (
748
+ <div className="h-full bg-gray-900 text-gray-300 p-4 overflow-auto">
749
+ <div className="font-mono text-sm">
750
+ <div className="mb-4">
751
+ <div className="text-green-400">// app/page.tsx</div>
752
+ </div>
753
+ <div className="space-y-2">
754
+ <div>
755
+ <span className="text-purple-400">export</span>{' '}
756
+ <span className="text-purple-400">default</span>{' '}
757
+ <span className="text-blue-400">function</span>{' '}
758
+ <span className="text-yellow-400">Home</span>() {'{'}
759
+ </div>
760
+ <div className="ml-4">
761
+ <span className="text-purple-400">return</span> (
762
+ </div>
763
+ <div className="ml-8">
764
+ {'<'}
765
+ <span className="text-red-400">main</span>{' '}
766
+ <span className="text-green-400">className</span>=
767
+ <span className="text-yellow-400">
768
+ "flex min-h-screen flex-col items-center justify-between p-24"
769
+ </span>
770
+ {'>'}
771
+ </div>
772
+ <div className="ml-12">
773
+ {'<'}
774
+ <span className="text-red-400">div</span>{' '}
775
+ <span className="text-green-400">className</span>=
776
+ <span className="text-yellow-400">
777
+ "z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex"
778
+ </span>
779
+ {'>'}
780
+ </div>
781
+ <div className="ml-16">
782
+ {'<'}
783
+ <span className="text-red-400">p</span>{' '}
784
+ <span className="text-green-400">className</span>=
785
+ <span className="text-yellow-400">
786
+ "fixed left-0 top-0 flex w-full justify-center border-b border-gray-300
787
+ bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl
788
+ dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static
789
+ lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30"
790
+ </span>
791
+ {'>'}
792
+ </div>
793
+ <div className="ml-20 text-gray-400">Get started by editing&nbsp;</div>
794
+ <div className="ml-20">
795
+ {'<'}
796
+ <span className="text-red-400">code</span>{' '}
797
+ <span className="text-green-400">className</span>=
798
+ <span className="text-yellow-400">"font-mono font-bold"</span>
799
+ {'>'}app/page.tsx{'</'}
800
+ <span className="text-red-400">code</span>
801
+ {'>'}
802
+ </div>
803
+ <div className="ml-16">
804
+ {'</'}
805
+ <span className="text-red-400">p</span>
806
+ {'>'}
807
+ </div>
808
+ <div className="ml-12">
809
+ {'</'}
810
+ <span className="text-red-400">div</span>
811
+ {'>'}
812
+ </div>
813
+ <div className="ml-8">
814
+ {'</'}
815
+ <span className="text-red-400">main</span>
816
+ {'>'}
817
+ </div>
818
+ <div className="ml-4">);</div>
819
+ <div>{'}'}</div>
820
+ </div>
821
+ </div>
822
+ </div>
823
+ )}
824
+ </div>
825
+ </div>
826
+ );
827
+ });
828
+
829
+ const MessagesComponent = React.memo((props: any) => {
830
+ const {
831
+ channelId,
832
+ MessagesLoaderQuery,
833
+ channelsDetail,
834
+ channelLoading,
835
+ onMessageClick,
836
+ isSmallScreen,
837
+ isDesktopView,
838
+ windowHeight = 768,
839
+ windowWidth = 1024,
840
+ } = props;
841
+
842
+ const messageRootListRef = useRef(null);
843
+ const messageListRef = useRef(null);
844
+ const apolloClient = useApolloClient();
845
+ const [isLoadingOlder, setIsLoadingOlder] = React.useState(false);
846
+ const isLoadingOlderRef = useRef(false);
847
+ const scrollTimeoutRef = useRef(null);
848
+ const shouldAutoScrollRef = useRef(true);
849
+ const hasInitializedRef = useRef(false);
850
+
851
+ const auth = useSelector(userSelector);
852
+ const { startUpload } = useUploadFiles();
853
+ const [sendMsg] = useSendMessagesMutation();
854
+
855
+ const { data, loading: messageLoading, fetchMore: fetchMoreMessages, subscribeToMore } = MessagesLoaderQuery || {};
856
+
857
+ // Get messages directly from Apollo cache
858
+ const messages = useMemo(() => {
859
+ const messagesData = data?.messages?.data || [];
860
+ return orderBy(uniqBy(messagesData, 'id'), ['createdAt'], ['asc']);
861
+ }, [data?.messages?.data]);
862
+
863
+ const totalCount = data?.messages?.totalCount || 0;
864
+
865
+ const scrollToBottom = useCallback(() => {
866
+ if (messageRootListRef?.current) {
867
+ messageRootListRef.current.scrollTop = messageRootListRef.current.scrollHeight;
868
+ }
869
+ }, []);
870
+
871
+ // Auto-scroll rules:
872
+ // - Initial load: once messages arrive the first time
873
+ // - When user is at bottom and new messages arrive
874
+ // - When we explicitly set shouldAutoScrollRef (e.g., on send)
875
+ useEffect(() => {
876
+ if (isLoadingOlderRef.current) return;
877
+
878
+ // Initial load: first time messages appear
879
+ if (!hasInitializedRef.current && messages.length > 0) {
880
+ hasInitializedRef.current = true;
881
+ const timer = setTimeout(() => scrollToBottom(), 100);
882
+ return () => clearTimeout(timer);
883
+ }
884
+
885
+ if (shouldAutoScrollRef.current) {
886
+ const timer = setTimeout(() => scrollToBottom(), 100);
887
+ return () => clearTimeout(timer);
888
+ }
889
+ }, [messages.length, scrollToBottom]);
890
+
891
+ const onFetchOld = useCallback(
892
+ async (skip: number) => {
893
+ if (channelId && fetchMoreMessages && !isLoadingOlder) {
894
+ try {
895
+ setIsLoadingOlder(true);
896
+ isLoadingOlderRef.current = true;
897
+ // Capture current scroll height before fetching
898
+ const oldScrollHeight = messageRootListRef?.current?.scrollHeight || 0;
899
+
900
+ await fetchMoreMessages({
901
+ variables: {
902
+ channelId: channelId.toString(),
903
+ parentId: null,
904
+ skip,
905
+ },
906
+ updateQuery: (prev, { fetchMoreResult }) => {
907
+ if (!fetchMoreResult) return prev;
908
+
909
+ const newMessages = fetchMoreResult.messages.data;
910
+ const existingMessages = prev.messages?.data || [];
911
+
912
+ return {
913
+ ...prev,
914
+ messages: {
915
+ ...fetchMoreResult.messages,
916
+ data: uniqBy([...newMessages, ...existingMessages], 'id'),
917
+ },
918
+ };
919
+ },
920
+ });
921
+
922
+ // Maintain scroll position after loading older messages
923
+ setTimeout(() => {
924
+ if (messageRootListRef?.current) {
925
+ const newScrollHeight = messageRootListRef.current.scrollHeight;
926
+ const scrollDiff = newScrollHeight - oldScrollHeight;
927
+ // For normal flex layout, maintain position by adjusting scroll offset
928
+ messageRootListRef.current.scrollTop = scrollDiff;
929
+ }
930
+ // Reset the loading flag after position is maintained
931
+ setTimeout(() => {
932
+ isLoadingOlderRef.current = false;
933
+ }, 50);
934
+ }, 100);
935
+ } catch (error) {
936
+ console.error('Error fetching older messages:', error);
937
+ isLoadingOlderRef.current = false;
938
+ } finally {
939
+ setIsLoadingOlder(false);
940
+ }
941
+ }
942
+ },
943
+ [channelId, fetchMoreMessages, isLoadingOlder],
944
+ );
945
+
946
+ // Scroll to bottom when channel changes
947
+ useEffect(() => {
948
+ if (channelId && messages.length > 0) {
949
+ isLoadingOlderRef.current = false; // Reset flag on channel change
950
+ const timer = setTimeout(() => scrollToBottom(), 200);
951
+ return () => clearTimeout(timer);
952
+ }
953
+ }, [channelId, scrollToBottom]);
954
+
955
+ // Alternative scroll detection for Firefox
956
+ useEffect(() => {
957
+ const element = messageRootListRef.current;
958
+ if (!element) return;
959
+
960
+ // Firefox-specific scroll detection using passive listeners
961
+ const handleScrollEnd = () => {
962
+ if (!isLoadingOlder && element) {
963
+ const { scrollTop } = element;
964
+ const isAtTop = Math.round(scrollTop) <= 30;
965
+ const hasMoreMessages = totalCount > messages.length;
966
+
967
+ if (isAtTop && hasMoreMessages) {
968
+ console.log('ScrollEnd triggered load more (Firefox):', {
969
+ scrollTop: Math.round(scrollTop),
970
+ totalCount,
971
+ messagesLength: messages.length,
972
+ });
973
+ onFetchOld(messages.length);
974
+ }
975
+ }
976
+ };
977
+
978
+ // Use scrollend event if available (modern Firefox/Chrome)
979
+ if ('onscrollend' in element) {
980
+ element.addEventListener('scrollend', handleScrollEnd, { passive: true });
981
+ return () => {
982
+ element.removeEventListener('scrollend', handleScrollEnd);
983
+ };
984
+ }
985
+ }, [totalCount, messages.length, onFetchOld, isLoadingOlder]);
986
+
987
+ // Cleanup scroll timeout on unmount
988
+ useEffect(() => {
989
+ return () => {
990
+ if (scrollTimeoutRef.current) {
991
+ clearTimeout(scrollTimeoutRef.current);
992
+ }
993
+ };
994
+ }, []);
995
+
996
+ const onMessagesScroll = useCallback(
997
+ async (e: any) => {
998
+ // Throttle scroll events for better performance, especially in Firefox
999
+ if (scrollTimeoutRef.current) {
1000
+ clearTimeout(scrollTimeoutRef.current);
1001
+ }
1002
+
1003
+ scrollTimeoutRef.current = setTimeout(async () => {
1004
+ if (messageRootListRef.current && !isLoadingOlder) {
1005
+ const element = messageRootListRef.current;
1006
+ const { clientHeight, scrollHeight, scrollTop } = element;
1007
+
1008
+ // Firefox-compatible scroll detection
1009
+ // Use Math.ceil to handle Firefox's fractional scrollTop values
1010
+ const isAtTop = Math.ceil(scrollTop) <= 25;
1011
+ const hasMoreMessages = totalCount > messages.length;
1012
+
1013
+ // Track bottom proximity to decide future auto-scroll behavior
1014
+ const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
1015
+ const isAtBottom = distanceFromBottom <= 30;
1016
+ // Only auto-scroll for future incoming messages if user is at bottom
1017
+ shouldAutoScrollRef.current = isAtBottom;
1018
+
1019
+ // Additional Firefox-specific check
1020
+ const isFirefox = navigator.userAgent.includes('Firefox');
1021
+ const firefoxAdjustedTop = isFirefox ? Math.round(scrollTop) <= 30 : isAtTop;
1022
+
1023
+ if ((isAtTop || firefoxAdjustedTop) && hasMoreMessages) {
1024
+ console.log('Triggering load more:', {
1025
+ scrollTop: Math.ceil(scrollTop),
1026
+ originalScrollTop: scrollTop,
1027
+ totalCount,
1028
+ messagesLength: messages.length,
1029
+ scrollHeight,
1030
+ clientHeight,
1031
+ browser: isFirefox ? 'Firefox' : 'Other',
1032
+ isAtTop,
1033
+ firefoxAdjustedTop,
1034
+ });
1035
+ await onFetchOld(messages.length);
1036
+ }
1037
+ }
1038
+ }, 100);
1039
+ },
1040
+ [totalCount, messages.length, onFetchOld, isLoadingOlder],
1041
+ );
1042
+
1043
+ // Optimistic message sending with Apollo cache updates
1044
+ const handleSend = useCallback(
1045
+ async (message: string, files: any[] = []) => {
1046
+ // Allow sending if there's either a message or files
1047
+ if ((!message || !message.trim()) && (!files || files.length === 0)) return;
1048
+ if (!channelId) return;
1049
+
1050
+ try {
1051
+ // Ensure we auto-scroll when sending a new message
1052
+ shouldAutoScrollRef.current = true;
1053
+ setTimeout(() => scrollToBottom(), 0);
1054
+ const postId = objectId();
1055
+ const currentDate = new Date();
1056
+
1057
+ const createOptimisticMessage = (files?: any[]) => ({
1058
+ __typename: 'Post' as const,
1059
+ id: postId,
1060
+ message,
1061
+ createdAt: currentDate.toISOString(),
1062
+ updatedAt: currentDate.toISOString(),
1063
+ author: {
1064
+ __typename: 'UserAccount' as const,
1065
+ id: auth?.id,
1066
+ givenName: auth?.profile?.given_name || '',
1067
+ familyName: auth?.profile?.family_name || '',
1068
+ email: auth?.profile?.email || '',
1069
+ username: auth?.profile?.nickname || '',
1070
+ fullName: auth?.profile?.name || '',
1071
+ picture: auth?.profile?.picture || '',
1072
+ alias: [auth?.authUserId ?? ''],
1073
+ tokens: [],
1074
+ },
1075
+ isDelivered: false, // Will be true once confirmed by server
1076
+ isRead: false,
1077
+ type: 'TEXT' as PostTypeEnum,
1078
+ parentId: null,
1079
+ fromServer: false,
1080
+ channel: {
1081
+ __typename: 'Channel' as const,
1082
+ id: channelId,
1083
+ },
1084
+ propsConfiguration: {
1085
+ __typename: 'MachineConfiguration' as const,
1086
+ id: null,
1087
+ resource: '' as any,
1088
+ contents: null,
1089
+ keys: null,
1090
+ target: null,
1091
+ overrides: null,
1092
+ },
1093
+ props: {},
1094
+ files: {
1095
+ __typename: 'FilesInfo' as const,
1096
+ data: files || [],
1097
+ totalCount: files?.length || 0,
1098
+ },
1099
+ replies: {
1100
+ __typename: 'Messages' as const,
1101
+ data: [],
1102
+ totalCount: 0,
1103
+ },
1104
+ });
1105
+
1106
+ const optimisticMessage = createOptimisticMessage(files);
1107
+
1108
+ if (files?.length > 0) {
1109
+ const uploadResponse = await startUpload({
1110
+ file: files,
1111
+ saveUploadedFile: { variables: { postId } },
1112
+ createUploadLink: { variables: { postId } },
1113
+ });
1114
+
1115
+ const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
1116
+ if (uploadedFiles) {
1117
+ const fileIds = uploadedFiles.map((f: any) => f.id);
1118
+ await sendMsg({
1119
+ variables: { postId, channelId, content: message, files: fileIds },
1120
+ optimisticResponse: {
1121
+ __typename: 'Mutation',
1122
+ sendMessage: createOptimisticMessage(uploadedFiles),
1123
+ },
1124
+ update: (cache, { data: mutationData }) => {
1125
+ if (!mutationData?.sendMessage) return;
1126
+
1127
+ // Update messages cache optimistically
1128
+ const messagesQuery = {
1129
+ query: MessagesDocument,
1130
+ variables: {
1131
+ channelId: channelId.toString(),
1132
+ parentId: null,
1133
+ limit: MESSAGES_PER_PAGE,
1134
+ },
1135
+ };
1136
+
1137
+ try {
1138
+ const existingData = cache.readQuery(messagesQuery) as any;
1139
+ if (existingData?.messages) {
1140
+ cache.writeQuery({
1141
+ ...messagesQuery,
1142
+ data: {
1143
+ messages: {
1144
+ ...existingData.messages,
1145
+ data: [
1146
+ ...(existingData.messages.data || []),
1147
+ mutationData.sendMessage,
1148
+ ],
1149
+ totalCount: (existingData.messages.totalCount || 0) + 1,
1150
+ },
1151
+ },
1152
+ });
1153
+ }
1154
+ } catch (error) {
1155
+ console.debug('Cache update failed (expected on first message):', error);
1156
+ }
1157
+ },
1158
+ });
1159
+ }
1160
+ } else {
1161
+ await sendMsg({
1162
+ variables: { channelId, content: message },
1163
+ optimisticResponse: {
1164
+ __typename: 'Mutation',
1165
+ sendMessage: optimisticMessage,
1166
+ },
1167
+ update: (cache, { data: mutationData }) => {
1168
+ if (!mutationData?.sendMessage) return;
1169
+
1170
+ // Update messages cache optimistically
1171
+ const messagesQuery = {
1172
+ query: MessagesDocument,
1173
+ variables: {
1174
+ channelId: channelId.toString(),
1175
+ parentId: null,
1176
+ limit: MESSAGES_PER_PAGE,
1177
+ },
1178
+ };
1179
+
1180
+ try {
1181
+ const existingData = cache.readQuery(messagesQuery) as any;
1182
+ if (existingData?.messages) {
1183
+ cache.writeQuery({
1184
+ ...messagesQuery,
1185
+ data: {
1186
+ messages: {
1187
+ ...existingData.messages,
1188
+ data: [...(existingData.messages.data || []), mutationData.sendMessage],
1189
+ totalCount: (existingData.messages.totalCount || 0) + 1,
1190
+ },
1191
+ },
1192
+ });
1193
+ }
1194
+ } catch (error) {
1195
+ console.debug('Cache update failed (expected on first message):', error);
1196
+ }
1197
+ },
1198
+ });
1199
+ }
1200
+ } catch (error) {
1201
+ console.error('Error sending message:', error);
1202
+ }
1203
+ },
1204
+ [channelId, auth, startUpload, sendMsg, scrollToBottom],
1205
+ );
1206
+
1207
+ // Show loading spinner for initial load
1208
+ if ((messageLoading || channelLoading) && messages.length === 0) {
1209
+ return (
1210
+ <div className="flex-1 flex justify-center items-center">
1211
+ <Spinner className="w-12 h-12" />
1212
+ </div>
1213
+ );
1214
+ }
1215
+
1216
+ return (
1217
+ <>
1218
+ <div
1219
+ ref={messageRootListRef}
1220
+ className={`overflow-y-scroll bg-gray-50 ${
1221
+ isSmallScreen ? 'p-2 px-3' : isDesktopView ? 'p-6 px-8' : 'p-4 px-6'
1222
+ }`}
1223
+ onScroll={onMessagesScroll}
1224
+ style={{
1225
+ height: `${windowHeight - 140}px`, // Subtract header + input height
1226
+ maxHeight: '100vh',
1227
+ scrollbarWidth: 'thin',
1228
+ scrollbarColor: '#cbd5e0 #f7fafc',
1229
+ overflowY: 'scroll',
1230
+ WebkitOverflowScrolling: 'touch',
1231
+ }}
1232
+ >
1233
+ <div className="min-h-full">
1234
+ {messages.length > 0 ? (
1235
+ <>
1236
+ {/* Loading indicator for older messages at the top */}
1237
+ {isLoadingOlder && (
1238
+ <div className="flex justify-center py-4">
1239
+ <div className="flex items-center space-x-2 text-gray-500">
1240
+ <Spinner className="w-4 h-4" />
1241
+ <span className="text-sm">Loading older messages...</span>
1242
+ </div>
1243
+ </div>
1244
+ )}
1245
+ <Messages
1246
+ innerRef={messageListRef}
1247
+ channelId={channelId}
1248
+ currentUser={auth}
1249
+ channelMessages={messages}
1250
+ totalCount={totalCount}
1251
+ onMessageClick={onMessageClick}
1252
+ isDesktopView={isDesktopView || false}
1253
+ isSmallScreen={isSmallScreen || false}
1254
+ />
1255
+ <SubscriptionHandler
1256
+ subscribeToMore={subscribeToMore}
1257
+ document={CHAT_MESSAGE_ADDED}
1258
+ variables={{ channelId: channelId.toString() }}
1259
+ enabled={!!channelId && !!subscribeToMore}
1260
+ updateQuery={(prev: any, { subscriptionData }: any) => {
1261
+ console.log('Subscription updateQuery called:', { prev, subscriptionData });
1262
+ if (!subscriptionData.data) {
1263
+ console.log('No subscription data, returning prev');
1264
+ return prev;
1265
+ }
1266
+ const newMessage = subscriptionData.data.chatMessageAdded;
1267
+ console.log('New message received via subscription:', newMessage);
1268
+
1269
+ return {
1270
+ ...prev,
1271
+ messages: {
1272
+ ...prev?.messages,
1273
+ data: uniqBy([...(prev?.messages?.data || []), newMessage], 'id'),
1274
+ totalCount: (prev?.messages?.totalCount || 0) + 1,
1275
+ },
1276
+ };
1277
+ }}
1278
+ onError={(error) => {
1279
+ console.error('Subscription error:', error);
1280
+ }}
1281
+ />
1282
+ </>
1283
+ ) : (
1284
+ <div className="flex items-center justify-center text-gray-500 min-h-96">
1285
+ <div className="text-center max-w-sm mx-auto px-4">
1286
+ <div className="text-6xl mb-4 opacity-50">💬</div>
1287
+ <h3 className="text-lg font-semibold text-gray-600 mb-2">No messages yet</h3>
1288
+ <p className="text-sm text-gray-500">
1289
+ Start the conversation by sending a message below!
1290
+ </p>
1291
+ </div>
1292
+ </div>
1293
+ )}
1294
+ </div>
1295
+ </div>
1296
+ <div className="flex-shrink-0 border-t border-gray-200 bg-white">
1297
+ {/* Selection Options */}
1298
+ <div className="px-4 py-3 border-b border-gray-100">
1299
+ <div className="flex gap-3">
1300
+ {/* Framework Selection */}
1301
+ <div className="flex-1 relative">
1302
+ <button
1303
+ type="button"
1304
+ className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-left pr-10 flex items-center space-x-2"
1305
+ onClick={() => {
1306
+ const modal = document.getElementById('framework-modal');
1307
+ if (modal) {
1308
+ modal.classList.toggle('hidden');
1309
+ }
1310
+ }}
1311
+ >
1312
+ <div className="w-5 h-5 bg-purple-100 rounded flex items-center justify-center">⚛️</div>
1313
+ <span>Next.js</span>
1314
+ </button>
1315
+ <div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
1316
+ <svg
1317
+ className="w-4 h-4 text-gray-400"
1318
+ fill="none"
1319
+ stroke="currentColor"
1320
+ viewBox="0 0 24 24"
1321
+ >
1322
+ <path
1323
+ strokeLinecap="round"
1324
+ strokeLinejoin="round"
1325
+ strokeWidth={2}
1326
+ d="M19 9l-7 7-7-7"
1327
+ />
1328
+ </svg>
1329
+ </div>
1330
+
1331
+ {/* Framework Modal */}
1332
+ <div
1333
+ id="framework-modal"
1334
+ className="hidden absolute bottom-full left-0 mb-1 w-80 bg-white border border-gray-200 rounded-lg shadow-lg z-50 p-4"
1335
+ >
1336
+ <div className="space-y-2">
1337
+ <div className="flex items-center justify-between p-3 hover:bg-gray-50 rounded cursor-pointer border border-blue-300 bg-blue-50">
1338
+ <div className="flex items-center space-x-3">
1339
+ <div className="w-8 h-8 bg-purple-100 rounded flex items-center justify-center">
1340
+ ⚛️
1341
+ </div>
1342
+ <div>
1343
+ <div className="text-sm font-medium">Next.js</div>
1344
+ <div className="text-xs text-gray-500">
1345
+ React + Next.js 15 with Shadcn UI
1346
+ </div>
1347
+ </div>
1348
+ </div>
1349
+ <svg className="w-4 h-4 text-blue-500" fill="currentColor" viewBox="0 0 20 20">
1350
+ <path
1351
+ fillRule="evenodd"
1352
+ d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
1353
+ clipRule="evenodd"
1354
+ />
1355
+ </svg>
1356
+ </div>
1357
+
1358
+ <div className="flex items-center p-3 hover:bg-gray-50 rounded cursor-pointer">
1359
+ <div className="flex items-center space-x-3">
1360
+ <div className="w-8 h-8 bg-green-100 rounded flex items-center justify-center">
1361
+ 💚
1362
+ </div>
1363
+ <div>
1364
+ <div className="text-sm font-medium">Vue.js</div>
1365
+ <div className="text-xs text-gray-500">
1366
+ Vue 3 + Nuxt 3 with Tailwind CSS
1367
+ </div>
1368
+ </div>
1369
+ </div>
1370
+ </div>
1371
+
1372
+ <div className="flex items-center p-3 hover:bg-gray-50 rounded cursor-pointer">
1373
+ <div className="flex items-center space-x-3">
1374
+ <div className="w-8 h-8 bg-blue-100 rounded flex items-center justify-center">
1375
+ ⚛️
1376
+ </div>
1377
+ <div>
1378
+ <div className="text-sm font-medium">React</div>
1379
+ <div className="text-xs text-gray-500">
1380
+ React 18 + Vite with TypeScript
1381
+ </div>
1382
+ </div>
1383
+ </div>
1384
+ </div>
1385
+
1386
+ <div className="flex items-center p-3 hover:bg-gray-50 rounded cursor-pointer">
1387
+ <div className="flex items-center space-x-3">
1388
+ <div className="w-8 h-8 bg-red-100 rounded flex items-center justify-center">
1389
+ 🅰️
1390
+ </div>
1391
+ <div>
1392
+ <div className="text-sm font-medium">Angular</div>
1393
+ <div className="text-xs text-gray-500">
1394
+ Angular 17 + Material Design
1395
+ </div>
1396
+ </div>
1397
+ </div>
1398
+ </div>
1399
+
1400
+ <div className="flex items-center p-3 hover:bg-gray-50 rounded cursor-pointer">
1401
+ <div className="flex items-center space-x-3">
1402
+ <div className="w-8 h-8 bg-orange-100 rounded flex items-center justify-center">
1403
+ 🔥
1404
+ </div>
1405
+ <div>
1406
+ <div className="text-sm font-medium">Svelte</div>
1407
+ <div className="text-xs text-gray-500">SvelteKit + TailwindCSS</div>
1408
+ </div>
1409
+ </div>
1410
+ </div>
1411
+ </div>
1412
+ </div>
1413
+ </div>
1414
+
1415
+ {/* AI Model Selection */}
1416
+ <div className="flex-1 relative">
1417
+ <button
1418
+ type="button"
1419
+ className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-left pr-10"
1420
+ onClick={() => {
1421
+ const modal = document.getElementById('ai-model-modal');
1422
+ if (modal) {
1423
+ modal.classList.toggle('hidden');
1424
+ }
1425
+ }}
1426
+ >
1427
+ 🧠 Claude 3.5 Sonnet
1428
+ </button>
1429
+ <div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
1430
+ <svg
1431
+ className="w-4 h-4 text-gray-400"
1432
+ fill="none"
1433
+ stroke="currentColor"
1434
+ viewBox="0 0 24 24"
1435
+ >
1436
+ <path
1437
+ strokeLinecap="round"
1438
+ strokeLinejoin="round"
1439
+ strokeWidth={2}
1440
+ d="M19 9l-7 7-7-7"
1441
+ />
1442
+ </svg>
1443
+ </div>
1444
+
1445
+ {/* AI Model Modal */}
1446
+ <div
1447
+ id="ai-model-modal"
1448
+ className="hidden absolute bottom-full left-0 mb-1 w-72 bg-white border border-gray-200 rounded-lg shadow-lg z-50 p-4"
1449
+ >
1450
+ <div className="space-y-3">
1451
+ {/* Claude Models */}
1452
+ <div id="claude-models" className="space-y-2">
1453
+ <div className="flex items-center justify-between p-2 hover:bg-gray-50 rounded cursor-pointer">
1454
+ <div className="flex items-center space-x-3">
1455
+ <div className="w-6 h-6 bg-orange-100 rounded flex items-center justify-center">
1456
+ 🧠
1457
+ </div>
1458
+ <span className="text-sm font-medium">Claude 3.5 Sonnet</span>
1459
+ </div>
1460
+ <svg
1461
+ className="w-4 h-4 text-blue-500"
1462
+ fill="currentColor"
1463
+ viewBox="0 0 20 20"
1464
+ >
1465
+ <path
1466
+ fillRule="evenodd"
1467
+ d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
1468
+ clipRule="evenodd"
1469
+ />
1470
+ </svg>
1471
+ </div>
1472
+
1473
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1474
+ <div className="flex items-center space-x-3">
1475
+ <div className="w-6 h-6 bg-orange-100 rounded flex items-center justify-center">
1476
+ 🧠
1477
+ </div>
1478
+ <span className="text-sm">Claude 3.5 Haiku</span>
1479
+ </div>
1480
+ </div>
1481
+
1482
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1483
+ <div className="flex items-center space-x-3">
1484
+ <div className="w-6 h-6 bg-orange-100 rounded flex items-center justify-center">
1485
+ 🧠
1486
+ </div>
1487
+ <span className="text-sm">Claude 3 Opus</span>
1488
+ </div>
1489
+ </div>
1490
+
1491
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1492
+ <div className="flex items-center space-x-3">
1493
+ <div className="w-6 h-6 bg-orange-100 rounded flex items-center justify-center">
1494
+ 🧠
1495
+ </div>
1496
+ <span className="text-sm">Claude 3 Sonnet</span>
1497
+ </div>
1498
+ </div>
1499
+
1500
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1501
+ <div className="flex items-center space-x-3">
1502
+ <div className="w-6 h-6 bg-orange-100 rounded flex items-center justify-center">
1503
+ 🧠
1504
+ </div>
1505
+ <span className="text-sm">Claude 3 Haiku</span>
1506
+ </div>
1507
+ </div>
1508
+ </div>
1509
+
1510
+ {/* OpenAI Models */}
1511
+ <div id="openai-models" className="space-y-2 hidden">
1512
+ <div className="flex items-center justify-between p-2 hover:bg-gray-50 rounded cursor-pointer">
1513
+ <div className="flex items-center space-x-3">
1514
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1515
+ 🤖
1516
+ </div>
1517
+ <span className="text-sm font-medium">GPT-4o</span>
1518
+ </div>
1519
+ <svg
1520
+ className="w-4 h-4 text-blue-500"
1521
+ fill="currentColor"
1522
+ viewBox="0 0 20 20"
1523
+ >
1524
+ <path
1525
+ fillRule="evenodd"
1526
+ d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
1527
+ clipRule="evenodd"
1528
+ />
1529
+ </svg>
1530
+ </div>
1531
+
1532
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1533
+ <div className="flex items-center space-x-3">
1534
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1535
+ 🤖
1536
+ </div>
1537
+ <span className="text-sm">GPT-4o mini</span>
1538
+ </div>
1539
+ </div>
1540
+
1541
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1542
+ <div className="flex items-center space-x-3">
1543
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1544
+ 🤖
1545
+ </div>
1546
+ <span className="text-sm">GPT-4 Turbo</span>
1547
+ </div>
1548
+ </div>
1549
+
1550
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1551
+ <div className="flex items-center space-x-3">
1552
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1553
+ 🤖
1554
+ </div>
1555
+ <span className="text-sm">GPT-4</span>
1556
+ </div>
1557
+ </div>
1558
+
1559
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1560
+ <div className="flex items-center space-x-3">
1561
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1562
+ 🤖
1563
+ </div>
1564
+ <span className="text-sm">o1</span>
1565
+ </div>
1566
+ </div>
1567
+
1568
+ <div className="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
1569
+ <div className="flex items-center space-x-3">
1570
+ <div className="w-6 h-6 bg-green-100 rounded flex items-center justify-center">
1571
+ 🤖
1572
+ </div>
1573
+ <span className="text-sm">o1-mini</span>
1574
+ </div>
1575
+ </div>
1576
+ </div>
1577
+
1578
+ {/* Provider Buttons */}
1579
+ <div className="flex gap-2 pt-2 border-t border-gray-100">
1580
+ <button
1581
+ id="openai-btn"
1582
+ className="flex-1 px-3 py-2 border border-gray-300 text-gray-700 text-sm rounded-md hover:bg-gray-50 transition-colors"
1583
+ onClick={() => {
1584
+ document.getElementById('claude-models')?.classList.add('hidden');
1585
+ document.getElementById('openai-models')?.classList.remove('hidden');
1586
+ document
1587
+ .getElementById('openai-btn')
1588
+ ?.classList.add('bg-blue-500', 'text-white');
1589
+ document
1590
+ .getElementById('openai-btn')
1591
+ ?.classList.remove('border-gray-300', 'text-gray-700');
1592
+ document
1593
+ .getElementById('anthropic-btn')
1594
+ ?.classList.remove('bg-blue-500', 'text-white');
1595
+ document
1596
+ .getElementById('anthropic-btn')
1597
+ ?.classList.add('border-gray-300', 'text-gray-700');
1598
+ }}
1599
+ >
1600
+ OpenAI
1601
+ </button>
1602
+ <button
1603
+ id="anthropic-btn"
1604
+ className="flex-1 px-3 py-2 bg-blue-500 text-white text-sm rounded-md hover:bg-blue-600 transition-colors"
1605
+ onClick={() => {
1606
+ document.getElementById('openai-models')?.classList.add('hidden');
1607
+ document.getElementById('claude-models')?.classList.remove('hidden');
1608
+ document
1609
+ .getElementById('anthropic-btn')
1610
+ ?.classList.add('bg-blue-500', 'text-white');
1611
+ document
1612
+ .getElementById('anthropic-btn')
1613
+ ?.classList.remove('border-gray-300', 'text-gray-700');
1614
+ document
1615
+ .getElementById('openai-btn')
1616
+ ?.classList.remove('bg-blue-500', 'text-white');
1617
+ document
1618
+ .getElementById('openai-btn')
1619
+ ?.classList.add('border-gray-300', 'text-gray-700');
1620
+ }}
1621
+ >
1622
+ Anthropic
1623
+ </button>
1624
+ </div>
1625
+ </div>
1626
+ </div>
1627
+ </div>
1628
+
1629
+ {/* API Key Dropdown */}
1630
+ <div className="flex-1 relative">
1631
+ <button
1632
+ type="button"
1633
+ className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-left pr-10"
1634
+ onClick={() => {
1635
+ const modal = document.getElementById('api-key-modal');
1636
+ if (modal) {
1637
+ modal.classList.toggle('hidden');
1638
+ }
1639
+ }}
1640
+ >
1641
+ API Key ••••
1642
+ </button>
1643
+ <div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
1644
+ <svg
1645
+ className="w-4 h-4 text-gray-400"
1646
+ fill="none"
1647
+ stroke="currentColor"
1648
+ viewBox="0 0 24 24"
1649
+ >
1650
+ <path
1651
+ strokeLinecap="round"
1652
+ strokeLinejoin="round"
1653
+ strokeWidth={2}
1654
+ d="M19 9l-7 7-7-7"
1655
+ />
1656
+ </svg>
1657
+ </div>
1658
+
1659
+ {/* API Key Modal */}
1660
+ <div id="api-key-modal" className="hidden">
1661
+ {/* Modal Backdrop */}
1662
+ <div
1663
+ className="fixed inset-0 bg-opacity-50 z-[9998]"
1664
+ onClick={() => {
1665
+ const modal = document.getElementById('api-key-modal');
1666
+ if (modal) {
1667
+ modal.classList.add('hidden');
1668
+ }
1669
+ }}
1670
+ ></div>
1671
+
1672
+ {/* Modal Content */}
1673
+ <div
1674
+ className="fixed w-80 bg-white border border-gray-200 rounded-lg shadow-lg z-[9999] p-4"
1675
+ style={{
1676
+ position: 'fixed',
1677
+ left: '50%',
1678
+ top: '50%',
1679
+ transform: 'translate(-50%, -50%)',
1680
+ zIndex: 9999,
1681
+ }}
1682
+ >
1683
+ {/* Close Button */}
1684
+ <div className="flex justify-between items-center mb-4">
1685
+ <h3 className="text-lg font-semibold text-gray-900">API Key Settings</h3>
1686
+ <button
1687
+ type="button"
1688
+ className="text-gray-400 hover:text-gray-600 transition-colors"
1689
+ onClick={() => {
1690
+ const modal = document.getElementById('api-key-modal');
1691
+ if (modal) {
1692
+ modal.classList.add('hidden');
1693
+ }
1694
+ }}
1695
+ >
1696
+ <svg
1697
+ className="w-5 h-5"
1698
+ fill="none"
1699
+ stroke="currentColor"
1700
+ viewBox="0 0 24 24"
1701
+ >
1702
+ <path
1703
+ strokeLinecap="round"
1704
+ strokeLinejoin="round"
1705
+ strokeWidth={2}
1706
+ d="M6 18L18 6M6 6l12 12"
1707
+ />
1708
+ </svg>
1709
+ </button>
1710
+ </div>
1711
+
1712
+ <div className="space-y-4">
1713
+ {/* API Key Input Section */}
1714
+ <div>
1715
+ <label className="block text-sm font-medium text-gray-700 mb-2">
1716
+ API Key
1717
+ </label>
1718
+ <div className="relative">
1719
+ <input
1720
+ type="password"
1721
+ placeholder="••••••••••••••••••••••••••••••••••••••••••••"
1722
+ className="w-full px-3 py-2 text-sm border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent pr-10"
1723
+ />
1724
+ <button
1725
+ type="button"
1726
+ className="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600"
1727
+ onClick={(e) => {
1728
+ const input = e.currentTarget
1729
+ .previousElementSibling as HTMLInputElement;
1730
+ if (input) {
1731
+ input.type =
1732
+ input.type === 'password' ? 'text' : 'password';
1733
+ }
1734
+ }}
1735
+ >
1736
+ <svg
1737
+ className="w-4 h-4"
1738
+ fill="none"
1739
+ stroke="currentColor"
1740
+ viewBox="0 0 24 24"
1741
+ >
1742
+ <path
1743
+ strokeLinecap="round"
1744
+ strokeLinejoin="round"
1745
+ strokeWidth={2}
1746
+ d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
1747
+ />
1748
+ <path
1749
+ strokeLinecap="round"
1750
+ strokeLinejoin="round"
1751
+ strokeWidth={2}
1752
+ d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
1753
+ />
1754
+ </svg>
1755
+ </button>
1756
+ </div>
1757
+ </div>
1758
+
1759
+ {/* Parameters Section */}
1760
+ <div>
1761
+ <h3 className="text-sm font-medium text-gray-700 mb-3">Parameters</h3>
1762
+ <div className="space-y-2">
1763
+ <div className="flex justify-between items-center">
1764
+ <span className="text-sm text-gray-600">Output tokens</span>
1765
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1766
+ Auto
1767
+ </span>
1768
+ </div>
1769
+ <div className="flex justify-between items-center">
1770
+ <span className="text-sm text-gray-600">Temperature</span>
1771
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1772
+ Auto
1773
+ </span>
1774
+ </div>
1775
+ <div className="flex justify-between items-center">
1776
+ <span className="text-sm text-gray-600">Top P</span>
1777
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1778
+ Auto
1779
+ </span>
1780
+ </div>
1781
+ <div className="flex justify-between items-center">
1782
+ <span className="text-sm text-gray-600">Top K</span>
1783
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1784
+ Auto
1785
+ </span>
1786
+ </div>
1787
+ <div className="flex justify-between items-center">
1788
+ <span className="text-sm text-gray-600">Frequence penalty</span>
1789
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1790
+ Auto
1791
+ </span>
1792
+ </div>
1793
+ <div className="flex justify-between items-center">
1794
+ <span className="text-sm text-gray-600">Presence penalty</span>
1795
+ <span className="text-sm text-gray-500 bg-gray-100 px-2 py-1 rounded">
1796
+ Auto
1797
+ </span>
1798
+ </div>
1799
+ </div>
1800
+ </div>
1801
+ </div>
1802
+ </div>
1803
+ </div>
1804
+ </div>
1805
+ </div>
1806
+ </div>
1807
+ <MessageInputComponent channelId={channelId} handleSend={handleSend} placeholder="Message" />
1808
+ </div>
1809
+ </>
1810
+ );
1811
+ });
1812
+
1813
+ // Display names for debugging
1814
+ Inbox.displayName = 'Inbox';
1815
+ ContentComponent.displayName = 'ContentComponent';
1816
+ MessagesComponent.displayName = 'MessagesComponent';
1817
+ RightSidebarWrapper.displayName = 'RightSidebarWrapper';
1818
+
1819
+ export default React.memo(Inbox);