Merge pull request #1025 from matkoniecz/fix/make-postcode-search-less-annoying

just immediately go to the first match - postcode search
This commit is contained in:
Mike Simpson 2023-01-10 14:50:47 +00:00 committed by GitHub
commit 07f58dab78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,10 +103,7 @@ class SearchBox extends Component<SearchBoxProps, SearchBoxState> {
apiGet(`/api/search?q=${this.state.q}`) apiGet(`/api/search?q=${this.state.q}`)
.then((data) => { .then((data) => {
if (data && data.results){ if (data && data.results){
this.setState({ this.props.onLocate(data.results[0].geometry.coordinates[1], data.results[0].geometry.coordinates[0], data.results[0].attributes.zoom)
results: data.results,
fetching: false
});
} else { } else {
console.error(data); console.error(data);
@ -157,31 +154,7 @@ class SearchBox extends Component<SearchBoxProps, SearchBoxState> {
); );
} }
const resultsList = this.state.results.length? const resultsList = null;
<ul className="search-box-results">
{
this.state.results.map((result) => {
const label = result.attributes.label;
const lng = result.geometry.coordinates[0];
const lat = result.geometry.coordinates[1];
const zoom = result.attributes.zoom;
const href = `?lng=${lng}&lat=${lat}&zoom=${zoom}`;
return (
<li key={result.attributes.label}>
<a
className="search-box-result"
onClick={(e) => {
e.preventDefault();
this.props.onLocate(lat, lng, zoom);
}}
href={href}
>{`${label.substring(0, 4)} ${label.substring(4, 7)}`}</a>
</li>
);
})
}
</ul>
: null;
return ( return (
<div className="search-box" onKeyDown={this.handleKeyPress}> <div className="search-box" onKeyDown={this.handleKeyPress}>
<div className="search-box-pane"> <div className="search-box-pane">