homeflowjs 1.0.8 → 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
- nextPageSearch.page = currentPageNumber ? currentPageNumber + 1 : 2;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -108,12 +108,14 @@ class LocationInput extends Component {
108
108
  clearButton,
109
109
  clearButtonClassName,
110
110
  pattern,
111
+ name,
111
112
  } = this.props;
112
113
 
113
114
  const inputProps = {
114
115
  pattern,
115
116
  placeholder,
116
117
  value: q,
118
+ name,
117
119
  onChange: this.onLocationChange,
118
120
  };
119
121
 
@@ -131,7 +133,6 @@ class LocationInput extends Component {
131
133
  className,
132
134
  'data-testid': 'location-input',
133
135
  id: 'search-location-input',
134
- name: 'Location search',
135
136
  }}
136
137
  containerProps={{ 'data-testid': 'suggestions' }}
137
138
  theme={autosuggestTheme}
@@ -161,6 +162,7 @@ LocationInput.propTypes = {
161
162
  searchOnSelection: PropTypes.bool,
162
163
  clearButton: PropTypes.bool,
163
164
  clearButtonClassName: PropTypes.string,
165
+ name: PropTypes.string,
164
166
  };
165
167
 
166
168
  LocationInput.defaultProps = {
@@ -171,6 +173,7 @@ LocationInput.defaultProps = {
171
173
  searchOnSelection: false,
172
174
  clearButton: false,
173
175
  clearButtonClassName: '',
176
+ name: 'Location search',
174
177
  };
175
178
 
176
179
  const mapStateToProps = (state) => ({