homeflowjs 0.13.43 → 0.13.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.13.43",
3
+ "version": "0.13.44",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable */
2
2
  import DraggableMap from './draggable-map';
3
3
  import store from '../../store';
4
- import { currentGeonameId, filterGeonames } from '../../utils/index';
4
+ import { currentGeonameId, filterGeonames, uniqueGeonamesByNameAndArea } from '../../utils/index';
5
5
  import { setProperties, setGeonames, setSelectedMarker } from '../../actions/properties.actions';
6
6
  import { setInitialSearch, setPlace, setSearchField } from '../../actions/search.actions';
7
7
  import { buildQueryString } from '../../search/property-search/property-search';
@@ -283,11 +283,20 @@ export default class GeonamesMap extends DraggableMap {
283
283
  if (json.geonames) {
284
284
  this.geonames = this.concatenateDistinctObjects('geoname_id', this.geonames, json.geonames);
285
285
  window.markerType = 'geonames';
286
- const currentAreaId = store.getState().search.currentSearch?.place?.area;
287
- const geonamesFiltered = filterGeonames(
288
- this.currentGeonameIdFromLocationPath, Number(currentAreaId), this.geonames
289
- );
290
- store.dispatch(setGeonames(geonamesFiltered));
286
+
287
+ const currentSearchPlace = store.getState().search.currentSearch?.place;
288
+ const geonamePosition = currentSearchPlace?.geoname_position || null;
289
+ const area = currentSearchPlace?.area || null;
290
+
291
+ let geonamesToDisplay = uniqueGeonamesByNameAndArea(this.geonames);
292
+
293
+ if (geonamePosition || area) {
294
+ geonamesToDisplay = filterGeonames(
295
+ this.currentGeonameIdFromLocationPath, Number(area), Number(geoname_position), geonamesToDisplay
296
+ );
297
+
298
+ }
299
+ store.dispatch(setGeonames(geonamesToDisplay));
291
300
  } else if (json.properties) {
292
301
  this.properties = this.concatenateDistinctObjects('property_id', this.properties, json.properties);
293
302
  window.markerType = 'properties';
@@ -310,11 +319,20 @@ export default class GeonamesMap extends DraggableMap {
310
319
  this.hideSuggestedDestinations();
311
320
  this.markersInitialized = true;
312
321
  } else if (window.markerType === 'geonames' && this.geonames?.length) {
313
- const currentAreaId = store.getState().search.currentSearch?.place?.area;
314
- const geonamesFiltered = filterGeonames(
315
- this.currentGeonameIdFromLocationPath, Number(currentAreaId), this.geonames
316
- );
317
- geonamesFiltered.forEach(geoname => this.setGeonameMarker(geoname));
322
+ const currentSearchPlace = store.getState()?.search?.currentSearch?.place;
323
+
324
+ const geonamePosition = currentSearchPlace?.geoname_position || null;
325
+ const area = currentSearchPlace?.area || null;
326
+
327
+ let geonamesToDisplay = uniqueGeonamesByNameAndArea(this.geonames);
328
+
329
+ if (geonamePosition || area) {
330
+ geonamesToDisplay = filterGeonames(
331
+ this.currentGeonameIdFromLocationPath, Number(area), Number(geonamePosition), geonamesToDisplay
332
+ );
333
+ }
334
+
335
+ geonamesToDisplay.forEach(geoname => this.setGeonameMarker(geoname));
318
336
  this.showSuggestedDestinations();
319
337
  this.markersInitialized = true;
320
338
  }
package/utils/index.js CHANGED
@@ -93,10 +93,42 @@ export const currentGeonameId = (path) => {
93
93
 
94
94
  export const DEBOUNCE_DELAY = 200;
95
95
 
96
- export const filterGeonames = (geonameId = null, areaId = null, geonames) => {
96
+ export const filterGeonames = (geonameId = null, areaId = null, geoPosition = null, geonames) => {
97
97
  if (!geonameId) return geonames;
98
98
 
99
- if (areaId) return geonames.filter((geoname) => geoname?.geoname_id !== geonameId && geoname?.area < areaId);
100
-
101
- return geonames.filter((geoname) => geoname?.geoname_id !== geonameId);
99
+ // Filter our same id
100
+ let filtered = geonames.filter((geoname) => geoname?.geoname_id !== geonameId);
101
+
102
+ // Filter out higher area
103
+ if (areaId && !geoPosition) filtered = filtered.filter((geoname) => geoname?.area < areaId);
104
+
105
+ // Filter out lower geoname_position
106
+ if (geoPosition) filtered = filtered.filter((geoname) => {
107
+ // Fallback to area if no geoname_position
108
+ if (
109
+ geoname?.geoname_position === 0
110
+ && geoname?.area
111
+ && geoname?.area !== 0
112
+ && areaId
113
+ ) return geoname?.area < areaId;
114
+ return geoname?.geoname_position > geoPosition;
115
+ });
116
+
117
+ return filtered;
102
118
  };
119
+
120
+ export const uniqueGeonamesByNameAndArea = (geonames) => {
121
+ // One of the duplicated Geonames comes with geoname_position set as 0
122
+ // First set the one with geoname_position = 0 before the one with actual value, ordered by properties_count (as the response).
123
+ const sortByNameAndGeonamePosition = geonames.sort(
124
+ (first, second) => {
125
+ if (first.name === second.name) return first?.geoname_position - second?.geoname_position;
126
+ return first.properties_count > second.properties_count ? -1 : 1;
127
+ }
128
+ );
129
+ // Then remove duplicates by name
130
+ const uniqueNamesOnly = [...new Map(sortByNameAndGeonamePosition.map(item => [item['name'], item])).values()];
131
+
132
+ // Finally remove if they have the same area
133
+ return [...new Map(uniqueNamesOnly.map(item => [item['area'], item])).values()]
134
+ };