homeflowjs 1.0.9 → 1.0.10
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
|
});
|