homeflowjs 1.0.33 → 1.0.35
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
CHANGED
@@ -1,36 +1,38 @@
|
|
1
1
|
export const addSearchToLocalStorage = (search) => {
|
2
|
-
//
|
3
|
-
|
4
|
-
|
2
|
+
// <search> format: {channel: 'sales'}
|
3
|
+
|
4
|
+
// Get search history from local storage.
|
5
|
+
// <searchHistory> format: [{channel: 'sales'}, {channel: 'sales'}]
|
6
|
+
const searchHistory = JSON.parse(localStorage.getItem?.('searchHistory') || null) || [];
|
7
|
+
|
8
|
+
// Get current page number from Homeflow state.
|
9
|
+
const pageNumber = Homeflow.getState?.().properties?.pagination?.current_page;
|
5
10
|
|
6
11
|
// Make a new instance of the search object without the page number.
|
7
|
-
const
|
12
|
+
const searchWithoutPageNumberString = JSON.stringify({ ...search, page: null });
|
8
13
|
|
9
14
|
// Make a new instance of the last search object without the page number.
|
10
|
-
const
|
15
|
+
const lastSearchWithoutPageNumberString = JSON.stringify({ ...searchHistory[0], page: null });
|
11
16
|
|
12
17
|
/**
|
13
|
-
* If the
|
18
|
+
* If the searchWithoutPageNumberString and lastSearchWithoutPageNumberString match,
|
14
19
|
* just update the the last search in local storage to have the search's page number if
|
15
20
|
* it has one.
|
16
21
|
*/
|
17
|
-
if ((
|
18
|
-
|
19
|
-
|
20
|
-
searchHistory.shift();
|
21
|
-
searchHistory.unshift(lastSearchWithUpdatedPageNumber);
|
22
|
-
localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
|
22
|
+
if ((searchWithoutPageNumberString === lastSearchWithoutPageNumberString) && pageNumber) {
|
23
|
+
searchHistory[0].page = pageNumber;
|
24
|
+
localStorage.setItem?.('searchHistory', JSON.stringify(searchHistory));
|
23
25
|
}
|
24
26
|
|
25
27
|
/**
|
26
28
|
* If the search and last search without page numbers don't match add
|
27
|
-
* the search to local storage
|
29
|
+
* the search to local storage.
|
28
30
|
*/
|
29
|
-
if (
|
30
|
-
// Add
|
31
|
-
searchHistory.
|
32
|
-
|
33
|
-
|
31
|
+
if (searchWithoutPageNumberString !== lastSearchWithoutPageNumberString) {
|
32
|
+
// Add <search> to the front of the array and ensure only 10 most recent searches in history.
|
33
|
+
localStorage.setItem('searchHistory', JSON.stringify(
|
34
|
+
[{ ...search }, ...searchHistory].slice(0, 10),
|
35
|
+
));
|
34
36
|
}
|
35
37
|
};
|
36
38
|
|
package/package.json
CHANGED
@@ -9,19 +9,22 @@ const BackToSearchButton = ({ children, ...otherProps }) => {
|
|
9
9
|
const lastSearch = JSON.parse(searchHistory)?.[0];
|
10
10
|
const secondToLastSearch = JSON.parse(searchHistory)?.[1] || null;
|
11
11
|
|
12
|
-
|
13
12
|
let validSearch = lastSearch;
|
14
13
|
|
15
14
|
if (secondToLastSearch) {
|
16
|
-
const property =
|
15
|
+
const property = Homeflow.get('property');
|
17
16
|
const currentPropertyID = property?.propertyId || property?.property_id;
|
18
17
|
|
19
|
-
if (currentPropertyID === secondToLastSearch?.clickedProperty)
|
18
|
+
if (currentPropertyID === secondToLastSearch?.clickedProperty) {
|
19
|
+
if ('expandedPolygon' in secondToLastSearch) {
|
20
|
+
const thirdToLastSearch = JSON.parse(searchHistory)?.[2] || null;
|
21
|
+
validSearch = thirdToLastSearch;
|
22
|
+
} else {
|
23
|
+
validSearch = secondToLastSearch;
|
24
|
+
}
|
25
|
+
}
|
20
26
|
}
|
21
27
|
|
22
|
-
// delete the 'place' so we don't get [object Object] in URL if place is found in object.
|
23
|
-
if (validSearch?.place) delete validSearch.place;
|
24
|
-
|
25
28
|
const href = `/search?${buildQueryString(validSearch)}`;
|
26
29
|
|
27
30
|
return (
|
@@ -41,9 +41,10 @@ export const buildQueryString = (search) => {
|
|
41
41
|
// only include either q or place ID
|
42
42
|
if ((key === 'q' && !search.isQuerySearch)
|
43
43
|
|| (key === 'placeId' && search.isQuerySearch)
|
44
|
-
|| (key === 'place')
|
45
44
|
|| (key === 'poly' && search.isQuerySearch)) return;
|
46
45
|
|
46
|
+
if (key === 'place') return queryParams.push(`place_id=${value?.place_id}`);
|
47
|
+
|
47
48
|
// Don't include branch_id if a search term has been entered
|
48
49
|
if (key === 'branch_id' && search.isQuerySearch) return;
|
49
50
|
|