Skip to content

Commit

Permalink
fix(Geosuggest): GeoCode fixtures if no location is provided (Re-Impl…
Browse files Browse the repository at this point in the history
…ementation of #145)

As opposed to #145 this leaves the current API unchanged, except for adding an `isFixture` field to suggests returned in `onSuggestSelect`.
  • Loading branch information
Caerostris committed Jun 2, 2016
1 parent 0b8317e commit 8df8d31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Geosuggest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class Geosuggest extends React.Component {
if (!skipSuggest(suggest) && suggest.label.match(regex)) {
fixturesSearched++;

suggest.placeId = suggest.label;
suggest.isFixture = true;
suggests.push(suggest);
}
});
Expand All @@ -188,7 +190,8 @@ class Geosuggest extends React.Component {
if (!skipSuggest(suggest)) {
suggests.push({
label: this.props.getSuggestLabel(suggest),
placeId: suggest.place_id
placeId: suggest.place_id,
isFixture: false
});
}
});
Expand Down Expand Up @@ -269,7 +272,6 @@ class Geosuggest extends React.Component {

if (suggest.location) {
this.setState({ignoreBlur: false});
suggest.placeId = suggest.placeId || suggest.label;
this.props.onSuggestSelect(suggest);
return;
}
Expand All @@ -283,7 +285,8 @@ class Geosuggest extends React.Component {
*/
geocodeSuggest(suggest) {
this.geocoder.geocode(
suggest.placeId ? {placeId: suggest.placeId} : {address: suggest.label},
suggest.placeId && !suggest.isFixture ?
{placeId: suggest.placeId} : {address: suggest.label},
(results, status) => {
if (status !== this.googleMaps.GeocoderStatus.OK) {
return;
Expand All @@ -292,7 +295,6 @@ class Geosuggest extends React.Component {
var gmaps = results[0],
location = gmaps.geometry.location;

suggest.placeId = suggest.placeId || gmaps.place_id;
suggest.gmaps = gmaps;
suggest.location = {
lat: location.lat(),
Expand Down
4 changes: 2 additions & 2 deletions src/suggest-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default ({
);

return <ul className={classes}>
{suggests.map((suggest, index) => {
{suggests.map(suggest => {
const isActive = activeSuggest &&
suggest.placeId === activeSuggest.placeId;

return <SuggestItem key={index}
return <SuggestItem key={suggest.placeId}
className={suggest.className}
suggest={suggest}
isActive={isActive}
Expand Down

0 comments on commit 8df8d31

Please sign in to comment.