Skip to content

Commit 1a39712

Browse files
AkashDhimangnprice
authored andcommitted
actionsheet: Enable stream action sheet
This commit enables stream action sheet at all places.
1 parent 67eeb50 commit 1a39712

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/streams/StreamItem.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22
import React, { useContext } from 'react';
33
import type { Node } from 'react';
44
import { View } from 'react-native';
5+
// $FlowFixMe[untyped-import]
6+
import { useActionSheet } from '@expo/react-native-action-sheet';
7+
import invariant from 'invariant';
58

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';
622
import styles, { createStyleSheet, ThemeContext } from '../styles';
723
import { RawLabel, Touchable, UnreadCount, ZulipSwitch } from '../common';
824
import { foregroundColorFromBackground } from '../utils/color';
@@ -75,6 +91,21 @@ export default function StreamItem(props: Props): Node {
7591
onSwitch,
7692
} = props;
7793

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+
78109
const { backgroundColor: themeBackgroundColor, color: themeColor } = useContext(ThemeContext);
79110

80111
const wrapperStyle = [styles.listItem, { backgroundColor }, isMuted && componentStyles.muted];
@@ -90,7 +121,17 @@ export default function StreamItem(props: Props): Node {
90121
: themeColor;
91122

92123
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+
>
94135
<View style={wrapperStyle}>
95136
<StreamIcon size={iconSize} color={iconColor} isMuted={isMuted} isPrivate={isPrivate} />
96137
<View style={componentStyles.text}>

src/title/TitleStream.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import {
2020
getStreamsById,
2121
getOwnUser,
2222
getStreamInNarrow,
23+
getSettings,
2324
} from '../selectors';
24-
import { showTopicActionSheet } from '../action-sheets';
25+
import { showStreamActionSheet, showTopicActionSheet } from '../action-sheets';
2526
import type { ShowActionSheetWithOptions } from '../action-sheets';
2627
import { getUnread } from '../unread/unreadModel';
2728

@@ -56,6 +57,7 @@ export default function TitleStream(props: Props): Node {
5657
unread: getUnread(state),
5758
ownUser: getOwnUser(state),
5859
flags: getFlags(state),
60+
userSettingStreamNotification: getSettings(state).streamNotification,
5961
}));
6062

6163
const showActionSheetWithOptions: ShowActionSheetWithOptions = useActionSheet()
@@ -75,7 +77,14 @@ export default function TitleStream(props: Props): Node {
7577
topic: topicOfNarrow(narrow),
7678
});
7779
}
78-
: undefined
80+
: () => {
81+
showStreamActionSheet({
82+
showActionSheetWithOptions,
83+
callbacks: { dispatch, _ },
84+
backgroundData,
85+
streamId: stream.stream_id,
86+
});
87+
}
7988
}
8089
>
8190
<View style={componentStyles.outer}>

0 commit comments

Comments
 (0)