-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathChannelPreview.tsx
More file actions
145 lines (128 loc) · 4.03 KB
/
ChannelPreview.tsx
File metadata and controls
145 lines (128 loc) · 4.03 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
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { RectButton } from 'react-native-gesture-handler';
import Swipeable from 'react-native-gesture-handler/Swipeable';
import {
ChannelPreviewMessenger,
ChannelPreviewMessengerProps,
ChannelPreviewStatus,
ChannelPreviewStatusProps,
Delete,
MenuPointHorizontal,
Pin,
useChannelMembershipState,
useChatContext,
useTheme,
} from 'stream-chat-react-native';
import { useAppOverlayContext } from '../context/AppOverlayContext';
import { useBottomSheetOverlayContext } from '../context/BottomSheetOverlayContext';
import { useChannelInfoOverlayContext } from '../context/ChannelInfoOverlayContext';
import type { StackNavigationProp } from '@react-navigation/stack';
import type { StackNavigatorParamList } from '../types';
import { ChannelState } from 'stream-chat';
const styles = StyleSheet.create({
leftSwipeableButton: {
paddingLeft: 16,
paddingRight: 8,
paddingVertical: 20,
},
rightSwipeableButton: {
paddingLeft: 8,
paddingRight: 16,
paddingVertical: 20,
},
swipeableContainer: {
alignItems: 'center',
flexDirection: 'row',
},
statusContainer: {
display: 'flex',
flexDirection: 'row',
},
pinIconContainer: {
marginLeft: 8,
},
});
type ChannelListScreenNavigationProp = StackNavigationProp<
StackNavigatorParamList,
'ChannelListScreen'
>;
const CustomChannelPreviewStatus = (
props: ChannelPreviewStatusProps & { membership: ChannelState['membership'] },
) => {
const { membership } = props;
return (
<View style={styles.statusContainer}>
<ChannelPreviewStatus {...props} />
{membership.pinned_at && (
<View style={styles.pinIconContainer}>
<Pin size={24} />
</View>
)}
</View>
);
};
export const ChannelPreview: React.FC<ChannelPreviewMessengerProps> = (props) => {
const { channel } = props;
const { setOverlay } = useAppOverlayContext();
const { setData: setDataBottomSheet } = useBottomSheetOverlayContext();
const { data, setData } = useChannelInfoOverlayContext();
const { client } = useChatContext();
const navigation = useNavigation<ChannelListScreenNavigationProp>();
const membership = useChannelMembershipState(channel);
const {
theme: {
colors: { accent_red, white_smoke },
},
} = useTheme();
const otherMembers = channel
? Object.values(channel.state.members).filter((member) => member.user?.id !== data?.clientId)
: [];
return (
<Swipeable
overshootLeft={false}
overshootRight={false}
renderRightActions={() => (
<View style={[styles.swipeableContainer, { backgroundColor: white_smoke }]}>
<RectButton
onPress={() => {
setData({ channel, clientId: client.userID, membership, navigation });
setOverlay('channelInfo');
}}
style={[styles.leftSwipeableButton]}
>
<MenuPointHorizontal />
</RectButton>
<RectButton
onPress={() => {
setDataBottomSheet({
confirmText: 'DELETE',
onConfirm: () => {
channel.delete();
setOverlay('none');
},
subtext: `Are you sure you want to delete this ${
otherMembers.length === 1 ? 'conversation' : 'group'
}?`,
title: `Delete ${otherMembers.length === 1 ? 'Conversation' : 'Group'}`,
});
setOverlay('confirmation');
}}
style={[styles.rightSwipeableButton]}
>
<Delete size={32} fill={accent_red} />
</RectButton>
</View>
)}
>
<ChannelPreviewMessenger
{...props}
// eslint-disable-next-line react/no-unstable-nested-components
PreviewStatus={(statusProps) => (
<CustomChannelPreviewStatus {...statusProps} membership={membership} />
)}
/>
</Swipeable>
);
};