homeflowjs 0.11.5 → 0.11.7

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.
@@ -205,3 +205,8 @@ export const setSelectedMarker = (payload) => ({
205
205
  type: PropertiesActionTypes.SET_SELECTED_MARKER,
206
206
  payload,
207
207
  });
208
+
209
+ export const setBreadcrumbs = (payload) => ({
210
+ type: PropertiesActionTypes.SET_BREADCRUMBS,
211
+ payload,
212
+ });
@@ -8,6 +8,7 @@ const PropertiesActionTypes = {
8
8
  SET_PAGINATION: 'SET_PAGINATION',
9
9
  SET_PROPERTY_LINKS: 'SET_PROPERTY_LINKS',
10
10
  SET_SELECTED_MARKER: 'SET_SELECTED_MARKER',
11
+ SET_BREADCRUMBS: 'SET_BREADCRUMBS',
11
12
  };
12
13
 
13
14
  export default PropertiesActionTypes;
@@ -23,6 +23,7 @@ const BranchesMap = ({
23
23
  displayPopup,
24
24
  selectedBranch,
25
25
  branches: branchesProp,
26
+ MapContainerProps,
26
27
  }) => {
27
28
  let branches = !!branchesProp.length
28
29
  ? branchesProp
@@ -125,6 +126,7 @@ const BranchesMap = ({
125
126
  bounds={bounds}
126
127
  scrollWheelZoom={scrollWheelZoom}
127
128
  style={{ height: '100%' }}
129
+ {...MapContainerProps}
128
130
  >
129
131
  {google ? (
130
132
  <ReactLeafletGoogleLayer apiKey={gmapsKey} type="roadmap" />
@@ -149,7 +151,8 @@ BranchesMap.propTypes = {
149
151
  markerClickHandler: PropTypes.func,
150
152
  displayPopup : PropTypes.bool,
151
153
  selectedBranch: PropTypes.object,
152
- branches: PropTypes.arrayOf(PropTypes.object)
154
+ branches: PropTypes.arrayOf(PropTypes.object),
155
+ MapContainerProps: PropTypes.object
153
156
  };
154
157
 
155
158
  BranchesMap.defaultProps = {
@@ -162,7 +165,8 @@ BranchesMap.defaultProps = {
162
165
  markerClickHandler: () => {},
163
166
  displayPopup: true,
164
167
  selectedBranch: {},
165
- branches: []
168
+ branches: [],
169
+ MapContainerProps: {}
166
170
  };
167
171
 
168
172
  const mapStateToProps = (state) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,6 +23,7 @@ export default class DraggableMap {
23
23
  this.render = this.render.bind(this);
24
24
  this.generateMap = this.generateMap.bind(this);
25
25
  this.properties = this.getProperties();
26
+ this.breadcrumbs = null;
26
27
  if (Homeflow.get('select_marker_on_click')) {
27
28
  this.selectedMarker = null;
28
29
  store.subscribe(() => {
@@ -35,6 +36,8 @@ export default class DraggableMap {
35
36
  }
36
37
  })
37
38
  }
39
+
40
+ if (Homeflow.get('breadcrumbs_map')) store.subscribe(() => this.handleBreadcrumbsInit());
38
41
  }
39
42
 
40
43
  getSearch() {
@@ -53,10 +56,7 @@ export default class DraggableMap {
53
56
  this.mapLoadedTimes = 1;
54
57
  this.render();
55
58
  this.buildPolygon();
56
- const properties = this.properties;
57
- if (properties != null) {
58
- this.setMarkersFor(properties);
59
- }
59
+ this.setMarkersFor(this.propertiesOrBreadcrumbs());
60
60
  if (this.noLocationfound) { this.setToMarkeredBounds(); }
61
61
  if (Homeflow.get('custom_map_zoom') !== null) {
62
62
  this.map.setZoom(Homeflow.get('custom_map_zoom'));
@@ -74,7 +74,9 @@ export default class DraggableMap {
74
74
  // }
75
75
 
76
76
  this.generateMap();
77
- if (!Homeflow.get('free_text_search')) { this.map.on('zoomend', () => (this.onMapDrag())); }
77
+ if (!Homeflow.get('free_text_search') && !Homeflow.get('breadcrumbs_map')) {
78
+ this.map.on('zoomend', () => (this.onMapDrag()));
79
+ }
78
80
  this.map.on('dragend', () => (this.onMapDrag()));
79
81
  const _this = this;
80
82
 
@@ -120,7 +122,7 @@ export default class DraggableMap {
120
122
  }
121
123
 
122
124
  generateMarker(property) {
123
- const marker = L.marker([property.lat, property.lng], { icon: this.generateMarkerIcon(property) });
125
+ const marker = L.marker([property.lat, property.lng], { icon: Homeflow.get('custom_property_pin')(property) });
124
126
 
125
127
  // add the property to marker attributes so they can be accessed on click
126
128
  marker.property = property;
@@ -242,12 +244,12 @@ export default class DraggableMap {
242
244
  }
243
245
  }
244
246
 
245
- setMarkersFor(properties) {
247
+ setMarkersFor(propertiesOrBreadcrumbs) {
246
248
  let bounds;
247
249
  if (this.marker_layer != null) { this.map.removeLayer(this.marker_layer); }
248
- if (!properties) { return null }
250
+ if (!propertiesOrBreadcrumbs) { return null }
249
251
 
250
- if (Homeflow.get('pin_clustering')) {
252
+ if (Homeflow.get('pin_clustering') && !this.breadcrumbs?.length) {
251
253
  let radius = Homeflow.get('custom_clustering_radius');
252
254
  if (!radius) {
253
255
  radius = 10;
@@ -256,10 +258,10 @@ export default class DraggableMap {
256
258
  } else {
257
259
  this.marker_layer = L.featureGroup();
258
260
  }
259
- const markers = properties.map((property) => {
260
- if (property.property_id != null) {
261
- if (property.lat !== 0 && property.lng !== 0) {
262
- const m = this.generateMarker(property);
261
+ const markers = propertiesOrBreadcrumbs.map((propertyOrBreadcrumb) => {
262
+ if (propertyOrBreadcrumb.property_id != null || Homeflow.get('breadcrumbs_map')) {
263
+ if (propertyOrBreadcrumb.lat !== 0 && propertyOrBreadcrumb.lng !== 0) {
264
+ const m = this.generateMarker(propertyOrBreadcrumb);
263
265
  this.marker_layer.addLayer(m);
264
266
  return m;
265
267
  }
@@ -409,7 +411,7 @@ export default class DraggableMap {
409
411
  // if (this.tile_view != null) {
410
412
  // this.tile_view = new Ctesius.Views.Tiles({ collection: this.collection });
411
413
  // }
412
- return this.setMarkersFor(this.properties);
414
+ return this.setMarkersFor(this.propertiesOrBreadcrumbs());
413
415
  });
414
416
  }
415
417
  }
@@ -573,7 +575,7 @@ export default class DraggableMap {
573
575
  // this.tile_view = new Ctesius.Views.Tiles({ collection: this.collection });
574
576
  // }
575
577
 
576
- return this.setMarkersFor(json.properties);
578
+ return this.setMarkersFor(this.propertiesOrBreadcrumbs());
577
579
  })
578
580
  // return $.get(url, (res, status, xhr) => {
579
581
  // s.set('performed_data', res);
@@ -623,4 +625,27 @@ export default class DraggableMap {
623
625
 
624
626
  return new L.LatLng(y, x);
625
627
  }
628
+
629
+ propertiesOrBreadcrumbs() {
630
+ const breadcrumbs = this.breadcrumbs;
631
+ const properties = this.properties;
632
+ if (breadcrumbs && breadcrumbs.length) {
633
+ return breadcrumbs;
634
+ } else if (breadcrumbs && !breadcrumbs.length) {
635
+ return properties;
636
+ } else if (properties !== null && !Homeflow.get('breadcrumbs_map')) {
637
+ return properties;
638
+ } else {
639
+ return null;
640
+ }
641
+ }
642
+
643
+ handleBreadcrumbsInit() {
644
+ const { properties: { breadcrumbs } } = store.getState();
645
+
646
+ if (breadcrumbs && this.breadcrumbs !== breadcrumbs) {
647
+ this.breadcrumbs = breadcrumbs;
648
+ this.setMarkersFor(breadcrumbs);
649
+ }
650
+ }
626
651
  }
@@ -83,6 +83,12 @@ const propertiesReducer = (state = INITIAL_STATE, action) => {
83
83
  ...state,
84
84
  selectedMarker: action.payload,
85
85
  };
86
+ case 'SET_BREADCRUMBS': {
87
+ return {
88
+ ...state,
89
+ breadcrumbs: action.payload,
90
+ }
91
+ };
86
92
  default:
87
93
  return state;
88
94
  }
@@ -59,4 +59,12 @@ describe('propertiesReducer', () => {
59
59
 
60
60
  expect(reducedState).toMatchObject(state);
61
61
  });
62
+
63
+ it('Sets breadcrumbs when it receives the SET_BREADCRUMBS action', () => {
64
+ const breadcrumbs = [{ geoname_id: '12345' }, { geoname_id: '45678' }];
65
+ const state = { properties: [] };
66
+ const reducedState = propertiesReducer(state, { type: 'SET_BREADCRUMBS', payload: breadcrumbs });
67
+
68
+ expect(reducedState.breadcrumbs).toEqual([{ geoname_id: '12345' }, { geoname_id: '45678' }]);
69
+ });
62
70
  });
@@ -17,6 +17,7 @@ class LocationInput extends Component {
17
17
  this.onLocationChange = this.onLocationChange.bind(this);
18
18
  // wait half a second after typing stops before fetching results
19
19
  this.debouncedLoadSuggestions = debounce(this.loadSuggestions, DEBOUNCE_DELAY);
20
+ this.abortContRef = React.createRef();
20
21
  }
21
22
 
22
23
  onLocationChange(event, { newValue }) {
@@ -31,8 +32,14 @@ class LocationInput extends Component {
31
32
  }
32
33
 
33
34
  getSuggestions(q) {
34
- return fetch(`/places?term=${q}`)
35
- .then(response => response.json());
35
+ if (this.abortContRef.current) this.abortContRef.current.abort();
36
+ this.abortContRef.current = new AbortController();
37
+ return fetch(`/places?term=${q}`, { signal: this.abortContRef.current.signal })
38
+ .then(response => response.json())
39
+ .catch(e => {
40
+ if (e.code === 20) return;
41
+ console.error(e);
42
+ });
36
43
  }
37
44
 
38
45
  renderSuggestion(suggestion) {
@@ -51,7 +58,7 @@ class LocationInput extends Component {
51
58
  this.getSuggestions(value)
52
59
  .then((data) => {
53
60
  const suggestions = data ? (
54
- data
61
+ data
55
62
  .filter((_item, index) => index < 15 )
56
63
  .map((item) => (
57
64
  { label: item[0], place: item[1] }
@@ -41,6 +41,11 @@ export default (fragment) => {
41
41
  return;
42
42
  }
43
43
 
44
+ if (part.startsWith('gid-')) {
45
+ search.placeId = part.replace(/^gid-/, '');
46
+ return;
47
+ }
48
+
44
49
  if (orderParams.includes(part)) {
45
50
  search.sorted = part;
46
51
  return;
@@ -37,4 +37,10 @@ describe('parseFragment', () => {
37
37
  // Have to use `Array []` to check equality here for some reason
38
38
  expect(parseFragment(fragment).tags).toEqual(Array ['house', 'flat']);
39
39
  });
40
+
41
+ it('turns gid-12345 into Place ID', () => {
42
+ const fragment = '/properties/sales/france/gid-12345/from-3-bed';
43
+
44
+ expect(parseFragment(fragment).placeId).toEqual('12345');
45
+ });
40
46
  });