homeflowjs 1.0.35 → 1.0.37
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,38 +1,35 @@
|
|
1
1
|
export const addSearchToLocalStorage = (search) => {
|
2
|
-
//
|
3
|
-
|
4
|
-
|
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;
|
2
|
+
// Get search history from local storage
|
3
|
+
let searchHistory = localStorage.getItem('searchHistory');
|
4
|
+
searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
|
10
5
|
|
11
6
|
// Make a new instance of the search object without the page number.
|
12
|
-
const
|
7
|
+
const searchWithoutPageNumber = { ...search, page: null };
|
13
8
|
|
14
9
|
// Make a new instance of the last search object without the page number.
|
15
|
-
const
|
10
|
+
const lastSearchWithoutPageNumber = { ...searchHistory[0], page: null };
|
16
11
|
|
17
12
|
/**
|
18
|
-
* If the
|
13
|
+
* If the searchWithoutPageNumber and lastSearchWithoutPageNumber match,
|
19
14
|
* just update the the last search in local storage to have the search's page number if
|
20
15
|
* it has one.
|
21
16
|
*/
|
22
|
-
if ((
|
23
|
-
searchHistory[0].page
|
24
|
-
|
17
|
+
if ((JSON.stringify(searchWithoutPageNumber) === JSON.stringify(lastSearchWithoutPageNumber)) && search?.page) {
|
18
|
+
const lastSearchWithUpdatedPageNumber = { ...searchHistory[0], page: search.page };
|
19
|
+
searchHistory.shift();
|
20
|
+
searchHistory.unshift(lastSearchWithUpdatedPageNumber);
|
21
|
+
localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
|
25
22
|
}
|
26
23
|
|
27
24
|
/**
|
28
25
|
* If the search and last search without page numbers don't match add
|
29
26
|
* the search to local storage.
|
30
27
|
*/
|
31
|
-
if (
|
32
|
-
// Add
|
33
|
-
|
34
|
-
|
35
|
-
));
|
28
|
+
if ((JSON.stringify(searchWithoutPageNumber) !== JSON.stringify(lastSearchWithoutPageNumber))) {
|
29
|
+
// Add search to the front of the array ...
|
30
|
+
searchHistory.unshift(search);
|
31
|
+
// ... and ensure only 10 most recent searches in history.
|
32
|
+
localStorage.setItem('searchHistory', JSON.stringify(searchHistory.slice(0, 10)));
|
36
33
|
}
|
37
34
|
};
|
38
35
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "homeflowjs",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.37",
|
4
4
|
"sideEffects": [
|
5
5
|
"modal/**/*",
|
6
6
|
"user/default-profile/**/*",
|
@@ -8,7 +8,8 @@
|
|
8
8
|
"properties/properties-map/**/*",
|
9
9
|
"properties/property-map/**/*",
|
10
10
|
"properties/property-streetview/**/*",
|
11
|
-
"properties/stamp-duty-calculator/**/*"
|
11
|
+
"properties/stamp-duty-calculator/**/*",
|
12
|
+
"properties/property-results-pagination/**/*"
|
12
13
|
],
|
13
14
|
"description": "JavaScript toolkit for Homeflow themes",
|
14
15
|
"main": "index.js",
|
@@ -15,16 +15,12 @@ const BackToSearchButton = ({ children, ...otherProps }) => {
|
|
15
15
|
const property = Homeflow.get('property');
|
16
16
|
const currentPropertyID = property?.propertyId || property?.property_id;
|
17
17
|
|
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
|
-
}
|
18
|
+
if (currentPropertyID === secondToLastSearch?.clickedProperty) validSearch = secondToLastSearch;
|
26
19
|
}
|
27
20
|
|
21
|
+
// delete the 'place' so we don't get [object Object] in URL if place is found in object.
|
22
|
+
if (validSearch?.place) delete validSearch.place;
|
23
|
+
|
28
24
|
const href = `/search?${buildQueryString(validSearch)}`;
|
29
25
|
|
30
26
|
return (
|
@@ -47,6 +47,18 @@ export default function PropertyResultsPagination({
|
|
47
47
|
* currentPage = 3;
|
48
48
|
* pageCount = 100;
|
49
49
|
*'Should output: [ 3, 4, 5, 6]'
|
50
|
+
*
|
51
|
+
* currentPage = 100;
|
52
|
+
* pageCount = 100;
|
53
|
+
* 'Should output: [ 96, 97, 98, 99]'
|
54
|
+
*
|
55
|
+
* currentPage = 3;
|
56
|
+
* pageCount = 3;
|
57
|
+
* 'Should output: [ 2 ]'
|
58
|
+
*
|
59
|
+
* currentPage = 1;
|
60
|
+
* pageCount = 3;
|
61
|
+
* 'Should output: [ 2 ]'
|
50
62
|
* @returns {number[]} An array of page numbers for pagination.
|
51
63
|
*/
|
52
64
|
const getPaginationIncrements = () => {
|
@@ -59,10 +71,18 @@ export default function PropertyResultsPagination({
|
|
59
71
|
startIncrement++;
|
60
72
|
endIncrement++;
|
61
73
|
}
|
74
|
+
|
62
75
|
if (endIncrement >= pageCount) {
|
63
76
|
endIncrement = pageCount;
|
64
77
|
}
|
65
78
|
|
79
|
+
// If on the final page
|
80
|
+
if (currentPage === pageCount) {
|
81
|
+
startIncrement = pageCount >= paginationIncrements
|
82
|
+
? currentPage - paginationIncrements : currentPage - (paginationIncrements - currentPage);
|
83
|
+
endIncrement = currentPage;
|
84
|
+
}
|
85
|
+
|
66
86
|
for (let i = startIncrement; i < endIncrement; i++) {
|
67
87
|
pagination.push(i);
|
68
88
|
}
|
@@ -41,10 +41,9 @@ 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')
|
44
45
|
|| (key === 'poly' && search.isQuerySearch)) return;
|
45
46
|
|
46
|
-
if (key === 'place') return queryParams.push(`place_id=${value?.place_id}`);
|
47
|
-
|
48
47
|
// Don't include branch_id if a search term has been entered
|
49
48
|
if (key === 'branch_id' && search.isQuerySearch) return;
|
50
49
|
|