ux for clearing command and other cleanup
This commit is contained in:
@@ -72,9 +72,18 @@ class MainCommand extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleInputKeyDown = e => {
|
||||||
|
var input = e.target.value;
|
||||||
|
|
||||||
|
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 => {
|
handleInputChange = e => {
|
||||||
if (e.key === 'Enter') this.handleSubmitCommand(e);
|
|
||||||
else {
|
|
||||||
var newInput = e.target.value;
|
var newInput = e.target.value;
|
||||||
var newCommand = this.state.command;
|
var newCommand = this.state.command;
|
||||||
var newCommandIcon = this.state.commandIcon;
|
var newCommandIcon = this.state.commandIcon;
|
||||||
@@ -83,10 +92,7 @@ class MainCommand extends Component {
|
|||||||
var newCommandProcessedData = this.state.commandProcessedData;
|
var newCommandProcessedData = this.state.commandProcessedData;
|
||||||
|
|
||||||
// TODO: helper function to properly change properties
|
// TODO: helper function to properly change properties
|
||||||
if (
|
if (newInput.includes('gmail') && newCommandIcon == envVars.DEFAULT_LOGO) {
|
||||||
newInput.includes('gmail') &&
|
|
||||||
newCommandIcon == envVars.DEFAULT_LOGO
|
|
||||||
) {
|
|
||||||
newCommand = 'gmail';
|
newCommand = 'gmail';
|
||||||
newCommandIcon =
|
newCommandIcon =
|
||||||
'https://image.flaticon.com/icons/png/512/281/281769.png';
|
'https://image.flaticon.com/icons/png/512/281/281769.png';
|
||||||
@@ -111,7 +117,6 @@ class MainCommand extends Component {
|
|||||||
commandComplete: newCommandComplete,
|
commandComplete: newCommandComplete,
|
||||||
commandProcessedData: newCommandProcessedData
|
commandProcessedData: newCommandProcessedData
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleSubmitCommand = e => {
|
handleSubmitCommand = e => {
|
||||||
@@ -175,7 +180,7 @@ class MainCommand extends Component {
|
|||||||
<input
|
<input
|
||||||
value={commandInput}
|
value={commandInput}
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
onKeyPress={this.handleInputChange}
|
onKeyDown={this.handleInputKeyDown}
|
||||||
className={styles.searchBar}
|
className={styles.searchBar}
|
||||||
placeholder={commandInputPlaceholder}
|
placeholder={commandInputPlaceholder}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user