mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Merge pull request #923 from sharetribe/fix-enter-while-fetching-predictions
Fix enter while fetching predictions
This commit is contained in:
commit
3a7c790fe7
2 changed files with 14 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue