homeflowjs 1.0.9 → 1.0.11
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.
@@ -5,6 +5,17 @@ import { setSearch } from './search.actions';
|
|
5
5
|
import { setLoading } from './app.actions';
|
6
6
|
import { JSON_to_URLEncoded, getOfflineSavedProperties } from '../utils';
|
7
7
|
|
8
|
+
/*
|
9
|
+
* we need to keep track of all the pages previously loaded
|
10
|
+
* to avoid duplications when running loadNext
|
11
|
+
*/
|
12
|
+
const loadedPages = new Array();
|
13
|
+
|
14
|
+
const addToLoadedPages = (pageNumber) => {
|
15
|
+
if (!loadedPages?.includes(pageNumber)) loadedPages.push(pageNumber);
|
16
|
+
return null;
|
17
|
+
};
|
18
|
+
|
8
19
|
export const setPropertyLinks = (payload) => ({
|
9
20
|
type: PropertiesActionTypes.SET_PROPERTY_LINKS,
|
10
21
|
payload,
|
@@ -167,8 +178,14 @@ export const loadNext = () => (dispatch, getState) => {
|
|
167
178
|
const nextPageSearch = { ...getState().search.initialSearch };
|
168
179
|
const currentPageNumber = getState()?.properties?.pagination?.current_page;
|
169
180
|
|
181
|
+
addToLoadedPages(currentPageNumber);
|
182
|
+
|
183
|
+
const sortedLoadedPages = loadedPages?.sort((a, b) => a - b) || null;
|
184
|
+
const highestPageLoaded = sortedLoadedPages ? sortedLoadedPages[sortedLoadedPages?.length - 1] : null;
|
185
|
+
|
170
186
|
if (nextPageSearch?.place?.place_id) nextPageSearch.placeId = nextPageSearch?.place?.place_id;
|
171
|
-
|
187
|
+
|
188
|
+
nextPageSearch.page = highestPageLoaded ? highestPageLoaded + 1 : 2;
|
172
189
|
|
173
190
|
// conduct search ljson
|
174
191
|
return fetch(`/search.ljson?${buildQueryString(nextPageSearch)}`)
|
@@ -190,6 +207,7 @@ export const loadNext = () => (dispatch, getState) => {
|
|
190
207
|
dispatch(setSearch(nextPageSearch));
|
191
208
|
dispatch(setProperties(newProperties));
|
192
209
|
dispatch(setPagination(json.pagination));
|
210
|
+
addToLoadedPages(json.pagination.current_page);
|
193
211
|
dispatch(setLoading({ properties: false }));
|
194
212
|
}
|
195
213
|
});
|
@@ -200,7 +218,12 @@ export const loadPage = (payload) => (dispatch, getState) => {
|
|
200
218
|
// set page on search to page + 1
|
201
219
|
let newProperties = [...getState().properties.properties];
|
202
220
|
const newSearch = { ...getState().search.currentSearch };
|
221
|
+
const currentPageNumber = getState()?.properties?.pagination?.current_page;
|
222
|
+
|
223
|
+
addToLoadedPages(currentPageNumber);
|
224
|
+
|
203
225
|
newSearch.page = payload;
|
226
|
+
|
204
227
|
// conduct search ljson
|
205
228
|
return fetch(`/search.ljson?${buildQueryString(newSearch)}`)
|
206
229
|
.then((response) => response.json())
|
@@ -214,6 +237,7 @@ export const loadPage = (payload) => (dispatch, getState) => {
|
|
214
237
|
dispatch(setSearch(newSearch));
|
215
238
|
dispatch(setProperties(newProperties));
|
216
239
|
dispatch(setPagination(json.pagination));
|
240
|
+
addToLoadedPages(json.pagination.current_page);
|
217
241
|
dispatch(setLoading({ properties: false }));
|
218
242
|
}
|
219
243
|
});
|
package/package.json
CHANGED
@@ -109,6 +109,7 @@ class LocationInput extends Component {
|
|
109
109
|
clearButtonClassName,
|
110
110
|
pattern,
|
111
111
|
name,
|
112
|
+
required,
|
112
113
|
} = this.props;
|
113
114
|
|
114
115
|
const inputProps = {
|
@@ -116,6 +117,7 @@ class LocationInput extends Component {
|
|
116
117
|
placeholder,
|
117
118
|
value: q,
|
118
119
|
name,
|
120
|
+
required,
|
119
121
|
onChange: this.onLocationChange,
|
120
122
|
};
|
121
123
|
|
@@ -163,6 +165,7 @@ LocationInput.propTypes = {
|
|
163
165
|
clearButton: PropTypes.bool,
|
164
166
|
clearButtonClassName: PropTypes.string,
|
165
167
|
name: PropTypes.string,
|
168
|
+
required: PropTypes.bool,
|
166
169
|
};
|
167
170
|
|
168
171
|
LocationInput.defaultProps = {
|
@@ -174,6 +177,7 @@ LocationInput.defaultProps = {
|
|
174
177
|
clearButton: false,
|
175
178
|
clearButtonClassName: '',
|
176
179
|
name: 'Location search',
|
180
|
+
required: false,
|
177
181
|
};
|
178
182
|
|
179
183
|
const mapStateToProps = (state) => ({
|