-
Notifications
You must be signed in to change notification settings - Fork 591
fix: early exit when userLocation is undefined #13859
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
Changes from all commits
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -116,10 +116,12 @@ export const GlobalMap: React.FC<Props> = (props) => { | |||||||||
| } | ||||||||||
|
|
||||||||||
| const onPressUserPositionButton = () => { | ||||||||||
| // @ts-expect-error STRICTNESS_MIGRATION --- 🚨 Unsafe legacy code 🚨 Please delete this and fix any type errors if you have time 🙏 | ||||||||||
| const { lat, lng } = userLocation | ||||||||||
| if (!isValidLatLng(userLocation)) { | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
| cameraRef.current?.setCamera({ | ||||||||||
| centerCoordinate: [lng, lat], | ||||||||||
| centerCoordinate: [userLocation.lng, userLocation.lat], | ||||||||||
| zoomLevel: DefaultZoomLevel, | ||||||||||
| animationDuration: 500, | ||||||||||
| }) | ||||||||||
|
|
@@ -146,7 +148,7 @@ export const GlobalMap: React.FC<Props> = (props) => { | |||||||||
| isLoading={!viewer.city} | ||||||||||
| onPress={onPressCitySwitcherButton} | ||||||||||
| /> | ||||||||||
| {!!userLocation && ( | ||||||||||
| {!!isValidLatLng(userLocation) && ( | ||||||||||
| <Box style={{ marginLeft: 10 }}> | ||||||||||
| <UserPositionButton | ||||||||||
| highlight={userLocation === currentLocation} | ||||||||||
|
|
@@ -337,11 +339,16 @@ export const GlobalMap: React.FC<Props> = (props) => { | |||||||||
| } | ||||||||||
|
|
||||||||||
| const onUserLocationUpdate = (location: MapboxGL.Location) => { | ||||||||||
| if (!location || !location.coords) { | ||||||||||
| const coords = location?.coords | ||||||||||
|
|
||||||||||
| // The native side sends updates with an empty `coords` object before the first location fix | ||||||||||
| // lands (and for heading-only updates), which would otherwise leave us with a location made of | ||||||||||
| // `undefined`s and crash the camera. | ||||||||||
| if (typeof coords?.latitude !== "number" || typeof coords?.longitude !== "number") { | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
| setUserLocation(longCoordsToLocation(location.coords)) | ||||||||||
| setUserLocation(longCoordsToLocation(coords)) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const onRegionIsChanging = async () => { | ||||||||||
|
|
@@ -590,6 +597,14 @@ const longCoordsToLocation = (coords: { longitude: number; latitude: number }) = | |||||||||
| return { lat: coords.latitude, lng: coords.longitude } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * `city.coordinates` is nullable in the schema and location updates can arrive without coordinates, | ||||||||||
| * so make sure we actually have numbers before handing them over to the map. | ||||||||||
| */ | ||||||||||
| const isValidLatLng = (location: any): location is { lat: number; lng: number } => { | ||||||||||
|
Contributor
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.
Suggested change
Not blocking —
Member
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. no need for this |
||||||||||
| return typeof location?.lat === "number" && typeof location?.lng === "number" | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const tracks = { | ||||||||||
| trackPinTap: (_: any, __: any, args: any) => { | ||||||||||
| const actionName = args[0] | ||||||||||
|
|
||||||||||
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.
isValidLatLngalready returns aboolean, so the!!is a no-op here (the old!!userLocationneeded it to coerce an object).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.
nope