-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy pathChannelAddMembersScreen.tsx
More file actions
76 lines (66 loc) · 2.34 KB
/
Copy pathChannelAddMembersScreen.tsx
File metadata and controls
76 lines (66 loc) · 2.34 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
import React, { useCallback, useMemo, useState } from 'react';
import type { RouteProp } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { StackNavigatorParamList } from '../types';
import {
ChannelAddMembers,
ChannelDetailsContext,
NotificationList,
NotificationTargetProvider,
useChannelActions,
} from 'stream-chat-react-native-core';
import type { UserResponse } from 'stream-chat';
import { KeyboardAvoidingView, Platform, Pressable, Text } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
type ChannelAddMembersScreenRouteProp = RouteProp<
StackNavigatorParamList,
'ChannelAddMembersScreen'
>;
type ChannelAddMembersScreenNavigationProp = NativeStackNavigationProp<
StackNavigatorParamList,
'ChannelAddMembersScreen'
>;
type Props = {
navigation: ChannelAddMembersScreenNavigationProp;
route: ChannelAddMembersScreenRouteProp;
};
export const ChannelAddMembersScreen: React.FC<Props> = ({
navigation,
route: {
params: { channel },
},
}) => {
const { addMembers } = useChannelActions(channel);
const [selectedUsers, setSelectedUsers] = useState<UserResponse[]>([]);
const channelDetailsContextValue = useMemo(() => ({ channel }), [channel]);
const goBack = useCallback(() => navigation.goBack(), [navigation]);
const onSavePress = useCallback(async () => {
await addMembers(
selectedUsers.map((user) => user.id),
{
onSuccess: () => {
setSelectedUsers([]);
goBack();
},
},
);
}, [addMembers, selectedUsers, goBack]);
return (
<ChannelDetailsContext.Provider value={channelDetailsContextValue}>
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : undefined}
style={{ flex: 1 }}
>
<SafeAreaView edges={['bottom']} style={{ flex: 1 }}>
<NotificationTargetProvider hostId={channel.cid} panel='channel-details'>
<ChannelAddMembers onSelectionChange={setSelectedUsers} />
<Pressable onPress={onSavePress} style={{ alignItems: 'center', padding: 16 }}>
<Text>Save</Text>
</Pressable>
<NotificationList />
</NotificationTargetProvider>
</SafeAreaView>
</KeyboardAvoidingView>
</ChannelDetailsContext.Provider>
);
};