Remove unneeded country from search params and place objects

This commit is contained in:
Kimmo Puputti 2018-08-09 10:57:52 +03:00
parent 74f62bc101
commit 5927ac7fe4
5 changed files with 9 additions and 24 deletions

View file

@ -25,17 +25,16 @@ const Form = props => {
const PlaceInfo = props => {
const { place } = props;
const { address, country, origin, bounds } = place;
const { address, origin, bounds } = place;
return (
<div>
<p>Submitted place:</p>
<ul>
<li>Address: {address}</li>
<li>Country: {country || '[no country]'}</li>
<li>
Coordinates: {origin.lat}, {origin.lng}
</li>
<li>Bounds: {bounds ? 'yes' : 'no'}</li>
<li>Bounds?: {bounds ? 'yes' : 'no'}</li>
</ul>
</div>
);

View file

@ -98,14 +98,13 @@ class TopbarComponent extends Component {
const { currentSearchParams } = this.props;
const { search, selectedPlace } = values.location;
const { history } = this.props;
const { origin, bounds, country } = selectedPlace;
const { origin, bounds } = selectedPlace;
const originMaybe = config.sortSearchByDistance ? { origin } : {};
const searchParams = {
...currentSearchParams,
...originMaybe,
address: search,
bounds,
country,
};
history.push(createResourceLocatorString('SearchPage', routeConfiguration(), {}, searchParams));
}
@ -151,7 +150,7 @@ class TopbarComponent extends Component {
showGenericError,
} = this.props;
const { mobilemenu, mobilesearch, address, origin, bounds, country } = parse(location.search, {
const { mobilemenu, mobilesearch, address, origin, bounds } = parse(location.search, {
latlng: ['origin'],
latlngBounds: ['bounds'],
});
@ -175,13 +174,13 @@ class TopbarComponent extends Component {
// Only render current search if full place object is available in the URL params
const locationFieldsPresent = config.sortSearchByDistance
? address && origin && bounds && country
: address && bounds && country;
? address && origin && bounds
: address && bounds;
const initialSearchFormValues = {
location: locationFieldsPresent
? {
search: address,
selectedPlace: { address, origin, bounds, country },
selectedPlace: { address, origin, bounds },
}
: null,
};

View file

@ -100,7 +100,7 @@ export class SearchPageComponent extends Component {
const { history, location } = this.props;
// parse query parameters, including a custom attribute named category
const { address, country, bounds, mapSearch, ...rest } = parse(location.search, {
const { address, bounds, mapSearch, ...rest } = parse(location.search, {
latlng: ['origin'],
latlngBounds: ['bounds'],
});
@ -127,7 +127,6 @@ export class SearchPageComponent extends Component {
address,
...originMaybe,
bounds: viewportBounds,
country,
mapSearch: true,
...validFilterParams(rest, this.filters()),
};
@ -367,7 +366,7 @@ SearchPage.loadData = (params, search) => {
latlng: ['origin'],
latlngBounds: ['bounds'],
});
const { page = 1, address, country, origin, ...rest } = queryParams;
const { page = 1, address, origin, ...rest } = queryParams;
const originMaybe = config.sortSearchByDistance && origin ? { origin } : {};
return searchListings({
...rest,

View file

@ -21,16 +21,6 @@ const placeBounds = place => {
return null;
};
const placeCountry = place => {
if (place && place.address_components) {
const country = place.address_components.find(component => {
return component.types.includes('country');
});
return country ? country.short_name : null;
}
return null;
};
/**
* Get a detailed place object
*
@ -60,7 +50,6 @@ export const getPlaceDetails = (placeId, sessionToken) =>
address: place.formatted_address,
origin: placeOrigin(place),
bounds: placeBounds(place),
country: placeCountry(place),
});
}
});

View file

@ -72,7 +72,6 @@ propTypes.place = shape({
address: string.isRequired,
origin: propTypes.latlng,
bounds: propTypes.latlngBounds, // optional viewport bounds
country: string, // country code, e.g. FI, US
});
// Denormalised image object