2
2
import React , { useContext } from 'react' ;
3
3
import type { Node } from 'react' ;
4
4
import { View } from 'react-native' ;
5
+ // $FlowFixMe[untyped-import]
6
+ import { useActionSheet } from '@expo/react-native-action-sheet' ;
7
+ import invariant from 'invariant' ;
5
8
9
+ import { showStreamActionSheet } from '../action-sheets' ;
10
+ import type { ShowActionSheetWithOptions } from '../action-sheets' ;
11
+ import { TranslationContext } from '../boot/TranslationProvider' ;
12
+ import { useDispatch , useSelector } from '../react-redux' ;
13
+ import {
14
+ getAuth ,
15
+ getFlags ,
16
+ getSubscriptionsById ,
17
+ getStreamsById ,
18
+ getStreamsByName ,
19
+ getOwnUser ,
20
+ getSettings ,
21
+ } from '../selectors' ;
6
22
import styles , { createStyleSheet , ThemeContext } from '../styles' ;
7
23
import { RawLabel , Touchable , UnreadCount , ZulipSwitch } from '../common' ;
8
24
import { foregroundColorFromBackground } from '../utils/color' ;
@@ -75,6 +91,21 @@ export default function StreamItem(props: Props): Node {
75
91
onSwitch,
76
92
} = props ;
77
93
94
+ const showActionSheetWithOptions : ShowActionSheetWithOptions = useActionSheet ( )
95
+ . showActionSheetWithOptions ;
96
+ const _ = useContext ( TranslationContext ) ;
97
+ const dispatch = useDispatch ( ) ;
98
+ const backgroundData = useSelector ( state => ( {
99
+ auth : getAuth ( state ) ,
100
+ ownUser : getOwnUser ( state ) ,
101
+ streams : getStreamsById ( state ) ,
102
+ subscriptions : getSubscriptionsById ( state ) ,
103
+ flags : getFlags ( state ) ,
104
+ userSettingStreamNotification : getSettings ( state ) . streamNotification ,
105
+ } ) ) ;
106
+ const stream = useSelector ( state => getStreamsByName ( state ) . get ( name ) ) ;
107
+ invariant ( stream !== undefined , 'No stream with provided stream name was found.' ) ;
108
+
78
109
const { backgroundColor : themeBackgroundColor , color : themeColor } = useContext ( ThemeContext ) ;
79
110
80
111
const wrapperStyle = [ styles . listItem , { backgroundColor } , isMuted && componentStyles . muted ] ;
@@ -90,7 +121,17 @@ export default function StreamItem(props: Props): Node {
90
121
: themeColor ;
91
122
92
123
return (
93
- < Touchable onPress = { ( ) => onPress ( name ) } >
124
+ < Touchable
125
+ onPress = { ( ) => onPress ( name ) }
126
+ onLongPress = { ( ) => {
127
+ showStreamActionSheet ( {
128
+ showActionSheetWithOptions,
129
+ callbacks : { dispatch, _ } ,
130
+ backgroundData,
131
+ streamId : stream . stream_id ,
132
+ } ) ;
133
+ } }
134
+ >
94
135
< View style = { wrapperStyle } >
95
136
< StreamIcon size = { iconSize } color = { iconColor } isMuted = { isMuted } isPrivate = { isPrivate } />
96
137
< View style = { componentStyles . text } >
0 commit comments