Prevent double tap of send button (#5154) (#5155)

(cherry picked from commit a17aff9c95)

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
This commit is contained in:
Mattermost Build 2021-02-04 19:59:27 +01:00 committed by GitHub
parent 43f6c0869a
commit 32e1ce0573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ import EventEmitter from '@mm-redux/utils/event_emitter';
import EphemeralStore from '@store/ephemeral_store';
import * as DraftUtils from '@utils/draft';
import {confirmOutOfOfficeDisabled} from '@utils/status';
import {preventDoubleTap} from '@utils/tap';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
const AUTOCOMPLETE_MARGIN = 20;
@ -228,7 +229,7 @@ export default class DraftInput extends PureComponent {
});
};
handleSendMessage = () => {
handleSendMessage = preventDoubleTap(() => {
if (!this.input.current) {
return;
}
@ -236,42 +237,44 @@ export default class DraftInput extends PureComponent {
const value = this.input.current.getValue();
this.input.current.resetTextInput();
requestAnimationFrame(() => {
if (!this.isSendButtonEnabled()) {
this.input.current.setValue(value);
return;
}
this.doHandleSendMessage(value);
});
this.setState({sendingMessage: true});
doHandleSendMessage = (value) => requestAnimationFrame(() => {
if (!this.isSendButtonEnabled()) {
this.input.current.setValue(value);
return;
}
const {channelId, files, handleClearFailedFiles, rootId} = this.props;
this.setState({sendingMessage: true});
const isReactionMatch = value.match(IS_REACTION_REGEX);
if (isReactionMatch) {
const emoji = isReactionMatch[2];
this.sendReaction(emoji);
return;
}
const {channelId, files, handleClearFailedFiles, rootId} = this.props;
const hasFailedAttachments = files.some((f) => f.failed);
if (hasFailedAttachments) {
const {formatMessage} = this.context.intl;
const cancel = () => {
this.setInputValue(value);
this.setState({sendingMessage: false});
};
const accept = () => {
// Remove only failed files
handleClearFailedFiles(channelId, rootId);
this.sendMessage(value);
};
const isReactionMatch = value.match(IS_REACTION_REGEX);
if (isReactionMatch) {
const emoji = isReactionMatch[2];
this.sendReaction(emoji);
return;
}
DraftUtils.alertAttachmentFail(formatMessage, accept, cancel);
} else {
const hasFailedAttachments = files.some((f) => f.failed);
if (hasFailedAttachments) {
const {formatMessage} = this.context.intl;
const cancel = () => {
this.setInputValue(value);
this.setState({sendingMessage: false});
};
const accept = () => {
// Remove only failed files
handleClearFailedFiles(channelId, rootId);
this.sendMessage(value);
}
});
}
};
DraftUtils.alertAttachmentFail(formatMessage, accept, cancel);
} else {
this.sendMessage(value);
}
});
isFileLoading = () => {
const {files} = this.props;