Skip to content

Commit

Permalink
Merge pull request #857 from sharetribe/topbar-search-value
Browse files Browse the repository at this point in the history
Fix Topbar search initial value
  • Loading branch information
lyyder authored Jul 2, 2018
2 parents 812a7b8 + c3e77ef commit 682629e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/SectionHero/SectionHero.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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));
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/Topbar/Topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ 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 = config.sortSearchByDistance
? address && origin && bounds && country
: address && bounds && country;
const initialSearchFormValues = {
location: locationFieldsPresent
? {
Expand Down
2 changes: 1 addition & 1 deletion src/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down

0 comments on commit 682629e

Please sign in to comment.