thm-p3-configurator 0.0.201 → 0.0.202

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.
@@ -54,7 +54,7 @@ const LocationsLoading = () => {
54
54
  };
55
55
  const LocationAutoComplete = _ref => {
56
56
  let {
57
- setUserLocation,
57
+ onLocationUpdate,
58
58
  label = 'Postcode'
59
59
  } = _ref;
60
60
  const [sessionToken, setSessionToken] = (0, _react.useState)();
@@ -65,21 +65,15 @@ const LocationAutoComplete = _ref => {
65
65
  const [dropdownActive, setDropdownActive] = (0, _react.useState)(false);
66
66
  const [loading, setLoading] = (0, _react.useState)(false);
67
67
  const [error, setError] = (0, _react.useState)('');
68
- const [place, setPlace] = (0, _react.useState)(null);
69
68
  const map = (0, _reactGoogleMaps.useMap)();
70
69
  const places = (0, _reactGoogleMaps.useMapsLibrary)('places');
71
70
  (0, _react.useEffect)(() => {
72
- var _place$geometry;
73
71
  if (!places || !map) return;
74
72
  setAutocompleteService(new places.AutocompleteService());
75
73
  setPlacesService(new places.PlacesService(map));
76
74
  setSessionToken(new places.AutocompleteSessionToken());
77
- if (place && (_place$geometry = place.geometry) !== null && _place$geometry !== void 0 && _place$geometry.viewport) {
78
- var _place$geometry2;
79
- map.fitBounds((_place$geometry2 = place.geometry) === null || _place$geometry2 === void 0 ? void 0 : _place$geometry2.viewport);
80
- }
81
75
  return () => setAutocompleteService(null);
82
- }, [map, places, place]);
76
+ }, [map, places]);
83
77
  const fetchPredictions = (0, _react.useCallback)(async inputValue => {
84
78
  if (!autocompleteService || !inputValue) {
85
79
  setPredictionResults([]);
@@ -122,21 +116,21 @@ const LocationAutoComplete = _ref => {
122
116
  setInputValue((_placeDetails$formatt = placeDetails === null || placeDetails === void 0 ? void 0 : placeDetails.formatted_address) !== null && _placeDetails$formatt !== void 0 ? _placeDetails$formatt : '');
123
117
  setSessionToken(new places.AutocompleteSessionToken());
124
118
  setDropdownActive(false);
125
- setPlace(placeDetails);
126
119
  if (placeDetails !== null && placeDetails !== void 0 && (_placeDetails$geometr = placeDetails.geometry) !== null && _placeDetails$geometr !== void 0 && _placeDetails$geometr.location) {
127
120
  const {
128
121
  lat,
129
122
  lng
130
123
  } = placeDetails.geometry.location;
131
- setUserLocation({
124
+ const coordinates = {
132
125
  lat: lat(),
133
126
  lng: lng()
134
- });
127
+ };
128
+ onLocationUpdate(coordinates, true);
135
129
  }
136
130
  };
137
131
  placesService === null || placesService === void 0 || placesService.getDetails(detailRequestOptions, detailsRequestCallback);
138
132
  (_document$querySelect = document.querySelector((0, _helpers__.withStyle)("dealer-autocomplete__list"))) === null || _document$querySelect === void 0 || _document$querySelect.scrollTo(0, 0);
139
- }, [places, placesService, sessionToken, setUserLocation]);
133
+ }, [places, placesService, sessionToken, onLocationUpdate, predictionResults]);
140
134
  const handleSubmit = event => {
141
135
  event.preventDefault();
142
136
  };
@@ -66,26 +66,23 @@ const LocationClusteredMap = /*#__PURE__*/_react.default.memo(_ref => {
66
66
  }, [core]);
67
67
  const fitBoundsToMarkers = (0, _react.useCallback)(() => {
68
68
  if (!map || !bounds || locationIds.length === 0) return;
69
+
70
+ // Get all valid coordinates from locations
71
+ const validCoordinates = locationIds.map(id => locationsById[id]).map(location => (0, _geolocation.getCoordinatesByString)(location.googleMapsLocation)).filter(Boolean);
69
72
  if (userLocation) {
70
- bounds.extend(new core.LatLng(userLocation.lat, userLocation.lng));
73
+ map.setCenter(userLocation);
74
+ map.setZoom(11);
75
+ } else {
76
+ validCoordinates.forEach(_ref2 => {
77
+ let {
78
+ lat,
79
+ lng
80
+ } = _ref2;
81
+ bounds.extend(new core.LatLng(lat, lng));
82
+ });
71
83
  map.fitBounds(bounds);
72
- map.setZoom(10);
73
- return;
74
84
  }
75
-
76
- // Batch coordinate calculations
77
- const validCoordinates = locationIds.map(id => locationsById[id]).map(location => (0, _geolocation.getCoordinatesByString)(location.googleMapsLocation)).filter(Boolean);
78
- validCoordinates.forEach(_ref2 => {
79
- let {
80
- lat,
81
- lng
82
- } = _ref2;
83
- bounds.extend(new core.LatLng(lat, lng));
84
- });
85
- map.fitBounds(bounds);
86
85
  }, [map, bounds, locationIds, locationsById, userLocation, core]);
87
-
88
- // Debounce bounds fitting
89
86
  (0, _react.useEffect)(() => {
90
87
  if (!core) return;
91
88
  const debounceFitBounds = (0, _lodash.default)(fitBoundsToMarkers, 150);
@@ -119,6 +119,7 @@ const LocationList = _ref => {
119
119
  locationsById,
120
120
  locationIds,
121
121
  userLocation,
122
+ isLocationSetViaSearch = false,
122
123
  isLoading = false
123
124
  } = _ref;
124
125
  const {
@@ -127,7 +128,7 @@ const LocationList = _ref => {
127
128
  const [{
128
129
  selectedBranch
129
130
  }] = (0, _OrderSessionContext.useOrderSession)();
130
- const selectedRef = (0, _react.useRef)(null);
131
+ const listRef = (0, _react.useRef)(null);
131
132
  const locationsWithDistance = locationIds.map((locationId, index) => {
132
133
  const location = locationsById[locationId];
133
134
  const coordinates = location.googleMapsLocation;
@@ -146,22 +147,26 @@ const LocationList = _ref => {
146
147
  });
147
148
  }).filter(location => location !== null);
148
149
  const sortedLocations = locationsWithDistance.sort((a, b) => {
150
+ const aIsSelected = a.entityId === activeMarkerId || a.entityId === selectedBranch;
151
+ const bIsSelected = b.entityId === activeMarkerId || b.entityId === selectedBranch;
152
+ if (aIsSelected && !bIsSelected) return -1; // a goes to top
153
+ if (!aIsSelected && bIsSelected) return 1; // b goes to top
154
+
149
155
  if (a.distance === null) return 1;
150
156
  if (b.distance === null) return -1;
151
157
  return a.distance - b.distance;
152
158
  });
159
+
160
+ // Handle scrolling when location is set via search
153
161
  (0, _react.useEffect)(() => {
154
- if (sortedLocations !== null && sortedLocations !== void 0 && sortedLocations.length && selectedRef.current) {
155
- selectedRef.current.scrollIntoView({
156
- behavior: 'smooth',
157
- block: 'center'
158
- });
162
+ if (isLocationSetViaSearch && listRef.current) {
163
+ listRef.current.scrollTop = 0;
159
164
  }
160
- }, [activeMarkerId, selectedBranch, sortedLocations]);
165
+ }, [isLocationSetViaSearch, userLocation]);
161
166
  return /*#__PURE__*/_react.default.createElement("div", {
167
+ ref: listRef,
162
168
  className: (0, _helpers__.withStyle)('dealer-list')
163
169
  }, /*#__PURE__*/_react.default.createElement("h5", null, userLocation ? 'Dichtsbijzijnde montagelocaties' : 'Montagelocaties'), isLoading && /*#__PURE__*/_react.default.createElement(LocationsLoading, null), !isLoading && !locationIds.length && /*#__PURE__*/_react.default.createElement(NoLocationFound, null), sortedLocations.map(location => /*#__PURE__*/_react.default.createElement(_LocationListItem.default, {
164
- ref: location.entityId === activeMarkerId || location.entityId === selectedBranch ? selectedRef : null,
165
170
  openingHours: location.openingstijden,
166
171
  title: location.naamVestiging,
167
172
  city: location.city,
@@ -12,6 +12,7 @@ var _reactGoogleMaps = require("@vis.gl/react-google-maps");
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
  var _queries = require("../../__api__/queries");
14
14
  var _constants__ = require("../../__constants__");
15
+ var _ActiveMarkerContext = require("../../__context__/ActiveMarkerContext");
15
16
  var _FormulaContext = require("../../__context__/FormulaContext");
16
17
  var _OrderSessionContext = require("../../__context__/OrderSessionContext");
17
18
  var _helpers__ = require("../../__helpers__");
@@ -61,9 +62,13 @@ const Loaded = /*#__PURE__*/_react.default.memo(_ref => {
61
62
  });
62
63
  const LocationsSelector = /*#__PURE__*/_react.default.memo(() => {
63
64
  const [userLocation, setUserLocation] = (0, _useUserLocation.default)();
65
+ const [isLocationSetViaSearch, setIsLocationSetViaSearch] = (0, _react.useState)(false);
66
+ const {
67
+ setActiveMarkerId
68
+ } = (0, _ActiveMarkerContext.useActiveMarker)();
69
+ const [, dispatch] = (0, _OrderSessionContext.useOrderSession)();
64
70
  const screen = (0, _useBreakpoint.default)();
65
71
  const isDesktop = screen.size >= 1200;
66
- const [visibleIds, setVisibleIds] = (0, _react.useState)([]);
67
72
  const formula = (0, _FormulaContext.useFormula)();
68
73
  const [{
69
74
  franchiseName
@@ -100,21 +105,26 @@ const LocationsSelector = /*#__PURE__*/_react.default.memo(() => {
100
105
  array: locations || [],
101
106
  key: 'entityId'
102
107
  }), [locations]);
103
- (0, _react.useEffect)(() => {
104
- if (!allIds.length) {
105
- return;
108
+
109
+ // Handle location updates from search
110
+ const handleLocationUpdate = function handleLocationUpdate(newLocation) {
111
+ let fromSearch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
112
+ setUserLocation(newLocation);
113
+ setIsLocationSetViaSearch(fromSearch);
114
+
115
+ // Close any open marker popups when searching for a new location
116
+ if (fromSearch) {
117
+ setActiveMarkerId(null);
118
+
119
+ // Also clear any selected branch to avoid confusion
120
+ dispatch({
121
+ payload: {
122
+ branchId: null
123
+ },
124
+ type: _OrderSessionContext.orderSessionActions.SET_SELECTED_BRANCH
125
+ });
106
126
  }
107
- setVisibleIds([]);
108
- const addIdsInBatches = index => {
109
- const offset = 10;
110
- const nextBatch = allIds.slice(index, index + offset);
111
- setVisibleIds(prev => [...prev, ...nextBatch]);
112
- if (index + offset < allIds.length) {
113
- requestAnimationFrame(() => addIdsInBatches(index + offset));
114
- }
115
- };
116
- addIdsInBatches(0);
117
- }, [allIds]);
127
+ };
118
128
  return /*#__PURE__*/_react.default.createElement(_reactGoogleMaps.APIProvider, {
119
129
  apiKey: APP_CONFIG.googleMapsApiKey,
120
130
  libraries: ['marker']
@@ -125,31 +135,33 @@ const LocationsSelector = /*#__PURE__*/_react.default.memo(() => {
125
135
  }, /*#__PURE__*/_react.default.createElement("div", {
126
136
  className: (0, _helpers__.withStyle)(isDesktop ? 'dealer-map__container' : 'dealer-map')
127
137
  }, /*#__PURE__*/_react.default.createElement(_LocationClusteredMap.default, {
128
- locationIds: visibleIds,
138
+ locationIds: allIds,
129
139
  locationsById: byId,
130
140
  userLocation: userLocation
131
141
  }))), /*#__PURE__*/_react.default.createElement("aside", {
132
142
  className: (0, _helpers__.withStyle)('dealer-sidebar col-xl-4 mt-3 mt-xl-0')
133
143
  }, isDesktop && /*#__PURE__*/_react.default.createElement(_LocationAutoComplete.default, {
134
- setUserLocation: setUserLocation
144
+ onLocationUpdate: handleLocationUpdate
135
145
  }), franchiseName && /*#__PURE__*/_react.default.createElement("h6", {
136
146
  className: (0, _helpers__.withStyle)('my-2')
137
147
  }, "Keten: ", franchiseName), /*#__PURE__*/_react.default.createElement(_LocationList.default, {
138
148
  locationIds: allIds,
139
149
  locationsById: byId,
140
- userLocation: userLocation
150
+ userLocation: userLocation,
151
+ isLocationSetViaSearch: isLocationSetViaSearch
141
152
  }))) : /*#__PURE__*/_react.default.createElement("div", {
142
153
  className: (0, _helpers__.withStyle)('row gx-5 mt-3 mt-xl-5 justify-content-center')
143
154
  }, /*#__PURE__*/_react.default.createElement("aside", {
144
155
  className: (0, _helpers__.withStyle)('dealer-sidebar col-xl-4 mt-3 mt-xl-0')
145
156
  }, isDesktop && /*#__PURE__*/_react.default.createElement(_LocationAutoComplete.default, {
146
- setUserLocation: setUserLocation
157
+ onLocationUpdate: handleLocationUpdate
147
158
  }), franchiseName && /*#__PURE__*/_react.default.createElement("h6", {
148
159
  className: (0, _helpers__.withStyle)('my-2')
149
160
  }, "Keten: ", franchiseName), /*#__PURE__*/_react.default.createElement(_LocationList.default, {
150
161
  locationIds: allIds,
151
162
  locationsById: byId,
152
- userLocation: userLocation
163
+ userLocation: userLocation,
164
+ isLocationSetViaSearch: isLocationSetViaSearch
153
165
  })))));
154
166
  });
155
167
  var _default = exports.default = LocationsSelector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.201",
3
+ "version": "0.0.202",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",