Skip to content

Commit

Permalink
show previous autocomplete elements
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Aug 10, 2024
1 parent a5382eb commit af2518c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/sidebar/search/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export default function AddressInput(props: AddressInputProps) {
const [hasFocus, setHasFocus] = useState(false)
const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })

// container for geocoding results which gets set by the geocoder class and set to empty if the underlying query point gets changed from outside
// also gets filled with an item to select the current location as input if input has focus and geocoding results are
// empty
// container for geocoding results which gets set by the geocoder class and set to empty if the underlying query
// point gets changed from outside also gets filled with an item to select the current location as input if input
// has focus and geocoding results are empty
const [origAutocompleteItems, setOrigAutocompleteItems] = useState<AutocompleteItem[]>([])
const [autocompleteItems, setAutocompleteItems] = useState<AutocompleteItem[]>([])
const [geocoder] = useState(
new Geocoder(getApi(), (query, provider, hits) => {
Expand All @@ -58,10 +59,6 @@ export default function AddressInput(props: AddressInputProps) {
)
})

// TODO autocompleteItems is empty here because query point changed from outside somehow
// const res = autocompleteItems.length > 1 ? autocompleteItems.slice(0, autocompleteItems.length - 2) : autocompleteItems
// res.concat(items)

setOrigText(query)
setAutocompleteItems(items)
})
Expand All @@ -76,6 +73,7 @@ export default function AddressInput(props: AddressInputProps) {

function hideSuggestions() {
geocoder.cancel()
setOrigAutocompleteItems(autocompleteItems)
setAutocompleteItems([])
}

Expand Down Expand Up @@ -164,8 +162,6 @@ export default function AddressInput(props: AddressInputProps) {
const type = props.point.type

// get the bias point for the geocoder
// (the query point above the current one)
const autocompleteIndex = props.points.findIndex(point => !point.isInitialized)
const lonlat = toLonLat(getMap().getView().getCenter()!)
const biasCoord = { lng: lonlat[0], lat: lonlat[1] }

Expand Down Expand Up @@ -208,6 +204,7 @@ export default function AddressInput(props: AddressInputProps) {
onFocus={() => {
setHasFocus(true)
props.clearDragDrop()
if (origAutocompleteItems.length > 0) setAutocompleteItems(origAutocompleteItems)
}}
onBlur={() => {
if (!isSmallScreen) hideSuggestions() // see #398
Expand Down
3 changes: 2 additions & 1 deletion src/sidebar/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ const SearchBox = ({
onCancel={() => console.log('cancel')}
onAddressSelected={(queryText, coordinate) => {
const initCount = points.filter(p => p.isInitialized).length
if (coordinate && initCount == 0) Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))
if (coordinate && initCount != points.length)
Dispatcher.dispatch(new SetBBox(getBBoxFromCoord(coordinate)))

Dispatcher.dispatch(
new SetPoint(
Expand Down

0 comments on commit af2518c

Please sign in to comment.