@@ -20,6 +20,8 @@ import { hiddenPropertyView } from "comps/utils/propertyUtils";
2020import { EditorContext } from "comps/editorState" ;
2121
2222import { ChatBoxView } from "./components/ChatBoxView" ;
23+ import { ChatBoxContext } from "./ChatBoxContext" ;
24+ import type { ChatRoom , PendingRoomInvite } from "./store" ;
2325
2426// ─── Events ──────────────────────────────────────────────────────────────────
2527
@@ -220,60 +222,80 @@ ChatBoxPropertyView.displayName = "ChatBoxV2PropertyView";
220222
221223let ChatBoxV2Tmp = ( function ( ) {
222224 return new UICompBuilder ( childrenMap , ( props ) => {
225+ const messages = Array . isArray ( props . messages ) ? props . messages : [ ] ;
226+ const rooms = ( Array . isArray ( props . rooms ) ? props . rooms : [ ] ) as unknown as ChatRoom [ ] ;
227+ const typingUsers = Array . isArray ( props . typingUsers ) ? props . typingUsers : [ ] ;
228+ const pendingInvites = ( Array . isArray ( props . pendingInvites )
229+ ? props . pendingInvites
230+ : [ ] ) as unknown as PendingRoomInvite [ ] ;
231+ const currentRoom = rooms . find ( ( r ) => r . id === props . currentRoomId ) ?? null ;
232+
233+ const contextValue = {
234+ messages,
235+ rooms,
236+ currentRoomId : props . currentRoomId ,
237+ currentRoom,
238+ currentUserId : props . currentUserId ,
239+ currentUserName : props . currentUserName ,
240+ typingUsers,
241+ pendingInvites,
242+
243+ chatTitle : props . chatTitle ,
244+ messageText : props . messageText ,
245+ lastSentMessageText : props . lastSentMessageText ,
246+
247+ showHeader : props . showHeader ,
248+ showRoomsPanel : props . showRoomsPanel ,
249+ roomsPanelWidth : props . roomsPanelWidth ,
250+ allowRoomCreation : props . allowRoomCreation ,
251+ allowRoomSearch : props . allowRoomSearch ,
252+ style : props . style ,
253+ animationStyle : props . animationStyle ,
254+
255+ onEvent : props . onEvent ,
256+
257+ onRoomSwitch : ( roomId : string ) => {
258+ props . pendingRoomId . onChange ( roomId ) ;
259+ props . onEvent ( "roomSwitch" ) ;
260+ } ,
261+ onRoomJoin : ( roomId : string ) => {
262+ props . pendingRoomId . onChange ( roomId ) ;
263+ props . onEvent ( "roomJoin" ) ;
264+ } ,
265+ onRoomLeave : ( roomId : string ) => {
266+ props . pendingRoomId . onChange ( roomId ) ;
267+ props . onEvent ( "roomLeave" ) ;
268+ } ,
269+ onRoomCreate : (
270+ name : string ,
271+ type : "public" | "private" | "llm" ,
272+ description ?: string ,
273+ llmQueryName ?: string ,
274+ ) => {
275+ props . newRoomName . onChange ( name ) ;
276+ props . newRoomType . onChange ( type ) ;
277+ props . newRoomDescription . onChange ( description || "" ) ;
278+ props . newRoomLlmQuery . onChange ( llmQueryName || "" ) ;
279+ props . onEvent ( "roomCreate" ) ;
280+ } ,
281+ onInviteSend : ( toUserId : string ) => {
282+ props . inviteTargetUserId . onChange ( toUserId ) ;
283+ props . onEvent ( "inviteSend" ) ;
284+ } ,
285+ onInviteAccept : ( inviteId : string ) => {
286+ props . pendingInviteId . onChange ( inviteId ) ;
287+ props . onEvent ( "inviteAccept" ) ;
288+ } ,
289+ onInviteDecline : ( inviteId : string ) => {
290+ props . pendingInviteId . onChange ( inviteId ) ;
291+ props . onEvent ( "inviteDecline" ) ;
292+ } ,
293+ } ;
294+
223295 return (
224- < ChatBoxView
225- chatTitle = { props . chatTitle }
226- showHeader = { props . showHeader }
227- messages = { props . messages }
228- currentUserId = { props . currentUserId }
229- currentUserName = { props . currentUserName }
230- typingUsers = { props . typingUsers }
231- lastSentMessageText = { props . lastSentMessageText }
232- messageText = { props . messageText }
233- style = { props . style }
234- animationStyle = { props . animationStyle }
235- onEvent = { props . onEvent }
236- // Rooms panel
237- rooms = { props . rooms }
238- currentRoomId = { props . currentRoomId }
239- pendingInvites = { props . pendingInvites }
240- showRoomsPanel = { props . showRoomsPanel }
241- roomsPanelWidth = { props . roomsPanelWidth }
242- allowRoomCreation = { props . allowRoomCreation }
243- allowRoomSearch = { props . allowRoomSearch }
244- // Callbacks that set state then fire events
245- onRoomSwitch = { ( roomId ) => {
246- props . pendingRoomId . onChange ( roomId ) ;
247- props . onEvent ( "roomSwitch" ) ;
248- } }
249- onRoomJoin = { ( roomId ) => {
250- props . pendingRoomId . onChange ( roomId ) ;
251- props . onEvent ( "roomJoin" ) ;
252- } }
253- onRoomLeave = { ( roomId ) => {
254- props . pendingRoomId . onChange ( roomId ) ;
255- props . onEvent ( "roomLeave" ) ;
256- } }
257- onRoomCreate = { ( name , type , description , llmQueryName ) => {
258- props . newRoomName . onChange ( name ) ;
259- props . newRoomType . onChange ( type ) ;
260- props . newRoomDescription . onChange ( description || "" ) ;
261- props . newRoomLlmQuery . onChange ( llmQueryName || "" ) ;
262- props . onEvent ( "roomCreate" ) ;
263- } }
264- onInviteSend = { ( toUserId ) => {
265- props . inviteTargetUserId . onChange ( toUserId ) ;
266- props . onEvent ( "inviteSend" ) ;
267- } }
268- onInviteAccept = { ( inviteId ) => {
269- props . pendingInviteId . onChange ( inviteId ) ;
270- props . onEvent ( "inviteAccept" ) ;
271- } }
272- onInviteDecline = { ( inviteId ) => {
273- props . pendingInviteId . onChange ( inviteId ) ;
274- props . onEvent ( "inviteDecline" ) ;
275- } }
276- />
296+ < ChatBoxContext . Provider value = { contextValue } >
297+ < ChatBoxView />
298+ </ ChatBoxContext . Provider >
277299 ) ;
278300 } )
279301 . setPropertyViewFn ( ( children ) => (
0 commit comments