homeflowjs 0.11.4 → 0.11.6

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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.11.4",
3
+ "version": "0.11.6",
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
  }
@@ -9,6 +9,8 @@ const StampDutyCalculator = ({ scotland, themePreferences }) => {
9
9
  const [type, setType] = useState('residential');
10
10
  const [purchaseType, setPurchaseType] = useState('firstTimeBuyer')
11
11
  const [purchasePrice, setPurchasePrice] = useState();
12
+ const [firstTimeBuyer, setFirstTimeBuyer] = useState(false);
13
+ const [additionalProperty, setAdditionalProperty] = useState(false);
12
14
 
13
15
  const renderCalculator = () => {
14
16
  if (type === 'residential') {
@@ -16,8 +18,8 @@ const StampDutyCalculator = ({ scotland, themePreferences }) => {
16
18
  <DefaultCalculator
17
19
  purchasePrice={purchasePrice}
18
20
  setPurchasePrice={setPurchasePrice}
19
- firstTimeBuyer={purchaseType === 'firstTimeBuyer'}
20
- additionalProperty={purchaseType === 'additional'}
21
+ firstTimeBuyer={firstTimeBuyer}
22
+ additionalProperty={additionalProperty}
21
23
  ukResident
22
24
  />
23
25
  );
@@ -61,22 +63,22 @@ const StampDutyCalculator = ({ scotland, themePreferences }) => {
61
63
  </div>
62
64
  <div className="switches">
63
65
  <div className="form-group">
64
- <button
65
- type="button"
66
- className={`stamp-duty-cal__type ${purchaseType === 'firstTimeBuyer' ? 'selected' : ''}`}
67
- onClick={() => setPurchaseType('firstTimeBuyer')}
68
- >
69
- First Time Buyer
70
- </button>
66
+ <input
67
+ type="checkbox"
68
+ id="firstTime"
69
+ checked={firstTimeBuyer}
70
+ onChange={() => setFirstTimeBuyer(prev => !prev)}
71
+ />
72
+ <label htmlFor="firstTime">First Time Buyer</label>
71
73
  </div>
72
74
  <div className="form-group">
73
- <button
74
- type="button"
75
- className={`stamp-duty-cal__type ${purchaseType === 'additional' ? 'selected' : ''}`}
76
- onClick={() => setPurchaseType('additional')}
77
- >
78
- Additional Property
79
- </button>
75
+ <input
76
+ type="checkbox"
77
+ id="additionalProperty"
78
+ checked={additionalProperty}
79
+ onChange={() => setAdditionalProperty(prev => !prev)}
80
+ />
81
+ <label htmlFor="additionalProperty">Additional Property</label>
80
82
  </div>
81
83
  </div>
82
84
  {renderCalculator()}
@@ -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
  });
@@ -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
  });