-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New places api support #47085
base: main
Are you sure you want to change the base?
New places api support #47085
Changes from 3 commits
04ea3a8
6425853
4836de6
4692371
43d5dba
67cc635
9a75de7
0e52dc9
ae0ef58
b396dd8
0c07e99
4379632
18d79b0
8f05d04
0ad4459
2a070f6
5b133e8
805eb47
f9e2ddc
4b60132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,6 @@ | |
lat: 'addressLat', | ||
lng: 'addressLng', | ||
}, | ||
resultTypes = 'address', | ||
shouldSaveDraft = false, | ||
value, | ||
locationBias, | ||
|
@@ -97,26 +96,25 @@ | |
const containerRef = useRef<View>(null); | ||
const query = useMemo( | ||
() => ({ | ||
language: preferredLocale, | ||
types: resultTypes, | ||
components: isLimitedToUSA ? 'country:us' : undefined, | ||
...(locationBias && {locationbias: locationBias}), | ||
languageCode: preferredLocale, | ||
includedRegionCodes: isLimitedToUSA ? ['us'] : undefined, | ||
...(locationBias && {locationBias}), | ||
}), | ||
[preferredLocale, resultTypes, isLimitedToUSA, locationBias], | ||
[preferredLocale, isLimitedToUSA, locationBias], | ||
); | ||
const shouldShowCurrentLocationButton = canUseCurrentLocation && searchValue.trim().length === 0 && isFocused; | ||
const saveLocationDetails = (autocompleteData: GooglePlaceData, details: GooglePlaceDetail | null) => { | ||
const addressComponents = details?.address_components; | ||
const addressComponents = details?.addressComponents; | ||
Check failure on line 107 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
|
||
if (!addressComponents) { | ||
// When there are details, but no address_components, this indicates that some predefined options have been passed | ||
// to this component which don't match the usual properties coming from auto-complete. In that case, only a limited | ||
// amount of data massaging needs to happen for what the parent expects to get from this function. | ||
if (details) { | ||
onPress?.({ | ||
address: autocompleteData.description ?? '', | ||
lat: details.geometry.location.lat ?? 0, | ||
lng: details.geometry.location.lng ?? 0, | ||
name: details.name, | ||
lat: details.location?.latitude ?? details.geometry.location?.lat ?? 0, | ||
Check failure on line 115 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
Check failure on line 115 in src/components/AddressSearch/index.tsx GitHub Actions / Run ESLint
|
||
lng: details.location?.longitude ?? details.geometry.location?.lng ?? 0, | ||
Check failure on line 116 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
Check failure on line 116 in src/components/AddressSearch/index.tsx GitHub Actions / Run ESLint
|
||
name: autocompleteData?.structured_formatting?.main_text ?? details?.name ?? '', | ||
}); | ||
} | ||
return; | ||
|
@@ -134,7 +132,7 @@ | |
administrative_area_level_1: state, | ||
administrative_area_level_2: stateFallback, | ||
country: countryPrimary, | ||
} = GooglePlacesUtils.getAddressComponents(addressComponents, { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
street_number: 'long_name', | ||
route: 'long_name', | ||
|
@@ -154,7 +152,7 @@ | |
|
||
// The state's iso code (short_name) is needed for the StatePicker component but we also | ||
// need the state's full name (long_name) when we render the state in a TextInput. | ||
const {administrative_area_level_1: longStateName} = GooglePlacesUtils.getAddressComponents(addressComponents, { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
administrative_area_level_1: 'long_name', | ||
}); | ||
|
@@ -174,7 +172,7 @@ | |
|
||
const values = { | ||
street: `${streetNumber} ${streetName}`.trim(), | ||
name: details.name ?? '', | ||
name: autocompleteData?.structured_formatting?.main_text ?? details?.name ?? '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
// Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise. | ||
street2: subpremise, | ||
// Make sure country is updated first, since city and state will be reset if the country changes | ||
|
@@ -187,9 +185,9 @@ | |
city: locality || postalTown || sublocality || cityAutocompleteFallback, | ||
zipCode, | ||
|
||
lat: details.geometry.location.lat ?? 0, | ||
lng: details.geometry.location.lng ?? 0, | ||
address: autocompleteData.description || details.formatted_address || '', | ||
lat: details.location?.latitude ?? details.geometry.location?.lat ?? 0, | ||
Check failure on line 188 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
Check failure on line 188 in src/components/AddressSearch/index.tsx GitHub Actions / Run ESLint
|
||
lng: details.location?.longitude ?? details.geometry.location?.lng ?? 0, | ||
Check failure on line 189 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
|
||
address: autocompleteData.description || details.formattedAddress || '', | ||
}; | ||
|
||
// If the address is not in the US, use the full length state name since we're displaying the address's | ||
|
@@ -211,9 +209,9 @@ | |
|
||
// Some edge-case addresses may lack both street_number and route in the API response, resulting in an empty "values.street" | ||
// We are setting up a fallback to ensure "values.street" is populated with a relevant value | ||
if (!values.street && details.adr_address) { | ||
if (!values.street && details.adrFormatAddress) { | ||
const streetAddressRegex = /<span class="street-address">([^<]*)<\/span>/; | ||
const adrAddress = details.adr_address.match(streetAddressRegex); | ||
const adrAddress = details.adrFormatAddress.match(streetAddressRegex); | ||
const streetAddressFallback = adrAddress ? adrAddress?.[1] : null; | ||
if (streetAddressFallback) { | ||
values.street = streetAddressFallback; | ||
|
@@ -474,6 +472,8 @@ | |
} | ||
placeholder="" | ||
listViewDisplayed | ||
fields={CONST.GOOGLE_PLACES_API.FIELDS_MASK} | ||
Check failure on line 475 in src/components/AddressSearch/index.tsx GitHub Actions / typecheck
|
||
isNewPlacesAPI | ||
> | ||
<LocationErrorMessage | ||
onClose={() => setLocationErrorCode(null)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
details.name
isn't the same as it was in the old API, the format here isplaces/<id>
so not really good to use here. The next closest thing isdetails?. shortFormattedAddress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this context, the
details.name
is not used from old API. Instead, it indicates a predefined option i.e. saved places in our app. So, I think we need to keepdetails.name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you mean, can you show me? The way I understand this code, the value in
autocompleteData.structured_formatting.main_text
in the new API is most similar todetails.name
from the old api. However,details.name
is no longer a good fallback, as in the new API, it does not contain a short version of the address, but something else entirelyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find the test video that demonstrates the use of
predefined
places. This is the reason why I think we need to keepdetails.name
.47085-predefined-places.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm ok. Can you take a look at how this is utilized when changing your address on the profile settings page as well? I wonder if we need different values in the two places.