Fix topbar search initial value

This commit is contained in:
Hannu Lyytikainen 2018-06-28 18:31:01 +03:00
parent 812a7b85b0
commit 9333b53bb7
3 changed files with 5 additions and 3 deletions

View file

@ -7,6 +7,7 @@ import { createResourceLocatorString } from '../../util/routes';
import routeConfiguration from '../../routeConfiguration';
import { IconSearch, Button } from '../../components';
import { LocationSearchForm } from '../../forms';
import config from '../../config';
import css from './SectionHero.css';
@ -22,7 +23,8 @@ const SectionHero = props => {
const handleSearchSubmit = values => {
const { search, selectedPlace } = values.location;
const { origin, bounds, country } = selectedPlace;
const searchParams = { address: search, origin, bounds, country };
const originMaybe = config.sortSearchByDistance ? { origin } : {};
const searchParams = { ...originMaybe, address: search, bounds, country };
history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, searchParams));
};

View file

@ -174,7 +174,7 @@ class TopbarComponent extends Component {
);
// Only render current search if full place object is available in the URL params
const locationFieldsPresent = address && origin && bounds && country;
const locationFieldsPresent = address && bounds && country;
const initialSearchFormValues = {
location: locationFieldsPresent
? {

View file

@ -70,7 +70,7 @@ propTypes.route = shape({
// Place object from LocationAutocompleteInput
propTypes.place = shape({
address: string.isRequired,
origin: propTypes.latlng.isRequired,
origin: propTypes.latlng,
bounds: propTypes.latlngBounds, // optional viewport bounds
country: string, // country code, e.g. FI, US
});