Merge pull request #905 from sharetribe/fix-search-on-window-resize

Add path check for map change searches
This commit is contained in:
Hannu Lyytikäinen 2018-08-21 16:19:18 +03:00 committed by GitHub
commit cab54b5ec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -13,6 +13,10 @@ way to update this template, but currently, we follow a pattern:
---
## Upcoming version 2018-08-XX
## v1.4.1 2018-08-21
* [fix] Fix window resize redirecting to search page with reusable map component
[#905](https://github.com/sharetribe/flex-template-web/pull/905)
## v1.4.0 2018-08-17
* [change] Put availability calendar behind a feature flag
[#902](https://github.com/sharetribe/flex-template-web/pull/902)

View file

@ -16,7 +16,7 @@ import {
sdkBoundsToFixedCoordinates,
hasSameSDKBounds,
} from '../../util/googleMaps';
import { createResourceLocatorString } from '../../util/routes';
import { createResourceLocatorString, pathByRouteName } from '../../util/routes';
import { parse, stringify } from '../../util/urlHelpers';
import { propTypes } from '../../util/types';
import { getListingsById } from '../../ducks/marketplaceData.duck';
@ -116,10 +116,18 @@ export class SearchPageComponent extends Component {
const viewportBoundsChanged =
this.viewportBounds && !hasSameSDKBounds(this.viewportBounds, viewportBounds);
const routes = routeConfiguration();
const searchPagePath = pathByRouteName('SearchPage', routes);
const currentPath =
typeof window !== 'undefined' && window.location && window.location.pathname;
// When using the ReusableMapContainer onIdle can fire from other pages than SearchPage too
const isSearchPage = currentPath === searchPagePath;
// If mapSearch url param is given (and we have not just opened mobile map modal)
// or original location search is rendered once,
// we start to react to 'bounds_changed' event by generating new searches
if (viewportBoundsChanged && !this.modalOpenedBoundsChange) {
if (viewportBoundsChanged && !this.modalOpenedBoundsChange && isSearchPage) {
const originMaybe = config.sortSearchByDistance
? { origin: googleLatLngToSDKLatLng(viewportGMapBounds.getCenter()) }
: {};
@ -132,9 +140,7 @@ export class SearchPageComponent extends Component {
};
this.viewportBounds = viewportBounds;
history.push(
createResourceLocatorString('SearchPage', routeConfiguration(), {}, searchParams)
);
history.push(createResourceLocatorString('SearchPage', routes, {}, searchParams));
} else {
this.viewportBounds = viewportBounds;
this.modalOpenedBoundsChange = false;