homeflowjs 1.0.41 → 1.0.43

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.
@@ -1,21 +1,58 @@
1
+ const sortSearchToCompare = (search) => Object.keys(search).sort().reduce((accumulator, currentValue) => {
2
+ accumulator[currentValue] = search[currentValue];
3
+ return accumulator;
4
+ }, {});
5
+
1
6
  export const addSearchToLocalStorage = (search) => {
7
+ const searchSize = Object.keys(search).length;
8
+ const pageRoute = Homeflow.get('page_route') || '';
9
+ const propertyId = Homeflow.get('property')?.property_id || null;
10
+
11
+ let theSearch = search;
12
+ /**
13
+ * placeId may only be added to the 2nd page load, if added in advance
14
+ * both search terms will match
15
+ */
16
+ if (!theSearch?.placeId && theSearch?.place?.place_id) {
17
+ theSearch = { ...theSearch, placeId: theSearch?.place?.place_id };
18
+ }
19
+
20
+ // Don't add expandedPolygon object to the local search
21
+ if (searchSize === 1 && theSearch?.expandedPolygon) return null;
22
+
2
23
  // Get search history from local storage
3
24
  let searchHistory = localStorage.getItem('searchHistory');
4
25
  searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
5
26
 
27
+
6
28
  // Make a new instance of the search object without the page number.
7
- const searchWithoutPageNumber = { ...search, page: null };
29
+ let searchWithoutPageNumber = { ...theSearch, page: null, expandedPolygon: null };
30
+ searchWithoutPageNumber = sortSearchToCompare(searchWithoutPageNumber);
8
31
 
9
32
  // Make a new instance of the last search object without the page number.
10
- const lastSearchWithoutPageNumber = { ...searchHistory[0], page: null };
33
+ let lastSearchWithoutPageNumber = { ...searchHistory[0], page: null, expandedPolygon: null };
34
+ lastSearchWithoutPageNumber = sortSearchToCompare(lastSearchWithoutPageNumber);
35
+
36
+ /**
37
+ * If the current viewed property is the same as the clicked before
38
+ * don't add the search to the local searches
39
+ * and keep the current last.
40
+ */
41
+ if (
42
+ pageRoute === 'properties#show'
43
+ && propertyId
44
+ && lastSearchWithoutPageNumber?.clickedProperty
45
+ ) {
46
+ if (+lastSearchWithoutPageNumber.clickedProperty === +propertyId) return null;
47
+ }
11
48
 
12
49
  /**
13
50
  * If the searchWithoutPageNumber and lastSearchWithoutPageNumber match,
14
51
  * just update the the last search in local storage to have the search's page number if
15
52
  * it has one.
16
53
  */
17
- if ((JSON.stringify(searchWithoutPageNumber) === JSON.stringify(lastSearchWithoutPageNumber)) && search?.page) {
18
- const lastSearchWithUpdatedPageNumber = { ...searchHistory[0], page: search.page };
54
+ if ((JSON.stringify(searchWithoutPageNumber) === JSON.stringify(lastSearchWithoutPageNumber)) && theSearch?.page) {
55
+ const lastSearchWithUpdatedPageNumber = { ...searchHistory[0], page: theSearch.page };
19
56
  searchHistory.shift();
20
57
  searchHistory.unshift(lastSearchWithUpdatedPageNumber);
21
58
  localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
@@ -27,28 +64,50 @@ export const addSearchToLocalStorage = (search) => {
27
64
  */
28
65
  if ((JSON.stringify(searchWithoutPageNumber) !== JSON.stringify(lastSearchWithoutPageNumber))) {
29
66
  // Add search to the front of the array ...
30
- searchHistory.unshift(search);
67
+ searchHistory.unshift(theSearch);
31
68
  // ... and ensure only 10 most recent searches in history.
32
69
  localStorage.setItem('searchHistory', JSON.stringify(searchHistory.slice(0, 10)));
33
70
  }
34
71
  };
35
72
 
36
- export const updateLastSearchPageInLocalStorage = (change) => {
73
+ export const updateLastSearchPageInLocalStorage = (change, toChange = false) => {
37
74
  // Get search history from local storage
38
75
  let searchHistory = localStorage.getItem('searchHistory');
39
76
  searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
40
- searchHistory[0].page = (searchHistory[0].page ? +searchHistory[0].page : 1) + change;
77
+ if (toChange) {
78
+ searchHistory[0].page = change;
79
+ } else {
80
+ searchHistory[0].page = (searchHistory[0].page ? +searchHistory[0].page : 1) + change;
81
+ }
41
82
  localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
42
83
  };
43
84
 
44
- export const updateLastSearchOnPropertyCardClick = (propertyID) => {
85
+ export const updateLastSearchOnPropertyCardClick = (propertyID, remove = false) => {
45
86
  // Get search history from local storage
46
87
  let searchHistory = localStorage.getItem('searchHistory');
47
88
  searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
48
89
 
49
90
  if (searchHistory?.length === 0) return null;
50
91
 
51
- // Add property about to be visited to the search object in local storage
52
- const newSearchHistory = searchHistory.map((search, index) => index === 0 ? {...search, clickedProperty: propertyID } : search);
92
+ const newSearchHistory = searchHistory.map((search, index) => {
93
+ if (index === 0) {
94
+ if (remove && search?.clickedProperty && propertyID === search?.clickedProperty) {
95
+ const { clickedProperty, ...rest } = search;
96
+ /**
97
+ * Remove clickedProperty from last search on back to search
98
+ * if last property clicked and current property match
99
+ */
100
+ return { ...rest };
101
+ }
102
+ /**
103
+ * Add property about to be visited to the search object in local storage
104
+ */
105
+ return {
106
+ ...search,
107
+ clickedProperty: propertyID,
108
+ }
109
+ }
110
+ return search;
111
+ });
53
112
  localStorage.setItem('searchHistory', JSON.stringify(newSearchHistory));
54
113
  }
@@ -32,7 +32,9 @@ const useLoadPreviousProperties = () => {
32
32
  if (currentFirstPage > 1) {
33
33
  dispatch(loadPage(currentFirstPage - 1))
34
34
  .then(() => {
35
- addSearchToLocalStorage(currentSearch);
35
+ const pageNumber = currentSearch?.page ? currentSearch?.page - 1 : 1;
36
+ const searchToLocal = {...currentSearch, page: pageNumber };
37
+ addSearchToLocalStorage(searchToLocal);
36
38
  updatePageInURL(currentFirstPage - 1);
37
39
  setCurrentTopPage(currentFirstPage - 1);
38
40
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
-
2
+ import { updateLastSearchOnPropertyCardClick } from '../../app/user-history';
3
3
  import { buildQueryString } from '../../search/property-search/property-search';
4
4
 
5
5
  const BackToSearchButton = ({ children, ...otherProps }) => {
@@ -8,23 +8,30 @@ const BackToSearchButton = ({ children, ...otherProps }) => {
8
8
 
9
9
  const lastSearch = JSON.parse(searchHistory)?.[0];
10
10
  const secondToLastSearch = JSON.parse(searchHistory)?.[1] || null;
11
+ const property = Homeflow.get('property');
12
+ const currentPropertyID = property?.propertyId || property?.property_id || null;
11
13
 
12
14
  let validSearch = lastSearch;
13
-
14
- if (secondToLastSearch) {
15
- const property = Homeflow.get('property');
16
- const currentPropertyID = property?.propertyId || property?.property_id;
17
-
18
- if (currentPropertyID === secondToLastSearch?.clickedProperty) validSearch = secondToLastSearch;
15
+
16
+ if (!lastSearch?.clickedProperty || lastSearch?.clickedProperty !== currentPropertyID) {
17
+ if (secondToLastSearch && !lastSearch?.clickedProperty) {
18
+ if (currentPropertyID === secondToLastSearch?.clickedProperty) validSearch = secondToLastSearch;
19
+ }
19
20
  }
20
21
 
21
- // delete the 'place' so we don't get [object Object] in URL if place is found in object.
22
+ /**
23
+ * Delete the 'place' so we don't get [object Object] in URL if place is found in object.
24
+ * And also the expanded polygon array in URL if expanded polygon is found in object
25
+ */
22
26
  if (validSearch?.place) delete validSearch.place;
27
+ if (validSearch?.expandedPolygon) delete validSearch.expandedPolygon;
23
28
 
24
- const href = `/search?${buildQueryString(validSearch)}`;
29
+ const href = `/search?${buildQueryString(validSearch, true)}`;
25
30
 
31
+ const removeFromSearch = (id) => updateLastSearchOnPropertyCardClick(id, true);
32
+
26
33
  return (
27
- <a href={href} {...otherProps}>
34
+ <a href={href} onClick={() => removeFromSearch(property?.propertyId || property?.property_id)} {...otherProps}>
28
35
  {children}
29
36
  </a>
30
37
  );
@@ -32,7 +32,9 @@ const LoadMoreButton = (props) => {
32
32
  dispatch(loadNext())
33
33
  .then(() => {
34
34
  setLoading(false);
35
- addSearchToLocalStorage(currentSearch);
35
+ const pageNumber = currentSearch?.page ? currentSearch?.page + 1 : 2;
36
+ const searchToLocal = {...currentSearch, page: pageNumber };
37
+ addSearchToLocalStorage(searchToLocal);
36
38
  });
37
39
  }}
38
40
  {...otherProps}
@@ -1,10 +1,9 @@
1
1
  import React, { useEffect, useRef, useMemo } from 'react';
2
2
  import { connect, useSelector } from 'react-redux';
3
3
  import PropTypes from 'prop-types';
4
-
5
4
  import { propertiesByPage, updatePageInURL } from '../property-utils/property-utils';
6
5
  import { usePropertyInfiniteScroll, useLoadPreviousProperties } from '../../hooks';
7
- import { updateLastSearchOnPropertyCardClick } from '../../app/user-history.js';
6
+ import { updateLastSearchOnPropertyCardClick, updateLastSearchPageInLocalStorage } from '../../app/user-history.js';
8
7
 
9
8
  const ConditionalWrapper = ({ condition, wrapper, children }) => (
10
9
  condition ? wrapper(children) : children
@@ -47,6 +46,7 @@ const PropertiesDisplay = ({
47
46
  entries.forEach((entry) => {
48
47
  if (entry.isIntersecting && entry.target?.dataset?.pageMarker) {
49
48
  updatePageInURL(parseInt(entry.target.dataset.pageMarker, 10));
49
+ updateLastSearchPageInLocalStorage(parseInt(entry.target.dataset.pageMarker, 10), true);
50
50
  }
51
51
  });
52
52
  });
@@ -61,7 +61,6 @@ const PropertiesDisplay = ({
61
61
  }, [properties]);
62
62
 
63
63
  const addWrapper = displayType === 'list';
64
-
65
64
  const showPreviousBtn = includePreviousBtn && hasPreviousPage && !loadingPreviousProperties;
66
65
  const showPreviousLoader = includePreviousBtn
67
66
  && InfiniteScrollLoader
@@ -180,6 +179,7 @@ PropertiesDisplay.propTypes = {
180
179
  Item: PropTypes.elementType.isRequired,
181
180
  displayType: PropTypes.string.isRequired,
182
181
  infiniteScroll: PropTypes.bool.isRequired,
182
+ includePreviousBtn: PropTypes.bool.isRequired,
183
183
  InfiniteScrollLoader: PropTypes.func,
184
184
  inserts: PropTypes.array,
185
185
  noResultsMessage: PropTypes.node,
@@ -188,6 +188,7 @@ PropertiesDisplay.propTypes = {
188
188
  PropertiesDisplay.defaultProps = {
189
189
  inserts: null,
190
190
  InfiniteScrollLoader: null,
191
+ includePreviousBtn: false,
191
192
  noResultsMessage: <p>There were no properties matching your search.</p>,
192
193
  };
193
194
 
@@ -21,7 +21,7 @@ const fragmentize = (key, value) => {
21
21
 
22
22
  const minOrMaxBedZero = (key, value) => (key === 'minBeds' || key === 'maxBeds') && value === 0;
23
23
 
24
- export const buildQueryString = (search) => {
24
+ export const buildQueryString = (search, withPlace = false) => {
25
25
  const queryParams = [];
26
26
  const fragmentParams = [];
27
27
 
@@ -39,10 +39,18 @@ export const buildQueryString = (search) => {
39
39
  if (Array.isArray(value) && !value.length) return;
40
40
 
41
41
  // only include either q or place ID
42
- if ((key === 'q' && !search.isQuerySearch)
43
- || (key === 'placeId' && search.isQuerySearch)
44
- || (key === 'place')
45
- || (key === 'poly' && search.isQuerySearch)) return;
42
+ if (
43
+ (key === 'q' && !search.isQuerySearch)
44
+ || (key === 'placeId' && search.isQuerySearch)
45
+ || (!withPlace && key === 'place')
46
+ || (key === 'poly' && search.isQuerySearch)
47
+ ) return;
48
+
49
+ // add place id
50
+ if (withPlace
51
+ && key === 'place'
52
+ && value?.place_id
53
+ ) return queryParams.push(`place_id=${value?.place_id}`);
46
54
 
47
55
  // Don't include branch_id if a search term has been entered
48
56
  if (key === 'branch_id' && search.isQuerySearch) return;
@@ -58,7 +58,7 @@ const englishRates = (
58
58
  totalRate = rate1 + rate2 + rate3 + rate4 + rate5;
59
59
 
60
60
  // Apply additional rate for non-UK residents only if applicable
61
- if (!ukResident && additionalProperty) {
61
+ if (!ukResident) {
62
62
  totalRate += price * 0.02; // Non-UK resident surcharge
63
63
  }
64
64
  }
@@ -10,50 +10,50 @@ const welshRates = (price, additionalProperty, ukResident) => {
10
10
 
11
11
  if (additionalProperty) {
12
12
  // Rate 1
13
- if (price > 180000) rate1 = 180000 * 0.04;
13
+ if (price > 180000) rate1 = 180000 * 0.05;
14
14
  if (price <= 180000) {
15
- rate1 = price * 0.04;
15
+ rate1 = price * 0.05;
16
16
  }
17
17
 
18
18
  // Rate 2
19
19
  if (price - 180000 > 0) {
20
20
  if ((price - 180000) > (250000 - 180000)) {
21
- rate2 = (250000 - 180000) * 0.075;
21
+ rate2 = (250000 - 180000) * 0.085;
22
22
  } else {
23
- rate2 = (price - 180000) * 0.075;
23
+ rate2 = (price - 180000) * 0.085;
24
24
  }
25
25
  }
26
26
 
27
27
  // Rate 3
28
28
  if (price - 250000 > 0) {
29
29
  if ((price - 250000) > (400000 - 250000)) {
30
- rate3 = (400000 - 250000) * 0.09;
30
+ rate3 = (400000 - 250000) * 0.10;
31
31
  } else {
32
- rate3 = (price - 250000) * 0.09;
32
+ rate3 = (price - 250000) * 0.10;
33
33
  }
34
34
  }
35
35
 
36
36
  // Rate 4
37
37
  if (price - 400000 > 0) {
38
38
  if ((price - 400000) > (750000 - 400000)) {
39
- rate4 = (750000 - 400000) * 0.115;
39
+ rate4 = (750000 - 400000) * 0.125;
40
40
  } else {
41
- rate4 = (price - 400000) * 0.115;
41
+ rate4 = (price - 400000) * 0.125;
42
42
  }
43
43
  }
44
44
 
45
45
  // Rate 5
46
46
  if (price - 750000 > 0) {
47
47
  if ((price - 750000) > (1500000 - 750000)) {
48
- rate5 = (1500000 - 750000) * 0.14;
48
+ rate5 = (1500000 - 750000) * 0.15;
49
49
  } else {
50
- rate5 = (price - 750000) * 0.14;
50
+ rate5 = (price - 750000) * 0.15;
51
51
  }
52
52
  }
53
53
 
54
54
  // Rate 6
55
55
  if (price - 1500000 > 0) {
56
- rate6 = (price - 1500000) * 0.160;
56
+ rate6 = (price - 1500000) * 0.17;
57
57
  }
58
58
  }
59
59