Skip to content

Commit cf8b507

Browse files
author
Jaap
committed
update app.js
1 parent c010559 commit cf8b507

File tree

1 file changed

+53
-22
lines changed

1 file changed

+53
-22
lines changed

examples/messaging/src/App.js

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,102 @@ import {
66
Channel,
77
MessageList,
88
MessageInput,
9-
MessageInputFlat,
109
MessageSimple,
11-
ChannelHeader,
1210
ChannelPreviewMessenger,
1311
InfiniteScrollPaginator,
14-
ChannelListMessenger,
1512
ChannelList,
1613
Window,
1714
Thread,
1815
} from 'stream-chat-react';
16+
import {
17+
MessagingInput,
18+
MessagingChannelHeader,
19+
MessagingChannelList,
20+
MessagingCreateChannel,
21+
} from './components';
1922
import 'stream-chat-react/dist/css/index.css';
2023
import './App.css';
2124

2225
const urlParams = new URLSearchParams(window.location.search);
23-
// const user =
24-
// urlParams.get('user') || process.env.REACT_APP_CHAT_API_DEFAULT_USER;
25-
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;
30-
const filters = { type: 'messaging', example: 1 };
26+
const apiKey = urlParams.get('apikey') || 'qk4nn7rpcn75';
27+
urlParams.get('user') || 'example-user';
28+
const user = urlParams.get('user') || 'example-user';
29+
const theme = urlParams.get('theme') || 'dark';
30+
const userToken =
31+
urlParams.get('user_token') ||
32+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZXhhbXBsZS11c2VyIn0.HlC0dMKL43y3K_XbfvQS_Yc3V314HU4Z7LrBLil777g';
33+
34+
const filters = { type: 'messaging', members: { $in: [user] } };
3135
const sort = {
3236
last_message_at: -1,
3337
updated_at: -1,
3438
cid: 1,
3539
};
36-
const options = { state: true, watch: true, presence: true };
40+
41+
const options = { state: true, watch: true, presence: true, limit: 10 };
3742
const Paginator = (props) => (
3843
<InfiniteScrollPaginator threshold={300} {...props} />
3944
);
4045

4146
class App extends Component {
4247
constructor(props) {
4348
super(props);
44-
this.chatClient = new StreamChat('qk4nn7rpcn75');
49+
this.chatClient = new StreamChat(apiKey);
4550
// if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
4651
// this.chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);
4752
// }
4853
this.chatClient.setUser(
4954
{
50-
id: 'example-user',
55+
id: user,
5156
},
52-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZXhhbXBsZS11c2VyIn0.HlC0dMKL43y3K_XbfvQS_Yc3V314HU4Z7LrBLil777g',
57+
userToken,
5358
);
59+
this.state = {
60+
createChannel: false,
61+
};
5462
}
5563

64+
onClose = () => {
65+
this.setState({
66+
createChannel: false,
67+
});
68+
};
69+
70+
onOpen = () => {
71+
this.setState({
72+
createChannel: true,
73+
});
74+
};
75+
5676
render() {
5777
return (
5878
<Chat client={this.chatClient} theme={`messaging ${theme}`}>
5979
<ChannelList
60-
List={ChannelListMessenger}
80+
List={(props) => (
81+
<MessagingChannelList {...props} onCreateChannel={this.onOpen} />
82+
)}
6183
Preview={ChannelPreviewMessenger}
6284
filters={filters}
6385
sort={sort}
6486
options={options}
65-
Paginator={Paginator}
87+
// Paginator={Paginator}
6688
/>
67-
<Channel>
89+
<Channel maxNumberOfFiles={10} multipleUploads={true}>
90+
<MessagingCreateChannel
91+
onClose={this.onClose}
92+
visible={this.state.createChannel}
93+
/>
6894
<Window>
69-
<ChannelHeader />
70-
<MessageList />
71-
<MessageInput Input={MessageInputFlat} focus />
95+
<MessagingChannelHeader />
96+
<MessageList TypingIndicator={() => null} />
97+
<MessageInput focus />
7298
</Window>
73-
<Thread Message={MessageSimple} />
99+
<Thread
100+
Message={MessageSimple}
101+
additionalMessageInputProps={{
102+
Input: MessagingInput,
103+
}}
104+
/>
74105
</Channel>
75106
</Chat>
76107
);

0 commit comments

Comments
 (0)