|
1 | | -/* eslint-disable */ |
2 | | -import React, { Component } from 'react'; |
| 1 | +import React from 'react'; |
3 | 2 | import { StreamChat } from 'stream-chat'; |
4 | 3 | import { |
5 | 4 | Chat, |
6 | 5 | Channel, |
7 | | - MessageList, |
8 | | - MessageInput, |
9 | | - MessageInputFlat, |
10 | | - MessageSimple, |
11 | 6 | ChannelHeader, |
| 7 | + ChannelList, |
| 8 | + ChannelListMessenger, |
12 | 9 | ChannelPreviewMessenger, |
13 | 10 | InfiniteScrollPaginator, |
14 | | - ChannelListMessenger, |
15 | | - ChannelList, |
16 | | - Window, |
| 11 | + MessageInput, |
| 12 | + MessageInputFlat, |
| 13 | + MessageList, |
17 | 14 | Thread, |
| 15 | + Window, |
18 | 16 | } from 'stream-chat-react'; |
19 | 17 | import 'stream-chat-react/dist/css/index.css'; |
| 18 | + |
20 | 19 | import './App.css'; |
21 | 20 |
|
22 | 21 | const urlParams = new URLSearchParams(window.location.search); |
23 | | -// const user = |
24 | | -// urlParams.get('user') || process.env.REACT_APP_CHAT_API_DEFAULT_USER; |
| 22 | +const apiKey = urlParams.get('apiKey') || 'qk4nn7rpcn75'; |
| 23 | +const userId = urlParams.get('user') || 'example-user'; |
25 | 24 | const theme = urlParams.get('theme') || 'light'; |
26 | | -// const channelName = urlParams.get('channel') || 'demo'; |
27 | | -// const userToken = |
28 | | -// urlParams.get('user_token') || |
29 | | -// process.env.REACT_APP_CHAT_API_DEFAULT_USER_TOKEN; |
| 25 | +const userToken = |
| 26 | + urlParams.get('user_token') || |
| 27 | + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZXhhbXBsZS11c2VyIn0.HlC0dMKL43y3K_XbfvQS_Yc3V314HU4Z7LrBLil777g'; |
| 28 | + |
30 | 29 | const filters = { type: 'messaging', example: 1 }; |
| 30 | +const options = { state: true, watch: true, presence: true }; |
31 | 31 | const sort = { |
| 32 | + cid: 1, |
32 | 33 | last_message_at: -1, |
33 | 34 | updated_at: -1, |
34 | | - cid: 1, |
35 | 35 | }; |
36 | | -const options = { state: true, watch: true, presence: true }; |
| 36 | + |
37 | 37 | const Paginator = (props) => ( |
38 | 38 | <InfiniteScrollPaginator threshold={300} {...props} /> |
39 | 39 | ); |
40 | 40 |
|
41 | | -class App extends Component { |
42 | | - constructor(props) { |
43 | | - super(props); |
44 | | - this.chatClient = new StreamChat('qk4nn7rpcn75'); |
45 | | - if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) { |
46 | | - this.chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT); |
47 | | - } |
48 | | - this.chatClient.setUser( |
49 | | - { |
50 | | - id: 'example-user', |
51 | | - }, |
52 | | - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZXhhbXBsZS11c2VyIn0.HlC0dMKL43y3K_XbfvQS_Yc3V314HU4Z7LrBLil777g', |
53 | | - ); |
54 | | - } |
| 41 | +const chatClient = new StreamChat(apiKey); |
55 | 42 |
|
56 | | - render() { |
57 | | - return ( |
58 | | - <Chat client={this.chatClient} theme={`messaging ${theme}`}> |
59 | | - <ChannelList |
60 | | - List={ChannelListMessenger} |
61 | | - Preview={ChannelPreviewMessenger} |
62 | | - filters={filters} |
63 | | - sort={sort} |
64 | | - options={options} |
65 | | - Paginator={Paginator} |
66 | | - /> |
67 | | - <Channel> |
68 | | - <Window> |
69 | | - <ChannelHeader /> |
70 | | - <MessageList /> |
71 | | - <MessageInput Input={MessageInputFlat} focus /> |
72 | | - </Window> |
73 | | - <Thread Message={MessageSimple} /> |
74 | | - </Channel> |
75 | | - </Chat> |
76 | | - ); |
77 | | - } |
| 43 | +if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) { |
| 44 | + chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT); |
78 | 45 | } |
79 | 46 |
|
| 47 | +chatClient.setUser({ id: userId }, userToken); |
| 48 | + |
| 49 | +const App = () => ( |
| 50 | + <Chat client={chatClient} theme={`messaging ${theme}`}> |
| 51 | + <ChannelList |
| 52 | + List={ChannelListMessenger} |
| 53 | + Preview={ChannelPreviewMessenger} |
| 54 | + filters={filters} |
| 55 | + sort={sort} |
| 56 | + options={options} |
| 57 | + Paginator={Paginator} |
| 58 | + /> |
| 59 | + <Channel> |
| 60 | + <Window> |
| 61 | + <ChannelHeader /> |
| 62 | + <MessageList /> |
| 63 | + <MessageInput Input={MessageInputFlat} focus /> |
| 64 | + </Window> |
| 65 | + <Thread /> |
| 66 | + </Channel> |
| 67 | + </Chat> |
| 68 | +); |
| 69 | + |
80 | 70 | export default App; |
0 commit comments