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

refactor(example): remove usage of aroundLatLng #2853

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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