Skip to content

Commit d9bebe6

Browse files
Leslie NgoLeslie Ngo
authored andcommitted
topid edit modal [nfc]: Revise Flow types for relevant components.
1 parent 9c66933 commit d9bebe6

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

src/action-sheets/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type TopicArgs = {
8282
topic: string,
8383
streamsById: Map<number, Stream>,
8484
_: GetText,
85-
) => void,
85+
) => Promise<void>,
8686
...
8787
};
8888

@@ -686,7 +686,7 @@ export const showTopicActionSheet = (args: {|
686686
topic: string,
687687
streamsById: Map<number, Stream>,
688688
_: GetText,
689-
) => void,
689+
) => Promise<void>,
690690
_: GetText,
691691
|},
692692
backgroundData: $ReadOnly<{

src/boot/TopicModalProvider.js

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import React, {
2-
createContext,
3-
useState,
4-
useMemo,
5-
useCallback,
6-
useContext }
7-
from 'react';
8-
import type { Context } from 'react';
1+
/* @flow strict-local */
2+
import React, { createContext, useState, useMemo, useCallback, useContext } from 'react';
3+
import type { Context, Node } from 'react';
94
import { useSelector } from '../react-redux';
105
import TopicEditModal from '../topics/TopicEditModal';
116
import type { Stream, GetText } from '../types';
@@ -16,21 +11,21 @@ type Props = $ReadOnly<{|
1611
children: Node,
1712
|}>;
1813

19-
type TopicModalContext = $ReadOnly<{|
14+
type TopicModalContext = {|
2015
startEditTopic: (
2116
streamId: number,
2217
topic: string,
2318
streamsById: Map<number, Stream>,
2419
_: GetText,
25-
) => void,
20+
) => Promise<void>,
2621
closeEditTopicModal: () => void,
27-
|}>;
22+
|};
2823

29-
const TopicModal: Context<TopicModalContext> = createContext();
24+
const TopicModal: Context<TopicModalContext> = createContext(undefined);
3025

3126
export const useTopicModalHandler = () => useContext(TopicModal);
3227

33-
export default function TopicModalProvider(props: Props) {
28+
export default function TopicModalProvider(props: Props): Node {
3429
const { children } = props;
3530
const auth = useSelector(getAuth);
3631
const zulipFeatureLevel = useSelector(getZulipFeatureLevel);
@@ -40,16 +35,12 @@ export default function TopicModalProvider(props: Props) {
4035
fetchArgs: {
4136
auth: null,
4237
messageId: null,
43-
zulipFeatureLevel: null
44-
}
38+
zulipFeatureLevel: null,
39+
},
4540
});
4641

47-
const startEditTopic = useCallback(async (
48-
streamId,
49-
topic,
50-
streamsById,
51-
_,
52-
) => {
42+
const startEditTopic = useCallback(
43+
async (streamId, topic, streamsById, _) => {
5344
const messageId = await fetchSomeMessageIdForConversation(
5445
auth,
5546
streamId,
@@ -67,30 +58,32 @@ export default function TopicModalProvider(props: Props) {
6758
setTopicModalState({
6859
visible: true,
6960
topic,
70-
fetchArgs: { auth, messageId, zulipFeatureLevel }
61+
fetchArgs: { auth, messageId, zulipFeatureLevel },
7162
});
72-
}, [auth, zulipFeatureLevel]);
63+
},
64+
[auth, zulipFeatureLevel],
65+
);
7366

7467
const closeEditTopicModal = useCallback(() => {
7568
setTopicModalState({
7669
visible: false,
7770
topic: null,
78-
fetchArgs: { auth: null, messageId: null, zulipFeatureLevel: null }
71+
fetchArgs: { auth: null, messageId: null, zulipFeatureLevel: null },
7972
});
8073
}, []);
8174

82-
const topicModalHandler = useMemo(() => ({
83-
startEditTopic,
84-
closeEditTopicModal,
85-
}), [startEditTopic, closeEditTopicModal]);
75+
const topicModalHandler = useMemo(
76+
() => ({
77+
startEditTopic,
78+
closeEditTopicModal,
79+
}),
80+
[startEditTopic, closeEditTopicModal],
81+
);
8682

8783
return (
8884
<TopicModal.Provider value={topicModalHandler}>
8985
{topicModalState.visible && (
90-
<TopicEditModal
91-
topicModalState={topicModalState}
92-
topicModalHandler={topicModalHandler}
93-
/>
86+
<TopicEditModal topicModalState={topicModalState} topicModalHandler={topicModalHandler} />
9487
)}
9588
{children}
9689
</TopicModal.Provider>

src/topics/TopicEditModal.js

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ type TopicEditModalArgs = {
1313
fetchArgs: {
1414
auth: Auth,
1515
messageId: number,
16-
zulipFeatureLevel: number
17-
}
16+
zulipFeatureLevel: number,
17+
},
1818
},
1919
topicModalHandler: {
2020
startEditTopic: (
2121
streamId: number,
2222
topic: string,
2323
streamsById: Map<number, Stream>,
2424
_: GetText,
25-
) => void,
25+
) => Promise<void>,
2626
closeEditTopicModal: () => void,
27-
}
27+
},
2828
};
2929

30-
export default function TopicEditModal({ topicModalState, topicModalHandler }:TopicEditModalArgs): JSX$Element {
30+
export default function TopicEditModal({
31+
topicModalState,
32+
topicModalHandler,
33+
}: TopicEditModalArgs): JSX$Element {
3134
const { topic, fetchArgs } = topicModalState;
3235
const [topicState, onChangeTopic] = useState(topic);
3336
const { closeEditTopicModal } = topicModalHandler;
@@ -103,7 +106,7 @@ export default function TopicEditModal({ topicModalState, topicModalHandler }:To
103106
},
104107
cancelButtonText: {
105108
color: BRAND_COLOR,
106-
}
109+
},
107110
});
108111

109112
const handleSubmit = async () => {
@@ -128,11 +131,7 @@ export default function TopicEditModal({ topicModalState, topicModalHandler }:To
128131
>
129132
<View style={styles.wrapper}>
130133
<View style={styles.modalView}>
131-
<Text
132-
style={styles.titleText}
133-
>
134-
Edit topic
135-
</Text>
134+
<Text style={styles.titleText}>Edit topic</Text>
136135
<TextInput
137136
style={styles.input}
138137
value={topicState}
@@ -146,32 +145,24 @@ export default function TopicEditModal({ topicModalState, topicModalHandler }:To
146145
borderStyle: 'solid',
147146
borderWidth: 2,
148147
borderColor: BRAND_COLOR,
149-
...styles.button
148+
...styles.button,
150149
}}
151150
onPress={() => {
152151
closeEditTopicModal();
153152
}}
154153
>
155-
<Text
156-
style={{ ...styles.text, ...styles.cancelButtonText }}
157-
>
158-
Cancel
159-
</Text>
154+
<Text style={{ ...styles.text, ...styles.cancelButtonText }}>Cancel</Text>
160155
</Pressable>
161156
<Pressable
162157
style={{
163158
opacity: !topicState ? 0.25 : 1,
164159
backgroundColor: BRAND_COLOR,
165-
...styles.button
160+
...styles.button,
166161
}}
167162
onPress={handleSubmit}
168163
disabled={!topicState}
169164
>
170-
<Text
171-
style={{ ...styles.text, ...styles.submitButtonText }}
172-
>
173-
Submit
174-
</Text>
165+
<Text style={{ ...styles.text, ...styles.submitButtonText }}>Submit</Text>
175166
</Pressable>
176167
</View>
177168
</View>

src/webview/MessageList.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type OuterProps = $ReadOnly<{|
5151
topic: string,
5252
streamsById: Map<number, Stream>,
5353
_: GetText,
54-
) => void,
54+
) => Promise<void>,
5555
|}>;
5656

5757
type SelectorProps = {|
@@ -85,7 +85,7 @@ export type Props = $ReadOnly<{|
8585
topic: string,
8686
streamsById: Map<number, Stream>,
8787
_: GetText,
88-
) => void,
88+
) => Promise<void>,
8989
|}>;
9090

9191
/**

src/webview/handleOutboundEvents.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ 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, Stream } from '../types';
7+
import type {
8+
Dispatch,
9+
GetText,
10+
Message,
11+
Narrow,
12+
Outbox,
13+
EditMessage,
14+
UserId,
15+
Stream,
16+
} from '../types';
817
import type { BackgroundData } from './backgroundData';
918
import type { ShowActionSheetWithOptions } from '../action-sheets';
1019
import type { JSONableDict } from '../utils/jsonable';
@@ -174,7 +183,7 @@ type Props = $ReadOnly<{
174183
topic: string,
175184
streamsById: Map<number, Stream>,
176185
_: GetText,
177-
) => void,
186+
) => Promise<void>,
178187
...
179188
}>;
180189

@@ -228,7 +237,14 @@ const handleLongPress = (
228237
if (!message) {
229238
return;
230239
}
231-
const { dispatch, showActionSheetWithOptions, backgroundData, narrow, startEditMessage, startEditTopic } = props;
240+
const {
241+
dispatch,
242+
showActionSheetWithOptions,
243+
backgroundData,
244+
narrow,
245+
startEditMessage,
246+
startEditTopic,
247+
} = props;
232248
if (target === 'header') {
233249
if (message.type === 'stream') {
234250
showTopicActionSheet({

0 commit comments

Comments
 (0)