Skip to content

Commit 30ab947

Browse files
committed
ComposeBox [nfc]: Make topic type optional.
Previously, the state.topic variable was an empty string in narrows with no topic, which made it annoying to distinguish that state from being in a stream or topic narrow with the topic box empty.
1 parent f59b4c4 commit 30ab947

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/compose/ComposeBox.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type State = {|
9595
isFocused: boolean,
9696

9797
isMenuExpanded: boolean,
98-
topic: string,
98+
topic: ?string,
9999
message: string,
100100
height: number,
101101
selection: InputSelection,
@@ -144,13 +144,21 @@ class ComposeBox extends PureComponent<Props, State> {
144144

145145
inputBlurTimeoutId: ?TimeoutID = null;
146146

147+
getCanSelectTopic = () => {
148+
const { editMessage, narrow } = this.props;
149+
if (editMessage) {
150+
return isStreamOrTopicNarrow(narrow);
151+
}
152+
return isStreamNarrow(narrow);
153+
};
154+
147155
state = {
148156
isMessageFocused: false,
149157
isTopicFocused: false,
150158
isFocused: false,
151159
isMenuExpanded: false,
152160
height: 20,
153-
topic: '',
161+
topic: this.getCanSelectTopic() ? '' : null,
154162
message: this.props.draft,
155163
selection: { start: 0, end: 0 },
156164
};
@@ -167,14 +175,6 @@ class ComposeBox extends PureComponent<Props, State> {
167175
}));
168176
};
169177

170-
getCanSelectTopic = () => {
171-
const { editMessage, narrow } = this.props;
172-
if (editMessage) {
173-
return isStreamOrTopicNarrow(narrow);
174-
}
175-
return isStreamNarrow(narrow);
176-
};
177-
178178
setMessageInputValue = (message: string) => {
179179
updateTextInput(this.messageInputRef.current, message);
180180
this.handleMessageChange(message);
@@ -304,10 +304,10 @@ class ComposeBox extends PureComponent<Props, State> {
304304

305305
getDestinationNarrow = (): Narrow => {
306306
const { narrow } = this.props;
307-
if (isStreamNarrow(narrow)) {
307+
const topic = this.state.topic;
308+
if (isStreamNarrow(narrow) && topic != null) {
308309
const streamName = streamNameOfNarrow(narrow);
309-
const topic = this.state.topic.trim();
310-
return topicNarrow(streamName, topic || '(no topic)');
310+
return topicNarrow(streamName, topic.trim() || '(no topic)');
311311
}
312312
return narrow;
313313
};
@@ -339,7 +339,7 @@ class ComposeBox extends PureComponent<Props, State> {
339339
}
340340
const { message, topic } = this.state;
341341
const content = editMessage.content !== message ? message : undefined;
342-
const subject = topic !== editMessage.topic ? topic : undefined;
342+
const subject = topic !== editMessage.topic && topic != null ? topic : undefined;
343343
if ((content !== undefined && content !== '') || (subject !== undefined && subject !== '')) {
344344
api.updateMessage(auth, { content, subject }, editMessage.id).catch(error => {
345345
showErrorAlert(_('Failed to edit message'), error.message);
@@ -448,12 +448,14 @@ class ComposeBox extends PureComponent<Props, State> {
448448
*/}
449449
<MentionWarnings narrow={narrow} stream={stream} ref={this.mentionWarnings} />
450450
<View style={[this.styles.autocompleteWrapper, { marginBottom: height }]}>
451-
<TopicAutocomplete
452-
isFocused={isTopicFocused}
453-
narrow={narrow}
454-
text={topic}
455-
onAutocomplete={this.handleTopicAutocomplete}
456-
/>
451+
{topic != null && (
452+
<TopicAutocomplete
453+
isFocused={isTopicFocused}
454+
narrow={narrow}
455+
text={topic}
456+
onAutocomplete={this.handleTopicAutocomplete}
457+
/>
458+
)}
457459
<AutocompleteView
458460
isFocused={this.state.isMessageFocused}
459461
selection={selection}

0 commit comments

Comments
 (0)