11import type { ChannelFilters , ChannelOptions , ChannelSort } from 'stream-chat' ;
2- import {
3- Chat ,
4- Channel ,
5- MessageList ,
6- useCreateChatClient ,
7- ChannelList ,
8- Window ,
9- MessageInput ,
10- useChatContext ,
11- } from 'stream-chat-react' ;
12- import { Composer } from './components/Composer' ;
13- import { MessageBubble } from './components/MessageBubble' ;
14- import { AIStateIndicator } from './components/AIStateIndicator' ;
15- import { useEffect } from 'react' ;
16- import { nanoid } from 'nanoid' ;
17- import { ChannelListItem } from './components/ChannelListItem' ;
2+ import { Chat , useCreateChatClient } from 'stream-chat-react' ;
3+
4+ import { ChatContent } from './components/ChatContent' ;
185
196const userToken = import . meta. env . VITE_STREAM_USER_TOKEN ;
207const apiKey = import . meta. env . VITE_STREAM_API_KEY ;
@@ -43,41 +30,6 @@ const filters: ChannelFilters = {
4330const options : ChannelOptions = { limit : 5 } ;
4431const sort : ChannelSort = { pinned_at : 1 , last_message_at : - 1 , updated_at : - 1 } ;
4532
46- const ChatContent = ( ) => {
47- const { setActiveChannel, client, channel } = useChatContext ( ) ;
48-
49- useEffect ( ( ) => {
50- if ( ! channel ) {
51- setActiveChannel (
52- client . channel ( 'messaging' , `ai-${ nanoid ( ) } ` , {
53- members : [ client . userID as string ] ,
54- // @ts -expect-error fix - this is a hack that allows a custom upload function to run
55- own_capabilities : [ 'upload-file' ] ,
56- } ) ,
57- ) ;
58- }
59- } , [ channel ] ) ;
60-
61- return (
62- < >
63- < ChannelList
64- Preview = { ChannelListItem }
65- setActiveChannelOnMount = { false }
66- filters = { filters }
67- sort = { sort }
68- options = { options }
69- />
70- < Channel initializeOnMount = { false } Message = { MessageBubble } >
71- < Window >
72- < MessageList />
73- < AIStateIndicator />
74- < MessageInput Input = { Composer } />
75- </ Window >
76- </ Channel >
77- </ >
78- ) ;
79- } ;
80-
8133function App ( ) {
8234 const chatClient = useCreateChatClient ( {
8335 apiKey : apiKey ! ,
@@ -93,7 +45,7 @@ function App() {
9345
9446 return (
9547 < Chat client = { chatClient } >
96- < ChatContent />
48+ < ChatContent filters = { filters } sort = { sort } options = { options } />
9749 </ Chat >
9850 ) ;
9951}
0 commit comments