Fix bug where UI breaks trying to send a DM (#2452)

This commit is contained in:
SleeplessOne1917 2024-05-10 11:01:34 -04:00 committed by GitHub
parent ef72c75000
commit b0a711a4ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -47,6 +47,8 @@ export class PrivateMessageForm extends Component<
super(props, context); super(props, context);
this.handleContentChange = this.handleContentChange.bind(this); this.handleContentChange = this.handleContentChange.bind(this);
this.handlePrivateMessageSubmit =
this.handlePrivateMessageSubmit.bind(this);
} }
componentWillReceiveProps( componentWillReceiveProps(
@ -118,9 +120,7 @@ export class PrivateMessageForm extends Component<
</label> </label>
<div className="col-sm-10"> <div className="col-sm-10">
<MarkdownTextArea <MarkdownTextArea
onSubmit={event => { onSubmit={this.handlePrivateMessageSubmit}
this.handlePrivateMessageSubmit(this, event);
}}
initialContent={this.state.content} initialContent={this.state.content}
onContentChange={this.handleContentChange} onContentChange={this.handleContentChange}
allLanguages={[]} allLanguages={[]}
@ -140,20 +140,19 @@ export class PrivateMessageForm extends Component<
); );
} }
handlePrivateMessageSubmit(i: PrivateMessageForm, event: any) { handlePrivateMessageSubmit() {
event.preventDefault(); this.setState({ loading: true, submitted: true });
i.setState({ loading: true, submitted: true }); const pm = this.props.privateMessageView;
const pm = i.props.privateMessageView; const content = this.state.content ?? "";
const content = i.state.content ?? "";
if (pm) { if (pm) {
i.props.onEdit?.({ this.props.onEdit?.({
private_message_id: pm.private_message.id, private_message_id: pm.private_message.id,
content, content,
}); });
} else { } else {
i.props.onCreate?.({ this.props.onCreate?.({
content, content,
recipient_id: i.props.recipient.id, recipient_id: this.props.recipient.id,
}); });
} }
} }