homeflowjs 0.8.16 → 0.9.2

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/hooks/index.js CHANGED
@@ -1,3 +1,7 @@
1
1
  import useDefaultSort from './use-default-sort.hook';
2
+ import useGeolocate from './use-geolocate';
2
3
 
3
- export { useDefaultSort };
4
+ export {
5
+ useDefaultSort,
6
+ useGeolocate,
7
+ };
@@ -0,0 +1,53 @@
1
+ import { useState } from 'react';
2
+ import notify from '../app/notify';
3
+
4
+ const placesNear = (lat, long) => (
5
+ fetch(`/places?near=${long},${lat}`)
6
+ .then(response => response.json())
7
+ .then((suggestions) => {
8
+ if (!suggestions) return [];
9
+
10
+ return suggestions
11
+ .slice(0, 15)
12
+ .map(([label, place]) => ({ label, place }))
13
+ })
14
+ );
15
+
16
+ const useGeolocate = () => {
17
+ const [location, setLocation] = useState();
18
+
19
+ const onSuccess = (loc) => {
20
+ const { latitude, longitude } = loc.coords;
21
+
22
+ placesNear(latitude, longitude)
23
+ .then((suggestions) => {
24
+ if (!suggestions.length) return;
25
+
26
+ setLocation(suggestions[0]);
27
+ });
28
+ };
29
+
30
+ const onError = (error) => {
31
+ notify('Sorry, something went wrong.', 'error');
32
+ console.warn(`Geolocation failed: ${error.message}`);
33
+ };
34
+
35
+ const handleGeolocate = () => {
36
+ if (!window.navigator || !window.navigator.geolocation) {
37
+ notify('Geolocation is not supported by your browser', 'error');
38
+
39
+ return null;
40
+ }
41
+
42
+ notify('Fetching your location...', 'success');
43
+
44
+ window.navigator.geolocation.getCurrentPosition(onSuccess, onError);
45
+ };
46
+
47
+ return {
48
+ handleGeolocate,
49
+ location,
50
+ };
51
+ };
52
+
53
+ export default useGeolocate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.8.16",
3
+ "version": "0.9.2",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -218,7 +218,11 @@ export default class DraggableMap {
218
218
  if (!store.getState().app.themePreferences.google_maps_api_key) {
219
219
  console.warn('Tried to render a Google map layer without a google maps API key being set in admin.');
220
220
  }
221
- layer = new L.Google('ROADMAP');
221
+ layer = new L.TileLayer(
222
+ 'http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
223
+ subdomains: ['mt0','mt1','mt2','mt3'],
224
+ attribution: '<img src="https://developers.google.com/maps/documentation/images/powered_by_google_on_white.png" alt="Powered by Google" />'
225
+ });
222
226
  }
223
227
 
224
228
  // if a callback has been passed with a custom layer, invoke it
@@ -56,7 +56,11 @@ const SortOrderSelect = (props) => {
56
56
  };
57
57
 
58
58
  return (
59
- <select value={sorted} onChange={handleChange} className={className}>
59
+ <select
60
+ value={sorted || defaultSort}
61
+ onChange={handleChange}
62
+ className={className}
63
+ >
60
64
  {children}
61
65
  </select>
62
66
  );