Chats: add submit button, fixes #356
This commit is contained in:
parent
024e9209af
commit
60402a7402
2 changed files with 28 additions and 6 deletions
|
@ -65,16 +65,22 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage = () => {
|
canSubmit = () => {
|
||||||
const { dispatch, chatId } = this.props;
|
const { content, attachment } = this.state;
|
||||||
const { content, attachment, isUploading } = this.state;
|
|
||||||
|
|
||||||
const conds = [
|
const conds = [
|
||||||
content.length > 0,
|
content.length > 0,
|
||||||
attachment,
|
attachment,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!isUploading && conds.some(c => c)) {
|
return conds.some(c => c);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessage = () => {
|
||||||
|
const { dispatch, chatId } = this.props;
|
||||||
|
const { isUploading } = this.state;
|
||||||
|
|
||||||
|
if (this.canSubmit() && !isUploading) {
|
||||||
const params = this.getParams();
|
const params = this.getParams();
|
||||||
|
|
||||||
dispatch(sendChatMessage(chatId, params));
|
dispatch(sendChatMessage(chatId, params));
|
||||||
|
@ -167,9 +173,21 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderActionButton = () => {
|
||||||
|
const { resetFileKey } = this.state;
|
||||||
|
|
||||||
|
return this.canSubmit() ? (
|
||||||
|
<div className='chat-box__send'>
|
||||||
|
<IconButton icon='send' size={16} onClick={this.sendMessage} />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<UploadButton onSelectFile={this.handleFiles} resetFileKey={resetFileKey} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { chatMessageIds, chatId, intl } = this.props;
|
const { chatMessageIds, chatId, intl } = this.props;
|
||||||
const { content, isUploading, uploadProgress, resetFileKey } = this.state;
|
const { content, isUploading, uploadProgress } = this.state;
|
||||||
if (!chatMessageIds) return null;
|
if (!chatMessageIds) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -178,7 +196,7 @@ class ChatBox extends ImmutablePureComponent {
|
||||||
{this.renderAttachment()}
|
{this.renderAttachment()}
|
||||||
<UploadProgress active={isUploading} progress={uploadProgress*100} />
|
<UploadProgress active={isUploading} progress={uploadProgress*100} />
|
||||||
<div className='chat-box__actions simple_form'>
|
<div className='chat-box__actions simple_form'>
|
||||||
<UploadButton onSelectFile={this.handleFiles} resetFileKey={resetFileKey} />
|
{this.renderActionButton()}
|
||||||
<textarea
|
<textarea
|
||||||
rows={1}
|
rows={1}
|
||||||
placeholder={intl.formatMessage(messages.placeholder)}
|
placeholder={intl.formatMessage(messages.placeholder)}
|
||||||
|
|
|
@ -236,6 +236,10 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chat-box__send .icon-button {
|
||||||
|
top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
Loading…
Reference in a new issue