Skip to content

Commit ef0d814

Browse files
Leslie NgoLeslie Ngo
authored andcommitted
topic edit modal [nfc]: Provide topic modal Context hook to children.
The useTopicModalHandler is called normally in TopicItem and TitleStream. In order to deliver the callbacks to the action sheets in MessageList, the context hook is called in ChatScreen and a bit of prop-drilling is performed.
1 parent 2bf5e83 commit ef0d814

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
lines changed

src/action-sheets/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ type TopicArgs = {
7777
zulipFeatureLevel: number,
7878
dispatch: Dispatch,
7979
_: GetText,
80+
startEditTopic: (
81+
streamId: number,
82+
topic: string,
83+
streamsById: Map<number, Stream>,
84+
_: GetText,
85+
) => void,
8086
...
8187
};
8288

@@ -251,6 +257,14 @@ const toggleResolveTopic = async ({ auth, streamId, topic, _, streams, zulipFeat
251257
});
252258
};
253259

260+
const editTopic = {
261+
title: 'Edit topic',
262+
errorMessage: 'Failed to resolve topic',
263+
action: ({ streamId, topic, streams, _, startEditTopic }) => {
264+
startEditTopic(streamId, topic, streams, _);
265+
},
266+
};
267+
254268
const resolveTopic = {
255269
title: 'Resolve topic',
256270
errorMessage: 'Failed to resolve topic',
@@ -505,6 +519,7 @@ export const constructTopicActionButtons = (args: {|
505519
if (unreadCount > 0) {
506520
buttons.push(markTopicAsRead);
507521
}
522+
buttons.push(editTopic);
508523
if (isTopicMuted(streamId, topic, mute)) {
509524
buttons.push(unmuteTopic);
510525
} else {
@@ -666,6 +681,12 @@ export const showTopicActionSheet = (args: {|
666681
showActionSheetWithOptions: ShowActionSheetWithOptions,
667682
callbacks: {|
668683
dispatch: Dispatch,
684+
startEditTopic: (
685+
streamId: number,
686+
topic: string,
687+
streamsById: Map<number, Stream>,
688+
_: GetText,
689+
) => void,
669690
_: GetText,
670691
|},
671692
backgroundData: $ReadOnly<{

src/chat/ChatScreen.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { showErrorAlert } from '../utils/info';
3030
import { TranslationContext } from '../boot/TranslationProvider';
3131
import * as api from '../api';
3232
import { useConditionalEffect } from '../reactUtils';
33+
import { useTopicModalHandler } from '../boot/TopicModalProvider';
3334

3435
type Props = $ReadOnly<{|
3536
navigation: AppNavigationProp<'chat'>,
@@ -127,6 +128,7 @@ const useMessagesWithFetch = args => {
127128
export default function ChatScreen(props: Props): Node {
128129
const { route, navigation } = props;
129130
const { backgroundColor } = React.useContext(ThemeContext);
131+
const { startEditTopic } = useTopicModalHandler();
130132

131133
const { narrow, editMessage } = route.params;
132134
const setEditMessage = useCallback(
@@ -221,6 +223,7 @@ export default function ChatScreen(props: Props): Node {
221223
}
222224
showMessagePlaceholders={showMessagePlaceholders}
223225
startEditMessage={setEditMessage}
226+
startEditTopic={startEditTopic}
224227
/>
225228
);
226229
}

src/streams/TopicItem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { getMute } from '../mute/muteModel';
2626
import { getUnread } from '../unread/unreadModel';
2727
import { getOwnUserRole } from '../permissionSelectors';
28+
import { useTopicModalHandler } from '../boot/TopicModalProvider';
2829

2930
const componentStyles = createStyleSheet({
3031
selectedRow: {
@@ -70,6 +71,7 @@ export default function TopicItem(props: Props): Node {
7071
useActionSheet().showActionSheetWithOptions;
7172
const _ = useContext(TranslationContext);
7273
const dispatch = useDispatch();
74+
const startEditTopic = useTopicModalHandler();
7375
const backgroundData = useSelector(state => ({
7476
auth: getAuth(state),
7577
mute: getMute(state),
@@ -88,7 +90,7 @@ export default function TopicItem(props: Props): Node {
8890
onLongPress={() => {
8991
showTopicActionSheet({
9092
showActionSheetWithOptions,
91-
callbacks: { dispatch, _ },
93+
callbacks: { dispatch, startEditTopic, _ },
9294
backgroundData,
9395
streamId,
9496
topic: name,

src/title/TitleStream.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { showStreamActionSheet, showTopicActionSheet } from '../action-sheets';
2727
import type { ShowActionSheetWithOptions } from '../action-sheets';
2828
import { getUnread } from '../unread/unreadModel';
2929
import { getOwnUserRole } from '../permissionSelectors';
30+
import { useTopicModalHandler } from '../boot/TopicModalProvider';
3031

3132
type Props = $ReadOnly<{|
3233
narrow: Narrow,
@@ -67,6 +68,7 @@ export default function TitleStream(props: Props): Node {
6768
const showActionSheetWithOptions: ShowActionSheetWithOptions =
6869
useActionSheet().showActionSheetWithOptions;
6970
const _ = useContext(TranslationContext);
71+
const { startEditTopic } = useTopicModalHandler();
7072

7173
return (
7274
<TouchableWithoutFeedback
@@ -75,7 +77,7 @@ export default function TitleStream(props: Props): Node {
7577
? () => {
7678
showTopicActionSheet({
7779
showActionSheetWithOptions,
78-
callbacks: { dispatch, _ },
80+
callbacks: { dispatch, startEditTopic, _ },
7981
backgroundData,
8082
streamId: stream.stream_id,
8183
topic: topicOfNarrow(narrow),

src/webview/MessageList.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
MessageListElement,
1515
UserOrBot,
1616
EditMessage,
17+
Stream,
1718
} from '../types';
1819
import { assumeSecretlyGlobalState } from '../reduxTypes';
1920
import { connect } from '../react-redux';
@@ -45,6 +46,12 @@ type OuterProps = $ReadOnly<{|
4546
initialScrollMessageId: number | null,
4647
showMessagePlaceholders: boolean,
4748
startEditMessage: (editMessage: EditMessage) => void,
49+
startEditTopic: (
50+
streamId: number,
51+
topic: string,
52+
streamsById: Map<number, Stream>,
53+
_: GetText,
54+
) => void,
4855
|}>;
4956

5057
type SelectorProps = {|
@@ -71,6 +78,14 @@ export type Props = $ReadOnly<{|
7178

7279
// From `withGetText`.
7380
_: GetText,
81+
82+
// From 'TopicModalProvider'.
83+
startEditTopic: (
84+
streamId: number,
85+
topic: string,
86+
streamsById: Map<number, Stream>,
87+
_: GetText,
88+
) => void,
7489
|}>;
7590

7691
/**
@@ -153,6 +168,7 @@ class MessageListInner extends Component<Props> {
153168
doNotMarkMessagesAsRead,
154169
_,
155170
} = this.props;
171+
156172
const contentHtml = messageListElementsForShownMessages
157173
.map(element =>
158174
messageListElementHtml({
@@ -291,7 +307,6 @@ const MessageList: ComponentType<OuterProps> = connect<SelectorProps, _, _>(
291307
// they should probably turn into a `connectGlobal` call.
292308
const globalSettings = getGlobalSettings(assumeSecretlyGlobalState(state));
293309
const debug = getDebug(assumeSecretlyGlobalState(state));
294-
295310
return {
296311
backgroundData: getBackgroundData(state, globalSettings, debug),
297312
fetching: getFetchingForNarrow(state, props.narrow),

src/webview/handleOutboundEvents.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Clipboard, Alert } from 'react-native';
44
import * as NavigationService from '../nav/NavigationService';
55
import * as api from '../api';
66
import config from '../config';
7-
import type { Dispatch, GetText, Message, Narrow, Outbox, EditMessage, UserId } from '../types';
7+
import type { Dispatch, GetText, Message, Narrow, Outbox, EditMessage, UserId, Stream } from '../types';
88
import type { BackgroundData } from './backgroundData';
99
import type { ShowActionSheetWithOptions } from '../action-sheets';
1010
import type { JSONableDict } from '../utils/jsonable';
@@ -169,6 +169,12 @@ type Props = $ReadOnly<{
169169
doNotMarkMessagesAsRead: boolean,
170170
showActionSheetWithOptions: ShowActionSheetWithOptions,
171171
startEditMessage: (editMessage: EditMessage) => void,
172+
startEditTopic: (
173+
streamId: number,
174+
topic: string,
175+
streamsById: Map<number, Stream>,
176+
_: GetText,
177+
) => void,
172178
...
173179
}>;
174180

@@ -222,12 +228,12 @@ const handleLongPress = (
222228
if (!message) {
223229
return;
224230
}
225-
const { dispatch, showActionSheetWithOptions, backgroundData, narrow, startEditMessage } = props;
231+
const { dispatch, showActionSheetWithOptions, backgroundData, narrow, startEditMessage, startEditTopic } = props;
226232
if (target === 'header') {
227233
if (message.type === 'stream') {
228234
showTopicActionSheet({
229235
showActionSheetWithOptions,
230-
callbacks: { dispatch, _ },
236+
callbacks: { dispatch, startEditTopic, _ },
231237
backgroundData,
232238
streamId: message.stream_id,
233239
topic: message.subject,

0 commit comments

Comments
 (0)