mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Remove unneeded country from search params and place objects
This commit is contained in:
parent
74f62bc101
commit
5927ac7fe4
5 changed files with 9 additions and 24 deletions
|
|
@ -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>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue