From 31543335583166354a0507305b8bf4c311e6efc7 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 12 Sep 2018 11:24:58 +0300 Subject: [PATCH 1/2] Fix: selecting with enter key prevented while fetching predictions --- .../LocationAutocompleteInputImpl.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js b/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js index 148ddfe5..225cd0e2 100644 --- a/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js +++ b/src/components/LocationAutocompleteInput/LocationAutocompleteInputImpl.js @@ -163,6 +163,7 @@ class LocationAutocompleteInputImpl extends Component { touchStartedFrom: null, highlightedIndex: -1, // -1 means no highlight fetchingPlaceDetails: false, + fetchingPredictions: false, }; // Ref to the input element. @@ -335,6 +336,11 @@ class LocationAutocompleteInputImpl extends Component { }); } selectItemIfNoneSelected() { + if (this.state.fetchingPredictions) { + // No need to select anything since prediction fetch is still going on + return; + } + const { search, selectedPlace } = currentValue(this.props); const predictions = this.currentPredictions(); if (!selectedPlace) { @@ -342,19 +348,19 @@ class LocationAutocompleteInputImpl extends Component { const index = this.state.highlightedIndex !== -1 ? this.state.highlightedIndex : 0; this.selectPrediction(predictions[index]); } else { - this.predict(search).then(() => { - this.selectPrediction(predictions[0]); - }); + this.predict(search); } } } predict(search) { const onChange = this.props.input.onChange; + this.setState({ fetchingPredictions: true }); return this.getGeocoder() .getPlacePredictions(search) .then(results => { const { search: currentSearch } = currentValue(this.props); + this.setState({ fetchingPredictions: false }); // If the earlier predictions arrive when the user has already // changed the search term, ignore and wait until the latest @@ -373,6 +379,7 @@ class LocationAutocompleteInputImpl extends Component { } }) .catch(e => { + this.setState({ fetchingPredictions: false }); // eslint-disable-next-line no-console console.error(e); const value = currentValue(this.props); From 9db3ea6db946e3936b1ec8dcc5f799a2a91a2483 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 12 Sep 2018 11:27:31 +0300 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6bc38d4..9ce90261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ way to update this template, but currently, we follow a pattern: * Patch (v0.0.**X**): Bug fixes and small changes to components. --- +## Upcoming version 2018-09-XX +* [fix] Selecting with enter key prevented while fetching predictions. + [#923](https://github.com/sharetribe/flex-template-web/pull/923) + ## v1.4.2 2018-09-06 * [add] Reduce character queries on LocationAutocompleteInput to reduce geocoding costs. [#883](https://github.com/sharetribe/flex-template-web/pull/883)