1- import { JSX , ReactNode , useCallback , useContext , useEffect , useRef , useState } from 'react'
1+ import { JSX , ReactNode , useCallback , useEffect , useRef , useState } from 'react'
22import { QueryPoint , QueryPointType } from '@/stores/QueryStore'
33import { Bbox , GeocodingHit , ReverseGeocodingHit } from '@/api/graphhopper'
44import Autocomplete , {
@@ -7,8 +7,7 @@ import Autocomplete, {
77 POIQueryItem ,
88 RecentLocationItem ,
99} from '@/sidebar/search/AddressInputAutocomplete'
10- import { getRecentLocations , saveRecentLocation } from '@/sidebar/search/RecentLocations'
11- import { SettingsContext } from '@/contexts/SettingsContext'
10+ import { getRecentLocations } from '@/sidebar/search/RecentLocations'
1211import ArrowBack from './arrow_back.svg'
1312import Cross from '@/sidebar/times-solid-thin.svg'
1413import CurrentLocationIcon from './current-location.svg'
@@ -30,7 +29,7 @@ export interface AddressInputProps {
3029 point : QueryPoint
3130 points : QueryPoint [ ]
3231 onCancel : ( ) => void
33- onAddressSelected : ( queryText : string , coord : Coordinate | undefined ) => void
32+ onLocationSelected : ( mainText : string , secondText : string | undefined , coord : Coordinate | undefined ) => void
3433 onChange : ( value : string ) => void
3534 clearDragDrop : ( ) => void
3635 moveStartIndex : number
@@ -40,7 +39,6 @@ export interface AddressInputProps {
4039}
4140
4241export default function AddressInput ( props : AddressInputProps ) {
43- const saveRecent = useContext ( SettingsContext ) . saveRecentLocations
4442 const [ origText , setOrigText ] = useState ( props . point . queryText )
4543 // controlled component pattern with initial value set from props
4644 const [ text , setText ] = useState ( props . point . queryText )
@@ -140,15 +138,15 @@ export default function AddressInput(props: AddressInputProps) {
140138 // try to parse input as coordinate. Otherwise query nominatim
141139 const coordinate = textToCoordinate ( text )
142140 if ( coordinate ) {
143- props . onAddressSelected ( text , coordinate )
141+ props . onLocationSelected ( text , undefined , coordinate )
144142 } else if ( autocompleteItems . length > 0 ) {
145143 const index = highlightedResult >= 0 ? highlightedResult : 0
146144 const item = autocompleteItems [ index ]
147145 if ( item instanceof POIQueryItem ) {
148146 handlePoiSearch ( poiSearch , item . result , props . map )
149- props . onAddressSelected ( item . result . text ( item . result . poi ) , undefined )
147+ props . onLocationSelected ( item . result . text ( item . result . poi ) , undefined , undefined )
150148 } else if ( item instanceof RecentLocationItem ) {
151- props . onAddressSelected ( item . toText ( ) , item . point )
149+ props . onLocationSelected ( item . mainText , item . secondText , item . point )
152150 } else if ( highlightedResult < 0 && ! props . point . isInitialized ) {
153151 // by default use the first result, otherwise the highlighted one
154152 getApi ( )
@@ -157,16 +155,13 @@ export default function AddressInput(props: AddressInputProps) {
157155 if ( result && result . hits . length > 0 ) {
158156 const hit : GeocodingHit = result . hits [ 0 ]
159157 const res = nominatimHitToItem ( hit )
160- props . onAddressSelected ( res . mainText + ', ' + res . secondText , hit . point )
161- if ( saveRecent ) saveRecentLocation ( res . mainText , res . secondText , hit . point )
158+ props . onLocationSelected ( res . mainText , res . secondText , hit . point )
162159 } else if ( item instanceof GeocodingItem ) {
163- props . onAddressSelected ( item . toText ( ) , item . point )
164- if ( saveRecent ) saveRecentLocation ( item . mainText , item . secondText , item . point )
160+ props . onLocationSelected ( item . mainText , item . secondText , item . point )
165161 }
166162 } )
167163 } else if ( item instanceof GeocodingItem ) {
168- props . onAddressSelected ( item . toText ( ) , item . point )
169- if ( saveRecent ) saveRecentLocation ( item . mainText , item . secondText , item . point )
164+ props . onLocationSelected ( item . mainText , item . secondText , item . point )
170165 }
171166 }
172167 if ( event . key === 'Enter' ) focusNextOrBlur ( )
@@ -290,7 +285,7 @@ export default function AddressInput(props: AddressInputProps) {
290285 e => e . preventDefault ( ) // prevents that input->onBlur is called when clicking the button (would hide this button and prevent onClick)
291286 }
292287 onClick = { ( ) => {
293- onCurrentLocationSelected ( props . onAddressSelected )
288+ onCurrentLocationSelected ( ( text , coord ) => props . onLocationSelected ( text , undefined , coord ) )
294289 // but when clicked => we want to lose the focus e.g. to close mobile-input view
295290 searchInput . current ! . blur ( )
296291 } }
@@ -310,11 +305,10 @@ export default function AddressInput(props: AddressInputProps) {
310305 onSelect = { item => {
311306 if ( item instanceof GeocodingItem ) {
312307 setText ( item . toText ( ) )
313- props . onAddressSelected ( item . toText ( ) , item . point )
314- if ( saveRecent ) saveRecentLocation ( item . mainText , item . secondText , item . point )
308+ props . onLocationSelected ( item . mainText , item . secondText , item . point )
315309 } else if ( item instanceof RecentLocationItem ) {
316310 setText ( item . toText ( ) )
317- props . onAddressSelected ( item . toText ( ) , item . point )
311+ props . onLocationSelected ( item . mainText , item . secondText , item . point )
318312 } else if ( item instanceof POIQueryItem ) {
319313 handlePoiSearch ( poiSearch , item . result , props . map )
320314 setText ( item . result . text ( item . result . poi ) )
0 commit comments