-
-
Notifications
You must be signed in to change notification settings - Fork 662
/
Copy pathTopicItem.js
136 lines (129 loc) · 3.8 KB
/
TopicItem.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
/* @flow strict-local */
import React, { useContext } from 'react';
import type { Node } from 'react';
import { View } from 'react-native';
// $FlowFixMe[untyped-import]
import { useActionSheet } from '@expo/react-native-action-sheet';
import styles, { BRAND_COLOR, createStyleSheet } from '../styles';
import { IconMention, IconFollow } from '../common/Icons';
import ZulipText from '../common/ZulipText';
import Touchable from '../common/Touchable';
import UnreadCount from '../common/UnreadCount';
import { showTopicActionSheet } from '../action-sheets';
import type { ShowActionSheetWithOptions } from '../action-sheets';
import { TranslationContext } from '../boot/TranslationProvider';
import { useDispatch, useSelector } from '../react-redux';
import {
getAuth,
getFlags,
getSubscriptionsById,
getStreamsById,
getOwnUser,
getZulipFeatureLevel,
} from '../selectors';
import { getMute, isTopicFollowed } from '../mute/muteModel';
import { getUnread } from '../unread/unreadModel';
import { useNavigation } from '../react-navigation';
import { ThemeContext } from '../styles/theme';
const componentStyles = createStyleSheet({
selectedRow: {
backgroundColor: BRAND_COLOR,
},
mentionedLabel: {
paddingRight: 4,
color: 'gray',
},
label: {
flex: 1,
},
selectedText: {
color: 'white',
},
muted: {
opacity: 0.5,
},
followedIcon: {
paddingLeft: 4,
width: 20,
opacity: 0.2,
},
});
type Props = $ReadOnly<{|
streamId: number,
name: string,
isMuted?: boolean,
isSelected?: boolean,
isMentioned?: boolean,
unreadCount?: number,
onPress: (streamId: number, topic: string) => void,
|}>;
export default function TopicItem(props: Props): Node {
const {
streamId,
name,
isMuted = false,
isSelected = false,
isMentioned = false,
unreadCount = 0,
onPress,
} = props;
const showActionSheetWithOptions: ShowActionSheetWithOptions =
useActionSheet().showActionSheetWithOptions;
const _ = useContext(TranslationContext);
const navigation = useNavigation();
const dispatch = useDispatch();
const backgroundData = useSelector(state => {
const ownUser = getOwnUser(state);
return {
auth: getAuth(state),
mute: getMute(state),
streams: getStreamsById(state),
subscriptions: getSubscriptionsById(state),
unread: getUnread(state),
ownUser,
ownUserRole: ownUser.role,
flags: getFlags(state),
zulipFeatureLevel: getZulipFeatureLevel(state),
};
});
const theme = useContext(ThemeContext);
const iconColor = theme.themeName === 'dark' ? 'white' : 'black';
const isFollowed = useSelector(state => isTopicFollowed(streamId, name, getMute(state)));
return (
<Touchable
onPress={() => onPress(streamId, name)}
onLongPress={() => {
showTopicActionSheet({
showActionSheetWithOptions,
callbacks: { dispatch, navigation, _ },
backgroundData,
streamId,
topic: name,
});
}}
>
<View
style={[
styles.listItem,
isSelected && componentStyles.selectedRow,
isMuted && componentStyles.muted,
]}
>
<ZulipText
style={[componentStyles.label, isSelected && componentStyles.selectedText]}
text={name}
numberOfLines={1}
ellipsizeMode="tail"
/>
{isMentioned && <IconMention size={14} style={componentStyles.mentionedLabel} />}
<UnreadCount count={unreadCount} inverse={isSelected} />
{isFollowed ? (
<IconFollow style={componentStyles.followedIcon} size={14} color={iconColor} />
) : (
// $FlowFixMe[incompatible-type]: complains about `color` but that's not present
<View style={componentStyles.followedIcon} />
)}
</View>
</Touchable>
);
}