/
index.stories.js
206 lines (185 loc) · 4.61 KB
/
index.stories.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import React, { useState, useCallback } from 'react';
import Sendbird from '../../../lib/Sendbird';
const appId = process.env.STORYBOOK_APP_ID;;
const userId = 'sendbird';
import ChannelList from '../../ChannelList';
import { getSdk } from '../../../lib/selectors';
import withSendBird from '../../../lib/SendbirdSdkContext';
export default { title: 'ChannelList' };
export const IndependantChannelList = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '100vh' }}>
<ChannelList />
</div>
</Sendbird>
);
const MyCustomPreview = ({ channel, onLeaveChannel }) => (
<div style={{ border: '1px solid gray' }}>
<img height="20px" width="20px" src={channel.coverUrl} />
<button
onClick={() => {
const leaveChannelCb = () => { console.warn('Leave channel success') }
onLeaveChannel(channel, leaveChannelCb);
}}
>Leave</button>
</div>
);
export const CustomChannelPreview = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
renderChannelPreview={MyCustomPreview}
onChannelSelect={(c) => { console.warn(c); }}
/>
</div>
</Sendbird>
);
export const DisableUserProfile = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
disableUserProfile
/>
</div>
</Sendbird>
);
export const RenderUserProfile = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
renderUserProfile={({ user }) => (
<div>{user.userId}</div>
)}
/>
</div>
</Sendbird>
);
const MyCustomHeader = () => (
<div>Hello my friends</div>
);
export const CustomChannelListHeader = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
renderHeader={MyCustomHeader}
onChannelSelect={(c) => { console.warn(c); }}
/>
</div>
</Sendbird>
);
export const CustomSort = () => {
const channelSort = useCallback((channels) => {
if (channels.length === 0 ) {
return channels;
}
const channel = channels.find(c => c.name === 'hidden 3');
if (!channel) {
return channels;
}
const otherChannels = channels.filter(c => c.url !== channel.url);
otherChannels.sort(function(a, b){
if(a.name < b.name) { return -1; }
if(a.name > b.name) { return 1; }
return 0;
});
return [channel, ...otherChannels];
}, []);
return (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
sortChannelList={channelSort}
/>
</div>
</Sendbird>
)};
export const EditProfile = () => (
<Sendbird
appId={appId}
userId={userId}
>
<div style={{ height: '520px' }}>
<ChannelList
allowProfileEdit
onThemeChange={(theme) => {
alert(`New theme is: ${theme}`);
}}
onProfileEditSuccess={(user) => {
alert(`New nickname is: ${user.nickname}`);
}}
onChannelSelect={(c) => { console.warn(c); }}
/>
</div>
</Sendbird>
);
const ChannelWithOnBeforeCreateChannel = ({ sdk }) => (
<div style={{ height: '520px' }}>
<ChannelList
onBeforeCreateChannel={(selectedUsers) => {
if (!sdk || !sdk.GroupChannelParams) { return }
const params = new sdk.GroupChannelParams();
params.addUserIds(selectedUsers);
// params.isBroadcast = true;
params.operatorUserIds = [...selectedUsers, userId];
params.name = "custom name";
return params;
}}
/>
</div>
)
const ConnectedChannelList = withSendBird(ChannelWithOnBeforeCreateChannel, (store) => ({
sdk: getSdk(store),
}))
export const OnBeforeCreateChannel = () => (
<Sendbird
appId={appId}
userId={userId}
>
<ConnectedChannelList />
</Sendbird>
);
export const QueryParamsForChannelList = () => {
const [query, setquery] = useState(false);
return (
<Sendbird
appId={appId}
userId={userId}
>
<button onClick={() => { setquery(true); }}>
Click to change query
</button>
<div style={{ height: '520px' }}>
<ChannelList
queries={{
channelListQuery: query ? {
includeEmpty: true,
}: null,
applicationUserListQuery: {
limit: 30,
// userIdsFilter: ['hoon500'],
metaDataKeyFilter: 'areaGuid',
},
}}
/>
</div>
</Sendbird>
);
};