[FIX] Slash commands not cleaning is typing and not using state (#1233)

This commit is contained in:
Diego Mello 2019-09-25 18:32:13 -03:00 committed by GitHub
parent 915d19fbe8
commit 2e5c4b9b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 15 deletions

View File

@ -95,9 +95,9 @@ class MessageBox extends Component {
file: { file: {
isVisible: false isVisible: false
}, },
commandPreview: [] commandPreview: [],
showCommandPreview: false
}; };
this.showCommandPreview = false;
this.onEmojiSelected = this.onEmojiSelected.bind(this); this.onEmojiSelected = this.onEmojiSelected.bind(this);
this.text = ''; this.text = '';
this.fileOptions = [ this.fileOptions = [
@ -254,7 +254,6 @@ class MessageBox extends Component {
// matches if text either starts with '/' or have (@,#,:) then it groups whatever comes next of mention type // matches if text either starts with '/' or have (@,#,:) then it groups whatever comes next of mention type
const regexp = /(#|@|:|^\/)([a-z0-9._-]+)$/im; const regexp = /(#|@|:|^\/)([a-z0-9._-]+)$/im;
const result = lastNativeText.substr(0, cursor).match(regexp); const result = lastNativeText.substr(0, cursor).match(regexp);
this.showCommandPreview = false;
if (!result) { if (!result) {
const slash = lastNativeText.match(/^\/$/); // matches only '/' in input const slash = lastNativeText.match(/^\/$/); // matches only '/' in input
if (slash) { if (slash) {
@ -266,7 +265,6 @@ class MessageBox extends Component {
this.identifyMentionKeyword(name, lastChar); this.identifyMentionKeyword(name, lastChar);
} else { } else {
this.stopTrackingMention(); this.stopTrackingMention();
this.showCommandPreview = false;
} }
}, 100) }, 100)
@ -289,7 +287,7 @@ class MessageBox extends Component {
: (item.username || item.name || item.command); : (item.username || item.name || item.command);
const text = `${ result }${ mentionName } ${ msg.slice(cursor) }`; const text = `${ result }${ mentionName } ${ msg.slice(cursor) }`;
if ((trackingType === MENTIONS_TRACKING_TYPE_COMMANDS) && item.providesPreview) { if ((trackingType === MENTIONS_TRACKING_TYPE_COMMANDS) && item.providesPreview) {
this.showCommandPreview = true; this.setState({ showCommandPreview: true });
} }
this.setInput(text); this.setInput(text);
this.focus(); this.focus();
@ -301,10 +299,10 @@ class MessageBox extends Component {
const { text } = this; const { text } = this;
const command = text.substr(0, text.indexOf(' ')).slice(1); const command = text.substr(0, text.indexOf(' ')).slice(1);
const params = text.substr(text.indexOf(' ') + 1) || 'params'; const params = text.substr(text.indexOf(' ') + 1) || 'params';
this.showCommandPreview = false; this.setState({ commandPreview: [], showCommandPreview: false });
this.setState({ commandPreview: [] });
this.stopTrackingMention(); this.stopTrackingMention();
this.clearInput(); this.clearInput();
this.handleTyping(false);
try { try {
RocketChat.executeCommandPreview(command, params, rid, item); RocketChat.executeCommandPreview(command, params, rid, item);
} catch (e) { } catch (e) {
@ -414,10 +412,9 @@ class MessageBox extends Component {
const { rid } = this.props; const { rid } = this.props;
try { try {
const { preview } = await RocketChat.getCommandPreview(command, rid, params); const { preview } = await RocketChat.getCommandPreview(command, rid, params);
this.showCommandPreview = true; this.setState({ commandPreview: preview.items, showCommandPreview: true });
this.setState({ commandPreview: preview.items });
} catch (e) { } catch (e) {
this.showCommandPreview = false; this.setState({ commandPreview: [], showCommandPreview: true });
log(e); log(e);
} }
} }
@ -691,14 +688,15 @@ class MessageBox extends Component {
} }
stopTrackingMention = () => { stopTrackingMention = () => {
const { trackingType } = this.state; const { trackingType, showCommandPreview } = this.state;
if (!trackingType) { if (!trackingType && !showCommandPreview) {
return; return;
} }
this.setState({ this.setState({
mentions: [], mentions: [],
trackingType: '', trackingType: '',
commandPreview: [] commandPreview: [],
showCommandPreview: false
}); });
} }
@ -828,8 +826,8 @@ class MessageBox extends Component {
); );
renderCommandPreview = () => { renderCommandPreview = () => {
const { commandPreview } = this.state; const { commandPreview, showCommandPreview } = this.state;
if (!this.showCommandPreview) { if (!showCommandPreview) {
return null; return null;
} }
return ( return (