-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathAddMemberBottomSheet.tsx
More file actions
194 lines (180 loc) · 4.61 KB
/
AddMemberBottomSheet.tsx
File metadata and controls
194 lines (180 loc) · 4.61 KB
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
import React, { useState } from 'react';
import {
ActivityIndicator,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { Search, useTheme } from 'stream-chat-react-native';
import { UserSearchResultsGrid } from './UserSearch/UserSearchResultsGrid';
import { useAppOverlayContext } from '../context/AppOverlayContext';
import {
isAddMemberBottomSheetData,
useBottomSheetOverlayContext,
} from '../context/BottomSheetOverlayContext';
import { usePaginatedUsers } from '../hooks/usePaginatedUsers';
import type { UserResponse } from 'stream-chat';
import { CircleClose } from '../icons/CircleClose';
const styles = StyleSheet.create({
container: {
height: 300,
},
flex: {
flex: 1,
},
inputBox: {
flex: 1,
fontSize: 14,
includeFontPadding: false, // for android vertical text centering
marginLeft: 10,
padding: 0, // removal of default text input padding on android
paddingTop: 0, // removal of iOS top padding for weird centering
textAlignVertical: 'center', // for android vertical text centering
},
inputBoxContainer: {
alignItems: 'center',
borderRadius: 18,
borderWidth: 1,
flexDirection: 'row',
paddingHorizontal: 10,
paddingVertical: 8,
},
inputRow: {
alignItems: 'center',
flexDirection: 'row',
padding: 16,
justifyContent: 'center',
},
text: {
marginLeft: 10,
},
textContainer: {
alignItems: 'center',
flexDirection: 'row',
padding: 5,
width: '100%',
},
});
export const AddMemberBottomSheet: React.FC = () => {
const { setOverlay } = useAppOverlayContext();
const { data, reset } = useBottomSheetOverlayContext();
const channel = data && isAddMemberBottomSheetData(data) ? data.channel : undefined;
const insets = useSafeAreaInsets();
const {
theme: {
colors: { accent_red, black, grey, grey_whisper, white, white_smoke },
},
} = useTheme();
const {
clearText,
loading: loadingResults,
loadMore,
onChangeSearchText,
onFocusInput,
results,
searchText,
} = usePaginatedUsers();
const [addMemberQueryInProgress, setAddMemberQueryInProgress] = useState(false);
const [error, setError] = useState(false);
if (!channel) {
return null;
}
const addMember = async (user: UserResponse) => {
setAddMemberQueryInProgress(true);
try {
await channel.addMembers([user.id]);
reset();
setOverlay('none');
} catch (err) {
console.warn('An error has occurred while adding members: ', err);
setError(true);
}
setAddMemberQueryInProgress(false);
};
return (
<View
style={[
styles.container,
{
marginBottom: insets.bottom,
},
]}
>
<View style={styles.inputRow}>
<View
style={[
styles.inputBoxContainer,
{
backgroundColor: white,
borderColor: grey_whisper,
},
]}
>
<Search pathFill={black} />
<TextInput
onChangeText={onChangeSearchText}
onFocus={onFocusInput}
placeholder='Search'
placeholderTextColor={grey}
style={[
styles.inputBox,
{
color: black,
},
]}
value={searchText}
/>
<TouchableOpacity onPress={clearText}>
<CircleClose pathFill={grey} />
</TouchableOpacity>
</View>
</View>
<View style={styles.flex}>
{addMemberQueryInProgress && (
<View
style={[
styles.textContainer,
{
backgroundColor: white_smoke,
},
]}
>
<ActivityIndicator size='small' />
<Text style={styles.text}>Adding user to channel</Text>
</View>
)}
{error && (
<View
style={[
styles.textContainer,
{
backgroundColor: accent_red,
},
]}
>
<Text
style={[
styles.text,
{
color: white,
},
]}
>
Error adding user to channel
</Text>
</View>
)}
<UserSearchResultsGrid
loading={loadingResults}
loadMore={loadMore}
onPress={addMember}
results={results}
searchText={searchText}
/>
</View>
</View>
);
};