Skip to content

Commit 800ad79

Browse files
authored
Merge pull request #661 from GetStream/update-example-apps
update messaging app
2 parents 7f366ad + 714276c commit 800ad79

File tree

2 files changed

+1674
-1477
lines changed

2 files changed

+1674
-1477
lines changed

examples/messaging/src/App.js

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,70 @@
1-
/* eslint-disable */
2-
import React, { Component } from 'react';
1+
import React from 'react';
32
import { StreamChat } from 'stream-chat';
43
import {
54
Chat,
65
Channel,
7-
MessageList,
8-
MessageInput,
9-
MessageInputFlat,
10-
MessageSimple,
116
ChannelHeader,
7+
ChannelList,
8+
ChannelListMessenger,
129
ChannelPreviewMessenger,
1310
InfiniteScrollPaginator,
14-
ChannelListMessenger,
15-
ChannelList,
16-
Window,
11+
MessageInput,
12+
MessageInputFlat,
13+
MessageList,
1714
Thread,
15+
Window,
1816
} from 'stream-chat-react';
1917
import 'stream-chat-react/dist/css/index.css';
18+
2019
import './App.css';
2120

2221
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';
2524
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+
3029
const filters = { type: 'messaging', example: 1 };
30+
const options = { state: true, watch: true, presence: true };
3131
const sort = {
32+
cid: 1,
3233
last_message_at: -1,
3334
updated_at: -1,
34-
cid: 1,
3535
};
36-
const options = { state: true, watch: true, presence: true };
36+
3737
const Paginator = (props) => (
3838
<InfiniteScrollPaginator threshold={300} {...props} />
3939
);
4040

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);
5542

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);
7845
}
7946

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+
8070
export default App;

0 commit comments

Comments
 (0)