-
Notifications
You must be signed in to change notification settings - Fork 281
/
Copy pathApp.tsx
48 lines (40 loc) · 1.43 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React from 'react';
import { ChannelFilters, ChannelOptions, ChannelSort, StreamChat } from 'stream-chat';
import {
Channel,
ChannelHeader,
ChannelList,
Chat,
MessageInput,
Thread,
VirtualizedMessageList as MessageList,
Window,
} from 'stream-chat-react';
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, property) => searchParams.get(property as string),
}) as unknown as Record<string, string | null>;
const apiKey = process.env.REACT_APP_STREAM_KEY as string;
const userId = params.uid || (process.env.REACT_APP_USER_ID as string);
const userToken = params.ut || (process.env.REACT_APP_USER_TOKEN as string);
const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] } };
const options: ChannelOptions = { state: true, presence: true, limit: 10 };
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
const chatClient = StreamChat.getInstance(apiKey);
if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);
}
chatClient.connectUser({ id: userId }, userToken);
const App = () => (
<Chat client={chatClient}>
<ChannelList filters={filters} sort={sort} options={options} showChannelSearch />
<Channel>
<Window>
<ChannelHeader />
<MessageList />
<MessageInput focus />
</Window>
<Thread />
</Channel>
</Chat>
);
export default App;