From bb44f39491424819715bfc6e9a30d4b98fa35559 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Tue, 8 Sep 2020 21:57:47 -0400 Subject: [PATCH] leap: safety check state.selected --- pkg/interface/src/views/components/leap/Omnibox.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/interface/src/views/components/leap/Omnibox.js b/pkg/interface/src/views/components/leap/Omnibox.js index adceb3aea..21e6af395 100644 --- a/pkg/interface/src/views/components/leap/Omnibox.js +++ b/pkg/interface/src/views/components/leap/Omnibox.js @@ -78,7 +78,7 @@ export class Omnibox extends Component { if (evt.key === 'Enter') { evt.preventDefault(); - if (this.state.selected !== '') { + if (this.state.selected !== []) { this.navigate(this.state.selected[0], this.state.selected[1]); } else { this.navigate( @@ -133,7 +133,7 @@ export class Omnibox extends Component { // wipe results if backspacing if (query.length === 0) { - this.setState({ results: results, selected: '' }); + this.setState({ results: results, selected: [] }); return; } @@ -170,7 +170,7 @@ export class Omnibox extends Component { const current = this.state.selected; const flattenedResults = Array.from(this.state.results.values()).flat(); const totalLength = flattenedResults.length; - if (current !== '') { + if (current !== []) { const currentIndex = flattenedResults.indexOf( ...flattenedResults.filter((e) => { return e.link === current[1]; @@ -195,7 +195,7 @@ export class Omnibox extends Component { setNextSelected() { const current = this.state.selected; const flattenedResults = Array.from(this.state.results.values()).flat(); - if (current !== '') { + if (current !== []) { const currentIndex = flattenedResults.indexOf( ...flattenedResults.filter((e) => { return e.link === current[1]; @@ -232,6 +232,7 @@ export class Omnibox extends Component { .map(({ category, categoryResults }, i) => { const categoryTitle = (category === 'other') ? null : {category.charAt(0).toUpperCase() + category.slice(1)}; + const selected = this.state.selected?.length ? this.state.selected[1] : ''; return ( {categoryTitle} @@ -243,7 +244,7 @@ export class Omnibox extends Component { subtext={result.host} link={result.link} navigate={() => this.navigate(result.app, result.link)} - selected={this.state.selected[1]} + selected={selected} dark={props.dark} /> ))} @@ -255,7 +256,7 @@ export class Omnibox extends Component { render() { const { props, state } = this; - if (state?.selected.length === 0 && Array.from(this.state.results.values()).flat().length) { + if (state?.selected?.length === 0 && Array.from(this.state.results.values()).flat().length) { this.setNextSelected(); } return (