From bc9c2a876d71ae4a9f96baeb080c8f586c41aca1 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:17:14 -0400 Subject: [PATCH 01/14] fix(PlaceEditor): Support using the current location as a favorite. --- lib/components/user/places/place-editor.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index c49b9c408..1bc8d4310 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -68,11 +68,17 @@ class PlaceEditor extends Component { static contextType = ComponentContext _handleLocationChange = (e: LocationSelectedEvent) => { - const { setTouched, setValues, values } = this.props - const { lat, lon, name } = e.location + const { intl, setTouched, setValues, values } = this.props + const { category, lat, lon, name } = e.location setValues({ ...values, - address: name, + address: + // If the current location is picked, set the "address" + // so that we can later determine what the current location was at that time. + // TODO: ideally, geocode that location. + category === 'CURRENT_LOCATION' + ? intl.formatMessage({ id: 'common.coordinates' }, { lat, lon }) + : name, lat, lon }) From 78f9705c8996c9308499e1e5fd26c3d616dff6e1 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:21:24 -0400 Subject: [PATCH 02/14] refactor(PlaceEditor): Remove unneeded fields for setValues. --- lib/components/user/places/place-editor.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 1bc8d4310..f18d9cd92 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -68,10 +68,9 @@ class PlaceEditor extends Component { static contextType = ComponentContext _handleLocationChange = (e: LocationSelectedEvent) => { - const { intl, setTouched, setValues, values } = this.props + const { intl, setTouched, setValues } = this.props const { category, lat, lon, name } = e.location setValues({ - ...values, address: // If the current location is picked, set the "address" // so that we can later determine what the current location was at that time. From b61e3c410d09d69c61f98ce37147fa2f115c5ab2 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 09:47:43 -0400 Subject: [PATCH 03/14] fix(PlaceEditor): Populate coords when current location is picked fron dropdown. --- lib/actions/location.js | 20 ++++++++--------- lib/components/user/places/place-editor.tsx | 22 ++++++++++++++++++- .../user/places/place-location-field.ts | 5 +++++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/actions/location.js b/lib/actions/location.js index 5b26ba3f1..b25942929 100644 --- a/lib/actions/location.js +++ b/lib/actions/location.js @@ -7,35 +7,35 @@ export const receivedPositionError = createAction('POSITION_ERROR') export const fetchingPosition = createAction('POSITION_FETCHING') export const receivedPositionResponse = createAction('POSITION_RESPONSE') -export function getCurrentPosition (intl, setAsType = null, onSuccess) { +export function getCurrentPosition(intl, setAsType = null, onSuccess) { return async function (dispatch, getState) { if (navigator.geolocation) { dispatch(fetchingPosition({ type: setAsType })) navigator.geolocation.getCurrentPosition( // On success - position => { + (position) => { if (position) { console.log('current loc', position, setAsType) dispatch(receivedPositionResponse({ position })) if (setAsType) { console.log('setting location to current position') dispatch(setLocationToCurrent({ locationType: setAsType }, intl)) - onSuccess && onSuccess() } + onSuccess && onSuccess(position) } else { dispatch( receivedPositionError({ error: { - message: intl.formatMessage( - { id: 'actions.location.unknownPositionError' } - ) + message: intl.formatMessage({ + id: 'actions.location.unknownPositionError' + }) } }) ) } }, // On error - error => { + (error) => { console.log('error getting current position', error) // FIXME, analyze error code to produce better error message. // See https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError @@ -49,9 +49,9 @@ export function getCurrentPosition (intl, setAsType = null, onSuccess) { dispatch( receivedPositionError({ error: { - message: intl.formatMessage( - { id: 'actions.location.geolocationNotSupportedError' } - ) + message: intl.formatMessage({ + id: 'actions.location.geolocationNotSupportedError' + }) } }) ) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index f18d9cd92..3d2ffc73c 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -1,3 +1,4 @@ +import { connect } from 'react-redux' import { ControlLabel, FormControl, @@ -11,6 +12,7 @@ import coreUtils from '@opentripplanner/core-utils' import React, { Component, Fragment } from 'react' import styled from 'styled-components' +import * as locationActions from '../../../actions/location' import { capitalizeFirst, getErrorStates } from '../../../util/ui' import { ComponentContext } from '../../../util/contexts' import { CUSTOM_PLACE_TYPES, isHomeOrWork } from '../../../util/user' @@ -84,6 +86,19 @@ class PlaceEditor extends Component { setTouched({ address: true }) } + _handleGetCurrentPosition = () => { + const { getCurrentPosition, intl, setTouched, setValues } = this.props + getCurrentPosition(intl, null, (position) => { + const { latitude: lat, longitude: lon } = position.coords + setValues({ + address: intl.formatMessage({ id: 'common.coordinates' }, { lat, lon }), + lat, + lon + }) + setTouched({ address: true }) + }) + } + render() { const { errors, intl, values: place } = this.props const { SvgIcon } = this.context @@ -173,6 +188,7 @@ class PlaceEditor extends Component { { } } -export default injectIntl(PlaceEditor) +const mapDispatchToProps = { + getCurrentPosition: locationActions.getCurrentPosition +} + +export default connect(null, mapDispatchToProps)(injectIntl(PlaceEditor)) diff --git a/lib/components/user/places/place-location-field.ts b/lib/components/user/places/place-location-field.ts index ab606f647..711be8ae5 100644 --- a/lib/components/user/places/place-location-field.ts +++ b/lib/components/user/places/place-location-field.ts @@ -55,9 +55,14 @@ const StyledLocationField = styled(LocationField)` props.static ? 'padding-left: 10px; padding-right: 5px; width: 100%' : ''} } ` + /** * Styled LocationField for setting a favorite place locations using the geocoder. */ export const PlaceLocationField = connectLocationField(StyledLocationField, { + actions: { + // Set to null so that PlaceEditor can set its own handler. + getCurrentPosition: null + }, excludeSavedLocations: true }) From 176836fa23bd792173cb78831664c04d17d1b393 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 10:33:35 -0400 Subject: [PATCH 04/14] improvement(PlaceEditor): Display fetching message when picking current location. --- lib/actions/location.js | 4 ++- lib/components/user/places/place-editor.tsx | 27 ++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/actions/location.js b/lib/actions/location.js index b25942929..3c074920c 100644 --- a/lib/actions/location.js +++ b/lib/actions/location.js @@ -7,6 +7,8 @@ export const receivedPositionError = createAction('POSITION_ERROR') export const fetchingPosition = createAction('POSITION_FETCHING') export const receivedPositionResponse = createAction('POSITION_RESPONSE') +export const PLACE_EDITOR_LOCATION = 'placeeditor' + export function getCurrentPosition(intl, setAsType = null, onSuccess) { return async function (dispatch, getState) { if (navigator.geolocation) { @@ -17,7 +19,7 @@ export function getCurrentPosition(intl, setAsType = null, onSuccess) { if (position) { console.log('current loc', position, setAsType) dispatch(receivedPositionResponse({ position })) - if (setAsType) { + if (setAsType && setAsType !== PLACE_EDITOR_LOCATION) { console.log('setting location to current position') dispatch(setLocationToCurrent({ locationType: setAsType }, intl)) } diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 3d2ffc73c..5402055c7 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -69,6 +69,8 @@ function makeLocationFieldLocation(favoriteLocation: UserSavedLocation) { class PlaceEditor extends Component { static contextType = ComponentContext + _ + _handleLocationChange = (e: LocationSelectedEvent) => { const { intl, setTouched, setValues } = this.props const { category, lat, lon, name } = e.location @@ -88,15 +90,22 @@ class PlaceEditor extends Component { _handleGetCurrentPosition = () => { const { getCurrentPosition, intl, setTouched, setValues } = this.props - getCurrentPosition(intl, null, (position) => { - const { latitude: lat, longitude: lon } = position.coords - setValues({ - address: intl.formatMessage({ id: 'common.coordinates' }, { lat, lon }), - lat, - lon - }) - setTouched({ address: true }) - }) + getCurrentPosition( + intl, + locationActions.PLACE_EDITOR_LOCATION, + (position) => { + const { latitude: lat, longitude: lon } = position.coords + setValues({ + address: intl.formatMessage( + { id: 'common.coordinates' }, + { lat, lon } + ), + lat, + lon + }) + setTouched({ address: true }) + } + ) } render() { From c17c006a4be14b8cb53a23faef1cea4fb48dc401 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 10:40:58 -0400 Subject: [PATCH 05/14] refactor(PlaceEditor): Combine common code. --- lib/components/user/places/place-editor.tsx | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 5402055c7..14033ebe5 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -69,11 +69,9 @@ function makeLocationFieldLocation(favoriteLocation: UserSavedLocation) { class PlaceEditor extends Component { static contextType = ComponentContext - _ - - _handleLocationChange = (e: LocationSelectedEvent) => { + _setLocation = (location) => { const { intl, setTouched, setValues } = this.props - const { category, lat, lon, name } = e.location + const { category, lat, lon, name } = location setValues({ address: // If the current location is picked, set the "address" @@ -88,23 +86,21 @@ class PlaceEditor extends Component { setTouched({ address: true }) } + _handleLocationChange = (e: LocationSelectedEvent) => { + this._setLocation(e.location) + } + _handleGetCurrentPosition = () => { - const { getCurrentPosition, intl, setTouched, setValues } = this.props + const { getCurrentPosition, intl } = this.props getCurrentPosition( intl, locationActions.PLACE_EDITOR_LOCATION, - (position) => { - const { latitude: lat, longitude: lon } = position.coords - setValues({ - address: intl.formatMessage( - { id: 'common.coordinates' }, - { lat, lon } - ), - lat, - lon + ({ coords }) => + this._setLocation({ + category: 'CURRENT_LOCATION', + lat: coords.latitude, + lon: coords.longitude }) - setTouched({ address: true }) - } ) } From e3d17a58dcfdbc8e50ce38468646a30efffc0c2f Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 12:16:30 -0400 Subject: [PATCH 06/14] improvement(PlaceEditor): Reverse geocode the current location. --- lib/components/user/places/place-editor.tsx | 34 ++++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 14033ebe5..06514a12d 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -9,6 +9,7 @@ import { Field, FormikProps } from 'formik' import { FormattedMessage, injectIntl, WrappedComponentProps } from 'react-intl' import { LocationSelectedEvent } from '@opentripplanner/location-field/lib/types' import coreUtils from '@opentripplanner/core-utils' +import getGeocoder from '@opentripplanner/geocoder' import React, { Component, Fragment } from 'react' import styled from 'styled-components' @@ -91,16 +92,24 @@ class PlaceEditor extends Component { } _handleGetCurrentPosition = () => { - const { getCurrentPosition, intl } = this.props + const { geocoderConfig, getCurrentPosition, intl } = this.props getCurrentPosition( intl, locationActions.PLACE_EDITOR_LOCATION, - ({ coords }) => - this._setLocation({ - category: 'CURRENT_LOCATION', - lat: coords.latitude, - lon: coords.longitude - }) + ({ coords }) => { + getGeocoder(geocoderConfig) + .reverse({ point: coords }) + .then(this._setLocation) + .catch((err) => { + console.warn(err) + const { latitude: lat, longitude: lon } = coords + this._setLocation({ + category: 'CURRENT_LOCATION', + lat, + lon + }) + }) + } ) } @@ -225,8 +234,17 @@ class PlaceEditor extends Component { } } +const mapStateToProps = (state) => { + return { + geocoderConfig: state.otp.config.geocoder + } +} + const mapDispatchToProps = { getCurrentPosition: locationActions.getCurrentPosition } -export default connect(null, mapDispatchToProps)(injectIntl(PlaceEditor)) +export default connect( + mapStateToProps, + mapDispatchToProps +)(injectIntl(PlaceEditor)) From db052d0762a8eb07dca72cd2465ce28fdaedf64c Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 12:44:03 -0400 Subject: [PATCH 07/14] refactor(PlaceEditor): Re-include existing form values when submitting changes. --- lib/components/user/places/place-editor.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 06514a12d..6ad277560 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -71,9 +71,10 @@ class PlaceEditor extends Component { static contextType = ComponentContext _setLocation = (location) => { - const { intl, setTouched, setValues } = this.props + const { intl, setTouched, setValues, values } = this.props const { category, lat, lon, name } = location setValues({ + ...values, address: // If the current location is picked, set the "address" // so that we can later determine what the current location was at that time. From 27b3f6b975578235834b0c49ade34ce0e9557aa1 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 13:53:59 -0400 Subject: [PATCH 08/14] refactor(PlaceEditor): Adjust types. --- lib/actions/location.js | 4 ++-- lib/components/user/places/place-editor.tsx | 26 +++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/actions/location.js b/lib/actions/location.js index 3c074920c..f346e6936 100644 --- a/lib/actions/location.js +++ b/lib/actions/location.js @@ -9,10 +9,10 @@ export const receivedPositionResponse = createAction('POSITION_RESPONSE') export const PLACE_EDITOR_LOCATION = 'placeeditor' -export function getCurrentPosition(intl, setAsType = null, onSuccess) { +export function getCurrentPosition(intl, setAsType, onSuccess) { return async function (dispatch, getState) { if (navigator.geolocation) { - dispatch(fetchingPosition({ type: setAsType })) + dispatch(fetchingPosition({ type: setAsType || null })) navigator.geolocation.getCurrentPosition( // On success (position) => { diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 6ad277560..598fdaa00 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -6,7 +6,14 @@ import { HelpBlock } from 'react-bootstrap' import { Field, FormikProps } from 'formik' -import { FormattedMessage, injectIntl, WrappedComponentProps } from 'react-intl' +import { + FormattedMessage, + injectIntl, + IntlShape, + WrappedComponentProps +} from 'react-intl' +import { GeocoderConfig } from '@opentripplanner/geocoder/lib/geocoders/types' +import { Location } from '@opentripplanner/types' import { LocationSelectedEvent } from '@opentripplanner/location-field/lib/types' import coreUtils from '@opentripplanner/core-utils' import getGeocoder from '@opentripplanner/geocoder' @@ -26,7 +33,16 @@ import InvisibleA11yLabel from '../../util/invisible-a11y-label' import { PlaceLocationField } from './place-location-field' -type Props = WrappedComponentProps & FormikProps +type Props = WrappedComponentProps & + FormikProps & { + geocoderConfig: GeocoderConfig + getCurrentPosition: ( + intl: IntlShape, + setAsType?: string | null, + onSuccess?: (position: GeolocationPosition) => void + ) => Promise + intl: IntlShape + } const { isMobile } = coreUtils.ui @@ -70,7 +86,7 @@ function makeLocationFieldLocation(favoriteLocation: UserSavedLocation) { class PlaceEditor extends Component { static contextType = ComponentContext - _setLocation = (location) => { + _setLocation = (location: Location) => { const { intl, setTouched, setValues, values } = this.props const { category, lat, lon, name } = location setValues({ @@ -101,7 +117,7 @@ class PlaceEditor extends Component { getGeocoder(geocoderConfig) .reverse({ point: coords }) .then(this._setLocation) - .catch((err) => { + .catch((err: Error) => { console.warn(err) const { latitude: lat, longitude: lon } = coords this._setLocation({ @@ -235,7 +251,7 @@ class PlaceEditor extends Component { } } -const mapStateToProps = (state) => { +const mapStateToProps = (state: any) => { return { geocoderConfig: state.otp.config.geocoder } From cd1eb0465a1d2cfe2443b2c817e101aa01c3e818 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 14:55:11 -0400 Subject: [PATCH 09/14] refactor(actions/location): Convert to TypeScript. --- lib/actions/{location.js => location.tsx} | 14 +++++++++++--- lib/components/user/places/place-editor.tsx | 6 ++---- 2 files changed, 13 insertions(+), 7 deletions(-) rename lib/actions/{location.js => location.tsx} (81%) diff --git a/lib/actions/location.js b/lib/actions/location.tsx similarity index 81% rename from lib/actions/location.js rename to lib/actions/location.tsx index f346e6936..a336efb18 100644 --- a/lib/actions/location.js +++ b/lib/actions/location.tsx @@ -1,4 +1,7 @@ +// @ts-expect-error TODO: add @types/redux-actions (will break other other stuff). import { createAction } from 'redux-actions' +import { Dispatch } from 'redux' +import { IntlShape } from 'react-intl' import { setLocationToCurrent } from './map' @@ -9,10 +12,14 @@ export const receivedPositionResponse = createAction('POSITION_RESPONSE') export const PLACE_EDITOR_LOCATION = 'placeeditor' -export function getCurrentPosition(intl, setAsType, onSuccess) { - return async function (dispatch, getState) { +export function getCurrentPosition( + intl: IntlShape, + setAsType?: string | null, + onSuccess?: (position: GeolocationPosition) => void +) { + return function (dispatch: Dispatch): void { if (navigator.geolocation) { - dispatch(fetchingPosition({ type: setAsType || null })) + dispatch(fetchingPosition({ type: setAsType })) navigator.geolocation.getCurrentPosition( // On success (position) => { @@ -21,6 +28,7 @@ export function getCurrentPosition(intl, setAsType, onSuccess) { dispatch(receivedPositionResponse({ position })) if (setAsType && setAsType !== PLACE_EDITOR_LOCATION) { console.log('setting location to current position') + // @ts-expect-error Action below is not typed yet. dispatch(setLocationToCurrent({ locationType: setAsType }, intl)) } onSuccess && onSuccess(position) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 598fdaa00..52649af20 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -37,10 +37,8 @@ type Props = WrappedComponentProps & FormikProps & { geocoderConfig: GeocoderConfig getCurrentPosition: ( - intl: IntlShape, - setAsType?: string | null, - onSuccess?: (position: GeolocationPosition) => void - ) => Promise + ...args: Parameters + ) => void intl: IntlShape } From 15f292dca3eac9313dc611d31ef9bb7ade9f79f7 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 18 Jul 2023 15:02:09 -0400 Subject: [PATCH 10/14] refactor(PlaceEditor): Tweak comments --- lib/components/user/places/place-editor.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 52649af20..e1868944d 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -90,9 +90,8 @@ class PlaceEditor extends Component { setValues({ ...values, address: - // If the current location is picked, set the "address" - // so that we can later determine what the current location was at that time. - // TODO: ideally, geocode that location. + // If the raw current location is passed without a name attribute (i.e. the address), + // set the "address" as the formatted coordinates of the current location at that time. category === 'CURRENT_LOCATION' ? intl.formatMessage({ id: 'common.coordinates' }, { lat, lon }) : name, From dae3d040bf0bf48d4d90d723eb2a0edcddeff293 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:42:32 -0400 Subject: [PATCH 11/14] chore(deps): Update @opentripplanner/geocoder to 1.4.2, update import syntax. --- lib/components/user/places/place-editor.tsx | 3 +-- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index e1868944d..18d8dfb09 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -12,11 +12,10 @@ import { IntlShape, WrappedComponentProps } from 'react-intl' -import { GeocoderConfig } from '@opentripplanner/geocoder/lib/geocoders/types' import { Location } from '@opentripplanner/types' import { LocationSelectedEvent } from '@opentripplanner/location-field/lib/types' import coreUtils from '@opentripplanner/core-utils' -import getGeocoder from '@opentripplanner/geocoder' +import getGeocoder, { GeocoderConfig } from '@opentripplanner/geocoder' import React, { Component, Fragment } from 'react' import styled from 'styled-components' diff --git a/package.json b/package.json index c6e17a6f9..ec63d3e08 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@opentripplanner/core-utils": "^9.0.0-alpha.34", "@opentripplanner/endpoints-overlay": "^2.0.7", "@opentripplanner/from-to-location-picker": "^2.1.7", - "@opentripplanner/geocoder": "^1.4.1", + "@opentripplanner/geocoder": "^1.4.2", "@opentripplanner/humanize-distance": "^1.2.0", "@opentripplanner/icons": "^2.0.3", "@opentripplanner/itinerary-body": "^4.2.0-alpha.3", diff --git a/yarn.lock b/yarn.lock index 9378bba5f..c97f73ff7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2469,10 +2469,10 @@ isomorphic-mapzen-search "^1.6.1" lodash.memoize "^4.1.2" -"@opentripplanner/geocoder@^1.4.0", "@opentripplanner/geocoder@^1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-1.4.1.tgz#ee1aa00ce6938ab7a7b9ed4e0fa894a226352ee1" - integrity sha512-P2tvUkJRYcuT71UMC5MalJuHwVCT+JXw/C/rAVTrwhvFXn+4mceHlBBNLXGzQyzVceBE5lER0xC1PB7xBQeL0w== +"@opentripplanner/geocoder@^1.4.0", "@opentripplanner/geocoder@^1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-1.4.2.tgz#0f827dffca42c7f7a23063b54990a291dd028b80" + integrity sha512-yzMVrKXEHO6Y50j9kntk1+odvHaqn9K9D4aKJAd+EabhiZckesfScLb0updmWRUloEWjN45nuDSFto8fbU7Uiw== dependencies: "@conveyal/geocoder-arcgis-geojson" "^0.0.3" "@conveyal/lonlat" "^1.4.1" From be974f972e80f4e921611d49a97df6d9df61cefe Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 24 Jul 2023 17:10:55 -0400 Subject: [PATCH 12/14] improvement(PlaceEditor): Populate coords as interim address while waiting geocoder --- lib/components/user/places/place-editor.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index 18d8dfb09..bf04cd726 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -110,17 +110,19 @@ class PlaceEditor extends Component { intl, locationActions.PLACE_EDITOR_LOCATION, ({ coords }) => { + const { latitude: lat, longitude: lon } = coords + // Populate the "address" field with the coordinates at first. + // If geocoding succeeds, the resulting address will appear there. + this._setLocation({ + category: 'CURRENT_LOCATION', + lat, + lon + }) getGeocoder(geocoderConfig) .reverse({ point: coords }) .then(this._setLocation) .catch((err: Error) => { console.warn(err) - const { latitude: lat, longitude: lon } = coords - this._setLocation({ - category: 'CURRENT_LOCATION', - lat, - lon - }) }) } ) From ff3a232fef63375b080308a13f7376f0f11325a3 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:08:27 -0400 Subject: [PATCH 13/14] chore(deps): Update @opentripplanner/location-field to 2.0.7. --- package.json | 2 +- yarn.lock | 42 ++++++++++++++++-------------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 21bfc5768..30831ce2b 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@opentripplanner/humanize-distance": "^1.2.0", "@opentripplanner/icons": "^2.0.3", "@opentripplanner/itinerary-body": "^4.2.0-alpha.3", - "@opentripplanner/location-field": "^2.0.6", + "@opentripplanner/location-field": "^2.0.7", "@opentripplanner/location-icon": "^1.4.1", "@opentripplanner/map-popup": "^2.0.4", "@opentripplanner/otp2-tile-overlay": "^1.0.3", diff --git a/yarn.lock b/yarn.lock index ec2dcb248..57f678983 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2413,14 +2413,14 @@ lodash.isequal "^4.5.0" qs "^6.9.1" -"@opentripplanner/core-utils@^9.0.0": - version "9.0.2" - resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-9.0.2.tgz#a2fdce7ae99533de623f1fe9266b60068cc02f76" - integrity sha512-xNNxbInolf4V2IzR2IXiPRsnxRqRMHf9qTc6n4k3dfHO4tVXFakk9frD4t6i+XgboXLhgQqn1ZMQaGsp8N9Xjw== +"@opentripplanner/core-utils@^9.0.0-alpha.33", "@opentripplanner/core-utils@^9.0.0-alpha.34": + version "9.0.0-alpha.34" + resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-9.0.0-alpha.34.tgz#63075efb6dd1bf8ba05e27b087c89d3f56827b22" + integrity sha512-jELEvn3diXd149ueIiBO0XxoZerl2+r3d31yZV7teao9yKcjOcTAnLph/FYj/3WdHTBi4iPBOZurgWJDpauL1g== dependencies: "@conveyal/lonlat" "^1.4.1" "@mapbox/polyline" "^1.1.0" - "@opentripplanner/geocoder" "^1.4.1" + "@opentripplanner/geocoder" "^1.4.0" "@styled-icons/foundation" "^10.34.0" "@turf/along" "^6.0.1" bowser "^2.7.0" @@ -2432,14 +2432,14 @@ lodash.isequal "^4.5.0" qs "^6.9.1" -"@opentripplanner/core-utils@^9.0.0-alpha.33", "@opentripplanner/core-utils@^9.0.0-alpha.34": - version "9.0.0-alpha.34" - resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-9.0.0-alpha.34.tgz#63075efb6dd1bf8ba05e27b087c89d3f56827b22" - integrity sha512-jELEvn3diXd149ueIiBO0XxoZerl2+r3d31yZV7teao9yKcjOcTAnLph/FYj/3WdHTBi4iPBOZurgWJDpauL1g== +"@opentripplanner/core-utils@^9.0.2": + version "9.0.2" + resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-9.0.2.tgz#a2fdce7ae99533de623f1fe9266b60068cc02f76" + integrity sha512-xNNxbInolf4V2IzR2IXiPRsnxRqRMHf9qTc6n4k3dfHO4tVXFakk9frD4t6i+XgboXLhgQqn1ZMQaGsp8N9Xjw== dependencies: "@conveyal/lonlat" "^1.4.1" "@mapbox/polyline" "^1.1.0" - "@opentripplanner/geocoder" "^1.4.0" + "@opentripplanner/geocoder" "^1.4.1" "@styled-icons/foundation" "^10.34.0" "@turf/along" "^6.0.1" bowser "^2.7.0" @@ -2478,16 +2478,6 @@ "@opentripplanner/location-icon" "^1.4.1" flat "^5.0.2" -"@opentripplanner/geocoder@1.4.1": - version "1.4.1" - resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-1.4.1.tgz#ee1aa00ce6938ab7a7b9ed4e0fa894a226352ee1" - integrity sha512-P2tvUkJRYcuT71UMC5MalJuHwVCT+JXw/C/rAVTrwhvFXn+4mceHlBBNLXGzQyzVceBE5lER0xC1PB7xBQeL0w== - dependencies: - "@conveyal/geocoder-arcgis-geojson" "^0.0.3" - "@conveyal/lonlat" "^1.4.1" - isomorphic-mapzen-search "^1.6.1" - lodash.memoize "^4.1.2" - "@opentripplanner/geocoder@^1.4.0", "@opentripplanner/geocoder@^1.4.1", "@opentripplanner/geocoder@^1.4.2": version "1.4.2" resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-1.4.2.tgz#0f827dffca42c7f7a23063b54990a291dd028b80" @@ -2547,14 +2537,14 @@ react-resize-detector "^4.2.1" string-similarity "^4.0.4" -"@opentripplanner/location-field@^2.0.6": - version "2.0.6" - resolved "https://registry.yarnpkg.com/@opentripplanner/location-field/-/location-field-2.0.6.tgz#449b93b2dcb565a5f994bd92673bff94682bcb1c" - integrity sha512-e/XjqT94gwMN/SxnWPiCQrWppih+0FIs9q5sarIhJNyKMhf6p5V8vnqz8ywI7YSohnkHyKZepow9l6eTLhwS0w== +"@opentripplanner/location-field@^2.0.7": + version "2.0.7" + resolved "https://registry.yarnpkg.com/@opentripplanner/location-field/-/location-field-2.0.7.tgz#a4479041c0c82d8f469076a47bc9874de2330efb" + integrity sha512-yexAnUk4CEnxDhAzTmA4rR4xF7aw18THFhdstf6Z7TdceVUxUdIFJv3Pa6A4IjudURN947hi6euuY+qUU0TBqw== dependencies: "@conveyal/geocoder-arcgis-geojson" "^0.0.3" - "@opentripplanner/core-utils" "^9.0.0" - "@opentripplanner/geocoder" "1.4.1" + "@opentripplanner/core-utils" "^9.0.2" + "@opentripplanner/geocoder" "^1.4.2" "@opentripplanner/humanize-distance" "^1.2.0" "@opentripplanner/location-icon" "^1.4.1" "@styled-icons/fa-solid" "^10.34.0" From 6e5bd2131165ede99562236df2da537baceb7522 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 28 Jul 2023 10:59:11 -0400 Subject: [PATCH 14/14] improvement(PlaceEditor): Relax location validation rule. --- lib/components/user/places/place-editor.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/components/user/places/place-editor.tsx b/lib/components/user/places/place-editor.tsx index bf04cd726..8dc509f74 100644 --- a/lib/components/user/places/place-editor.tsx +++ b/lib/components/user/places/place-editor.tsx @@ -84,7 +84,7 @@ class PlaceEditor extends Component { static contextType = ComponentContext _setLocation = (location: Location) => { - const { intl, setTouched, setValues, values } = this.props + const { intl, setValues, values } = this.props const { category, lat, lon, name } = location setValues({ ...values, @@ -97,7 +97,6 @@ class PlaceEditor extends Component { lat, lon }) - setTouched({ address: true }) } _handleLocationChange = (e: LocationSelectedEvent) => {