homeflowjs 0.10.3 → 0.10.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "JavaScript toolkit for Homeflow themes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,7 @@ import base64 from '../../utils/base64';
5
5
  import store from '../../store';
6
6
  import { buildQueryString } from '../../search/property-search/property-search';
7
7
  import { setPlace, setSearchField } from '../../actions/search.actions';
8
- import { setProperties, setSelectedMarker } from '../../actions/properties.actions';
8
+ import { setProperties, setSelectedMarker, setPagination } from '../../actions/properties.actions';
9
9
  import { setLoading } from '../../actions/app.actions';
10
10
 
11
11
  const element = function (X, Y) {
@@ -560,6 +560,7 @@ export default class DraggableMap {
560
560
  .then((response) => response.json())
561
561
  .then((json) => {
562
562
  store.dispatch(setProperties(json.properties));
563
+ store.dispatch(setPagination(json.pagination))
563
564
  // TODO: implement user history
564
565
  // Ctesius.getUserHistoryCollection().addSearch(s);
565
566
  Homeflow.kickEvent('clear_search_box');
@@ -9,6 +9,7 @@ const INITIAL_STATE = {
9
9
  isQuerySearch: true,
10
10
  suggestions: [],
11
11
  tags: [],
12
+ poly: '',
12
13
  },
13
14
  initialSearch: {}, // original search when the page first loads
14
15
  savedSearches: [],
@@ -57,7 +58,7 @@ const searchReducer = (state = INITIAL_STATE, action) => {
57
58
  ...state.currentSearch,
58
59
  ...action.payload,
59
60
  // delete poly if user enters new search query
60
- poly: action.payload.q ? null : state.currentSearch.poly,
61
+ ...(action.payload.q) && { poly: null },
61
62
  },
62
63
  };
63
64
  case SearchActionTypes.ADD_TAG: {
@@ -20,36 +20,50 @@ const NormalSelect = ({
20
20
  placeholder,
21
21
  bedOptionText,
22
22
  ...otherProps
23
- }) => (
24
- <select
25
- value={value}
26
- onChange={e => setSearchField({
27
- [e.target.name]: e.target.value ? parseInt(e.target.value) : null
28
- })}
29
- name={`${type}Beds`}
30
- {...otherProps}
31
- >
32
- <option
33
- value=""
34
- title={`${type} beds`}
35
- className={optionClass}
23
+ }) => {
24
+ const isNumberArray = (array) => array.every((item) => typeof item === 'number');
25
+
26
+ return (
27
+ <select
28
+ value={value}
29
+ onChange={(e) => setSearchField({
30
+ [e.target.name]: e.target.value ? parseInt(e.target.value) : null,
31
+ })}
32
+ name={`${type}Beds`}
33
+ {...otherProps}
36
34
  >
37
- {placeholder || `${capitalizeFirstLetter(type)}. bedrooms`}
38
- </option>
39
- {bedValues.map((_, i) => (
40
35
  <option
41
- key={i}
42
- value={i + 1}
43
- title={`${i + 1} Bed`}
36
+ value=""
37
+ title={`${type} beds`}
44
38
  className={optionClass}
45
39
  >
46
- {i + 1}
47
- {' '}
48
- {bedOptionText}
40
+ {placeholder || `${capitalizeFirstLetter(type)}. bedrooms`}
49
41
  </option>
50
- ))}
51
- </select>
52
- );
42
+ {bedValues.map((item) => (
43
+ isNumberArray(bedValues) ? (
44
+ <option
45
+ key={item}
46
+ value={item}
47
+ title={`${item} Bed`}
48
+ className={optionClass}
49
+ >
50
+ {item}
51
+ {' '}
52
+ {bedOptionText}
53
+ </option>
54
+ ) : (
55
+ <option
56
+ key={item.label}
57
+ value={item.value}
58
+ title={`${item.value} Bed`}
59
+ className={optionClass}
60
+ >
61
+ {item.label}
62
+ </option>
63
+ )))}
64
+ </select>
65
+ );
66
+ };
53
67
 
54
68
  const ReactSelect = (props) => {
55
69
  const {
@@ -63,7 +77,7 @@ const ReactSelect = (props) => {
63
77
  bedOptionText,
64
78
  } = props;
65
79
 
66
- const bedOptions = bedValues.map(bedValue => (
80
+ const bedOptions = bedValues.map((bedValue) => (
67
81
  { value: bedValue, label: `${bedValue} ${bedOptionText}` }
68
82
  ));
69
83
 
@@ -76,17 +90,17 @@ const ReactSelect = (props) => {
76
90
  options={bedOptions}
77
91
  styles={styles}
78
92
  placeholder={placeholder || `${capitalizeFirstLetter(type)} bedrooms`}
79
- value={bedOptions.find(option => option.value === value)}
93
+ value={bedOptions.find((option) => option.value === value)}
80
94
  setValue={() => value}
81
95
  isSearchable={false}
82
96
  onChange={({ value }) => {
83
97
  setSearchField({
84
- [`${type}Beds`]: value ? parseInt(value) : null
85
- })}
86
- }
98
+ [`${type}Beds`]: value ? parseInt(value) : null,
99
+ });
100
+ }}
87
101
  />
88
- )
89
- }
102
+ );
103
+ };
90
104
 
91
105
  const BedroomsSelect = (props) => {
92
106
  const {
@@ -104,18 +118,18 @@ const BedroomsSelect = (props) => {
104
118
  let filteredBedValues = bedValues;
105
119
 
106
120
  if (type === 'max' && minBeds && !allowUnderOver) {
107
- filteredBedValues = bedValues.filter(bedValue => bedValue >= minBeds);
121
+ filteredBedValues = bedValues.filter((bedValue) => (bedValue.value || bedValue) >= minBeds);
108
122
  }
109
123
 
110
124
  if (type === 'min' && maxBeds && !allowUnderOver) {
111
- filteredBedValues = bedValues.filter(bedValue => bedValue <= maxBeds);
125
+ filteredBedValues = bedValues.filter((bedValue) => (bedValue.value || bedValue) <= maxBeds);
112
126
  }
113
127
 
114
128
  if (reactSelect) {
115
- return <ReactSelect type={type} value={value || ''} bedValues={filteredBedValues} {...otherProps} />;
129
+ return <ReactSelect type={type} value={value || value === 0 ? value : ''} bedValues={filteredBedValues} {...otherProps} />;
116
130
  }
117
131
 
118
- return <NormalSelect type={type} value={value || ''} bedValues={filteredBedValues} {...otherProps} />;
132
+ return <NormalSelect type={type} value={value || value === 0 ? value : ''} bedValues={filteredBedValues} {...otherProps} />;
119
133
  };
120
134
 
121
135
  BedroomsSelect.propTypes = {
@@ -17,6 +17,8 @@ const fragmentize = (key, value) => {
17
17
  return `${pattern[0] ? pattern[0] : ''}${value}${pattern[1] ? pattern[1] : ''}`;
18
18
  };
19
19
 
20
+ const minOrMaxBedZero = (key, value) => (key === 'minBeds' || key === 'maxBeds') && value === 0;
21
+
20
22
  export const buildQueryString = (search) => {
21
23
  const queryParams = [];
22
24
  const fragmentParams = [];
@@ -24,7 +26,7 @@ export const buildQueryString = (search) => {
24
26
  Object.keys(search).forEach((key) => {
25
27
  const value = search[key];
26
28
 
27
- if (value === 0 && key === 'maxBeds') return fragmentParams.push(fragmentize(key, value));
29
+ if (minOrMaxBedZero(key, value)) return fragmentParams.push(fragmentize(key, value));
28
30
 
29
31
  if (!value) return;
30
32