From bf75c9ef6caa92b0a200aa55e661b9502e7e6e56 Mon Sep 17 00:00:00 2001 From: talksik Date: Sun, 23 Jun 2019 15:51:30 -0700 Subject: [PATCH] ux for clearing command and other cleanup --- src/components/MainCommand.js | 83 +++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/src/components/MainCommand.js b/src/components/MainCommand.js index 4d85047..32676c3 100644 --- a/src/components/MainCommand.js +++ b/src/components/MainCommand.js @@ -72,48 +72,53 @@ class MainCommand extends Component { }); }; - handleInputChange = e => { - if (e.key === 'Enter') this.handleSubmitCommand(e); - else { - var newInput = e.target.value; - var newCommand = this.state.command; - var newCommandIcon = this.state.commandIcon; - var newCommandInputPlaceholder = this.state.commandInputPlaceholder; - var newCommandComplete = this.state.commandComplete; - var newCommandProcessedData = this.state.commandProcessedData; + handleInputKeyDown = e => { + var input = e.target.value; - // TODO: helper function to properly change properties - if ( - newInput.includes('gmail') && - newCommandIcon == envVars.DEFAULT_LOGO - ) { - newCommand = 'gmail'; - newCommandIcon = - 'https://image.flaticon.com/icons/png/512/281/281769.png'; - newInput = newInput.replace('gmail', ''); - newCommandInputPlaceholder = 'to | subject | message'; - } - - // TODO: helper function to check if input complete and show submit button - if (newCommand == 'gmail') { - const gmailSendParts = newInput.split('|'); - if (gmailSendParts.length == 3) { - newCommandComplete = true; - newCommandProcessedData = gmailSendParts; - } - } - - this.setState({ - command: newCommand, - commandInput: newInput, - commandIcon: newCommandIcon, - commandInputPlaceholder: newCommandInputPlaceholder, - commandComplete: newCommandComplete, - commandProcessedData: newCommandProcessedData - }); + if (e.key === 'Enter' && this.state.commandComplete) + this.handleSubmitCommand(e); + else if ((e.key === 'Backspace' || e.key === 'Delete') && input == '') { + console.log('Clearing out command'); + this.setState(INITIAL_COMMAND_STATE); } }; + handleInputChange = e => { + var newInput = e.target.value; + var newCommand = this.state.command; + var newCommandIcon = this.state.commandIcon; + var newCommandInputPlaceholder = this.state.commandInputPlaceholder; + var newCommandComplete = this.state.commandComplete; + var newCommandProcessedData = this.state.commandProcessedData; + + // TODO: helper function to properly change properties + if (newInput.includes('gmail') && newCommandIcon == envVars.DEFAULT_LOGO) { + newCommand = 'gmail'; + newCommandIcon = + 'https://image.flaticon.com/icons/png/512/281/281769.png'; + newInput = newInput.replace('gmail', ''); + newCommandInputPlaceholder = 'to | subject | message'; + } + + // TODO: helper function to check if input complete and show submit button + if (newCommand == 'gmail') { + const gmailSendParts = newInput.split('|'); + if (gmailSendParts.length == 3) { + newCommandComplete = true; + newCommandProcessedData = gmailSendParts; + } + } + + this.setState({ + command: newCommand, + commandInput: newInput, + commandIcon: newCommandIcon, + commandInputPlaceholder: newCommandInputPlaceholder, + commandComplete: newCommandComplete, + commandProcessedData: newCommandProcessedData + }); + }; + handleSubmitCommand = e => { // TODO: make executing api calls modular with helpers/services const processedData = this.state.commandProcessedData; @@ -175,7 +180,7 @@ class MainCommand extends Component {