homeflowjs 0.13.0 → 0.13.1
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.
@@ -10,38 +10,34 @@ export const setPropertyLinks = (payload) => ({
|
|
10
10
|
});
|
11
11
|
|
12
12
|
// TODO: This method is long and repetitive. Refactor.
|
13
|
-
export const setPropertyLinksAsync = () => (dispatch) => {
|
13
|
+
export const setPropertyLinksAsync = (page = null) => (dispatch) => {
|
14
14
|
const searchHistory = localStorage.getItem('searchHistory');
|
15
15
|
if (!searchHistory) return null;
|
16
16
|
|
17
17
|
const parsedSearchHistory = JSON.parse(searchHistory);
|
18
18
|
if (!Array.isArray(parsedSearchHistory)) return null;
|
19
19
|
|
20
|
-
const
|
21
|
-
(!search.isQuerySearch && search?.q)
|
22
|
-
|| search?.place
|
23
|
-
|| (search.isQuerySearch && search?.placeId)
|
24
|
-
|| (search.isQuerySearch && search?.poly);
|
20
|
+
const lastSearch = parsedSearchHistory[0];
|
25
21
|
|
26
|
-
const
|
27
|
-
if (!filteredSearchHistory?.length) return null;
|
28
|
-
const lastSearch = filteredSearchHistory[0];
|
29
|
-
const { place, ...restOfSearch } = lastSearch;
|
30
|
-
const searchURL = `/search.ljson?${buildQueryString(restOfSearch)}`;
|
22
|
+
const searchURL = `/search.ljson?${buildQueryString(lastSearch)}`;
|
31
23
|
|
32
24
|
const propertyLinks = {
|
33
25
|
next: '',
|
34
26
|
prev: '',
|
27
|
+
nextPage: false,
|
28
|
+
prevPage: false,
|
35
29
|
};
|
36
30
|
|
37
31
|
const getPropertyUrl = (property) => property?.property_url || property?.url;
|
38
32
|
|
39
33
|
fetch(searchURL)
|
40
34
|
.then((response) => response.json())
|
41
|
-
.then(({ properties }) => {
|
35
|
+
.then(({ properties, pagination }) => {
|
42
36
|
if (!properties) return;
|
43
37
|
|
44
38
|
const index = properties.findIndex((prop) => prop.property_id === Homeflow.get('property').property_id);
|
39
|
+
if (index === -1) return;
|
40
|
+
|
45
41
|
// if there is a next and previous property in page, set those
|
46
42
|
if (properties[index + 1] && properties[index - 1]) {
|
47
43
|
propertyLinks.next = getPropertyUrl(properties[index + 1]);
|
@@ -50,60 +46,52 @@ export const setPropertyLinksAsync = () => (dispatch) => {
|
|
50
46
|
return dispatch(setPropertyLinks(propertyLinks));
|
51
47
|
}
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
const nextSearch = {
|
50
|
+
...lastSearch,
|
51
|
+
page: lastSearch.page ? lastSearch.page : 1,
|
52
|
+
};
|
53
|
+
|
54
|
+
// if there is a previous, conduct search for next
|
55
|
+
if (properties[index - 1]) {
|
56
56
|
propertyLinks.prev = getPropertyUrl(properties[index - 1]);
|
57
|
+
if (!pagination.has_next_page) return dispatch(setPropertyLinks(propertyLinks));
|
57
58
|
|
58
|
-
const nextSearch = {
|
59
|
-
...restOfSearch,
|
60
|
-
page: restOfSearch.page ? restOfSearch.page : 1,
|
61
|
-
};
|
62
59
|
nextSearch.page += 1;
|
63
60
|
const nextSearchURL = `/search.ljson?${buildQueryString(nextSearch)}`;
|
64
61
|
fetch(nextSearchURL)
|
65
62
|
.then((response) => response.json())
|
66
63
|
.then(({ properties }) => {
|
67
|
-
if (
|
68
|
-
propertyLinks.next = '';
|
69
|
-
} else {
|
64
|
+
if (properties) {
|
70
65
|
propertyLinks.next = getPropertyUrl(properties[0]);
|
66
|
+
propertyLinks.nextPage = true;
|
71
67
|
}
|
72
68
|
|
73
69
|
return dispatch(setPropertyLinks(propertyLinks));
|
74
70
|
});
|
75
71
|
}
|
76
72
|
|
77
|
-
// if there is
|
78
|
-
|
79
|
-
if (!properties[index - 1] && properties[index + 1]) {
|
73
|
+
// if there is a next, conduct search for previous
|
74
|
+
if (properties[index + 1]) {
|
80
75
|
propertyLinks.next = getPropertyUrl(properties[index + 1]);
|
81
76
|
|
82
|
-
const nextSearch = {
|
83
|
-
...restOfSearch,
|
84
|
-
page: restOfSearch.page ? restOfSearch.page : 1,
|
85
|
-
};
|
86
|
-
|
87
77
|
// if we're on page 1, there can't be a previous
|
88
|
-
if (
|
89
|
-
propertyLinks.prev = '';
|
90
|
-
return dispatch(setPropertyLinks(propertyLinks));
|
91
|
-
}
|
78
|
+
if (!pagination.has_prev_page) return dispatch(setPropertyLinks(propertyLinks));
|
92
79
|
|
93
80
|
nextSearch.page -= 1;
|
94
81
|
const nextSearchURL = `/search.ljson?${buildQueryString(nextSearch)}`;
|
95
82
|
fetch(nextSearchURL)
|
96
83
|
.then((response) => response.json())
|
97
84
|
.then(({ properties }) => {
|
98
|
-
if (
|
99
|
-
propertyLinks.prev = '';
|
100
|
-
} else {
|
85
|
+
if (properties) {
|
101
86
|
propertyLinks.prev = getPropertyUrl(properties[properties.length - 1]);
|
87
|
+
propertyLinks.prevPage = true;
|
102
88
|
}
|
103
89
|
|
104
90
|
return dispatch(setPropertyLinks(propertyLinks));
|
105
91
|
});
|
106
92
|
}
|
93
|
+
|
94
|
+
// There is neither a previous nor a next no need to setPropertyLinks as they are already blank
|
107
95
|
});
|
108
96
|
};
|
109
97
|
|
package/app/user-history.js
CHANGED
@@ -33,3 +33,11 @@ export const addSearchToLocalStorage = (search) => {
|
|
33
33
|
localStorage.setItem('searchHistory', JSON.stringify(searchHistory.slice(0, 10)));
|
34
34
|
}
|
35
35
|
};
|
36
|
+
|
37
|
+
export const updateLastSearchPageInLocalStorage = (change) => {
|
38
|
+
// Get search history from local storage
|
39
|
+
let searchHistory = localStorage.getItem('searchHistory');
|
40
|
+
searchHistory = searchHistory ? JSON.parse(searchHistory) : [];
|
41
|
+
searchHistory[0].page = (searchHistory[0].page ? searchHistory[0].page : 1) + change;
|
42
|
+
localStorage.setItem('searchHistory', JSON.stringify(searchHistory));
|
43
|
+
};
|
package/package.json
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { connect } from 'react-redux';
|
3
3
|
|
4
|
-
|
4
|
+
import { updateLastSearchPageInLocalStorage } from '../../app/user-history';
|
5
|
+
|
6
|
+
const NextPropertyLink = ({ children, className, link, nextPage }) => {
|
5
7
|
if (!link) return null;
|
6
8
|
|
9
|
+
const handleOnClick = () => {
|
10
|
+
if (nextPage) updateLastSearchPageInLocalStorage(1);
|
11
|
+
}
|
7
12
|
return (
|
8
|
-
<a
|
13
|
+
<a
|
14
|
+
className={className}
|
15
|
+
href={link}
|
16
|
+
onClick={handleOnClick}
|
17
|
+
>
|
9
18
|
{children}
|
10
19
|
</a>
|
11
20
|
);
|
@@ -13,63 +22,7 @@ const NextPropertyLink = ({ children, className, link }) => {
|
|
13
22
|
|
14
23
|
const mapStateToProps = (state) => ({
|
15
24
|
link: state.properties.propertyLinks.next,
|
25
|
+
nextPage: state.properties.propertyLinks.nextPage,
|
16
26
|
});
|
17
27
|
|
18
28
|
export default connect(mapStateToProps)(NextPropertyLink);
|
19
|
-
|
20
|
-
// probably best to wait until button is clicked before doing all this:
|
21
|
-
// conduct search using most recent search in local storage
|
22
|
-
// find position of property in search
|
23
|
-
// if there is a NEXT property, go to that
|
24
|
-
// if not, conduct another search for the next page and render first property
|
25
|
-
|
26
|
-
// getNextProperty:()->
|
27
|
-
// return @_next_property if @_next_property
|
28
|
-
// property = @propertyAfter(@currentPropertyId())
|
29
|
-
// if property?
|
30
|
-
// return @_next_property = property
|
31
|
-
// else
|
32
|
-
// if (@mostRecentSearch().get('performed_data').properties.length - 1) == @positionOfPropertyInSearch(@currentPropertyId()) && @mostRecentSearch().get('performed_data').pagination.has_next_page
|
33
|
-
// #get next page
|
34
|
-
// new_search = @mostRecentSearch().clone()
|
35
|
-
// current_page = @mostRecentSearch().get('page')
|
36
|
-
// current_page = 1 unless current_page
|
37
|
-
// new_search.unset('performed_data')
|
38
|
-
// new_search.set('page', ( current_page + 1 ))
|
39
|
-
// new_search.performAsData =>
|
40
|
-
// @addSearch(new_search)
|
41
|
-
// @_next_property = new_search.get('performed_data').properties[0]
|
42
|
-
// @_most_recent = undefined
|
43
|
-
// @getOrCreatNextAndPreviousPropertyView().render()
|
44
|
-
// return null
|
45
|
-
|
46
|
-
// Trying to emulate this in C2:
|
47
|
-
// class Ctesius.Views.NextAndPreviousProperty extends Backbone.View
|
48
|
-
|
49
|
-
// template: ->
|
50
|
-
// Ctesius.Template.load('next_and_previous_property_template')
|
51
|
-
|
52
|
-
// render: ->
|
53
|
-
// if search = @model.mostRecentSearch()
|
54
|
-
// Homeflow.kickEvent('before_next_and_previous_property_view_rendered', search)
|
55
|
-
// prev = @model.getPreviousProperty()
|
56
|
-
// next = @model.getNextProperty()
|
57
|
-
|
58
|
-
// @addPrefetch(prev) if prev
|
59
|
-
// @addPrefetch(next) if next
|
60
|
-
|
61
|
-
// pos = @model.positionOfPropertyInSearch(@model.currentPropertyId()) + search.get('performed_data').pagination.from_record
|
62
|
-
|
63
|
-
// _template = this.template()
|
64
|
-
// t = _template.render({next_property: next, previous_property: prev, position: pos , search: @model.mostRecentSearch()})
|
65
|
-
// for ele in $('[id|="next_and_previous_property_view"]')
|
66
|
-
// $(ele).html(t)
|
67
|
-
// Homeflow.kickEvent('next_and_previous_property_view_rendered', search)
|
68
|
-
|
69
|
-
|
70
|
-
// addPrefetch: (property) ->
|
71
|
-
// @_prefetched = {} unless @_prefetched?
|
72
|
-
// unless @_prefetched[property.property_url]?
|
73
|
-
// @_prefetched[property.property_url] = true
|
74
|
-
// $("<link />", {rel: "prerender", href: property.property_url}).appendTo("head");
|
75
|
-
// $.get(property.property_url)
|
@@ -1,11 +1,20 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { connect } from 'react-redux';
|
3
3
|
|
4
|
-
|
4
|
+
import { updateLastSearchPageInLocalStorage } from '../../app/user-history';
|
5
|
+
|
6
|
+
const PreviousPropertyLink = ({ children, className, link, prevPage }) => {
|
5
7
|
if (!link) return null;
|
6
8
|
|
9
|
+
const handleOnClick = () => {
|
10
|
+
if (prevPage) updateLastSearchPageInLocalStorage(-1);
|
11
|
+
}
|
7
12
|
return (
|
8
|
-
<a
|
13
|
+
<a
|
14
|
+
className={className}
|
15
|
+
href={link}
|
16
|
+
onClick={handleOnClick}
|
17
|
+
>
|
9
18
|
{children}
|
10
19
|
</a>
|
11
20
|
);
|
@@ -13,6 +22,7 @@ const PreviousPropertyLink = ({ children, className, link }) => {
|
|
13
22
|
|
14
23
|
const mapStateToProps = (state) => ({
|
15
24
|
link: state.properties.propertyLinks.prev,
|
25
|
+
prevPage: state.properties.propertyLinks.prevPage,
|
16
26
|
});
|
17
27
|
|
18
28
|
export default connect(mapStateToProps)(PreviousPropertyLink);
|