homeflowjs 1.0.41 → 1.0.42
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/app/user-history.js +69 -10
- package/hooks/use-load-previous-properties.jsx +3 -1
- package/package.json +1 -1
- package/properties/back-to-search-button/back-to-search-button.component.jsx +17 -10
- package/properties/load-more-button/load-more-button.component.jsx +3 -1
- package/properties/properties-display/properties-display.component.jsx +4 -3
- package/search/property-search/property-search.js +13 -5
package/app/user-history.js
CHANGED
@@ -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
|
-
|
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
|
-
|
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)) &&
|
18
|
-
const lastSearchWithUpdatedPageNumber = { ...searchHistory[0], 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(
|
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
|
-
|
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
|
-
|
52
|
-
|
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
|
-
|
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,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 (
|
15
|
-
|
16
|
-
|
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
|
-
|
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
|
-
|
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 (
|
43
|
-
|
44
|
-
|
45
|
-
|
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;
|