Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
refactor(example): remove usage of aroundLatLng (#2853)
Browse files Browse the repository at this point in the history
**Summary**

This PR removes the usage of `aroundLatLng` inside the geo-search example. The logic to apply the parameter was present, but the App doesn't expose a way to use it. We don't have to support it since it uses either the IP of the user of the bounding box of the map.
  • Loading branch information
samouss committed Oct 11, 2019
1 parent c987087 commit 29a7351
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions examples/geo-search/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
'6be0576ff61c053d5f9a3225e2a90f76',
{
_useRequestCache: true,
}
);

const updateAfter = 700;
Expand All @@ -22,15 +25,8 @@ class App extends Component {
constructor() {
super();

// retrieve searchState and aroundLatLng properties from the URL at first rendering
const initialSearchState = qs.parse(window.location.search.slice(1));
const aroundLatLng = initialSearchState.configure
? initialSearchState.configure.aroundLatLng
: null;

this.state = {
searchState: initialSearchState,
aroundLatLng,
searchState: qs.parse(window.location.search.slice(1)),
};

window.addEventListener('popstate', ({ state: searchState }) => {
Expand All @@ -50,13 +46,11 @@ class App extends Component {
}, updateAfter);

this.setState(previousState => {
// when a new query is performed, removed the aroundLatLng + boundingBox
const hasQueryChanged =
previousState.searchState.query !== searchState.query;

return {
...previousState,
aroundLatLng: !hasQueryChanged ? previousState.aroundLatLng : null,
searchState: {
...searchState,
boundingBox: !hasQueryChanged ? searchState.boundingBox : null,
Expand All @@ -66,12 +60,10 @@ class App extends Component {
};

render() {
const { aroundLatLng, searchState } = this.state;
const { searchState } = this.state;

const parameters = {};
if (aroundLatLng && !searchState.boundingBox) {
parameters.aroundLatLng = aroundLatLng;
} else if (!searchState.boundingBox) {
if (!searchState.boundingBox) {
parameters.aroundLatLngViaIP = true;
parameters.aroundRadius = 'all';
}
Expand Down

0 comments on commit 29a7351

Please sign in to comment.