homeflowjs 0.13.25 → 0.13.27
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/actions/branches.actions.js +5 -0
- package/actions/branches.types.js +1 -0
- package/app/hf-initialize.jsx +9 -1
- package/hooks/index.js +2 -0
- package/hooks/use-load-branches.js +36 -0
- package/hooks/use-load-branches.spec.js +31 -0
- package/package.json +1 -1
- package/reducers/branches.reducer.js +6 -0
- package/reducers/test-provider.jsx +7 -0
- package/search/location-input/location-input.component.jsx +4 -0
package/app/hf-initialize.jsx
CHANGED
@@ -14,8 +14,11 @@ import { fetchUser } from '../actions/user.actions';
|
|
14
14
|
import {
|
15
15
|
setProperties, setPagination, setProperty, setPropertyLinksAsync,
|
16
16
|
} from '../actions/properties.actions';
|
17
|
-
import {
|
17
|
+
import {
|
18
|
+
setSearch, setInitialSearch, setSearchField, setPlace,
|
19
|
+
} from '../actions/search.actions';
|
18
20
|
import { setArticles } from '../actions/articles.actions';
|
21
|
+
import { setBranches, setBranchesPagination } from '../actions/branches.actions';
|
19
22
|
import parseFragment from '../search/property-search/parse-fragment';
|
20
23
|
import { isEmpty } from '../utils';
|
21
24
|
|
@@ -105,6 +108,11 @@ const hfInitialize = () => {
|
|
105
108
|
store.dispatch(setArticles(Homeflow.get('articles')));
|
106
109
|
}
|
107
110
|
|
111
|
+
if (pageRoute === 'branches#index') {
|
112
|
+
store.dispatch(setBranches(Homeflow.get('branches')));
|
113
|
+
store.dispatch(setBranchesPagination(Homeflow.get('branchesPagination')));
|
114
|
+
}
|
115
|
+
|
108
116
|
// all property results routes
|
109
117
|
if (pageRoute === 'properties#index'
|
110
118
|
|| pageRoute === 'counties#show'
|
package/hooks/index.js
CHANGED
@@ -3,6 +3,7 @@ import useGeolocate from './use-geolocate';
|
|
3
3
|
import useOutsideClick from './use-outside-click';
|
4
4
|
import { useOnScreen } from './use-on-screen';
|
5
5
|
import usePropertyInfiniteScroll from './use-property-inifinite-scroll';
|
6
|
+
import useLoadBranches from './use-load-branches';
|
6
7
|
|
7
8
|
export {
|
8
9
|
useDefaultSort,
|
@@ -10,4 +11,5 @@ export {
|
|
10
11
|
useOutsideClick,
|
11
12
|
useOnScreen,
|
12
13
|
usePropertyInfiniteScroll,
|
14
|
+
useLoadBranches,
|
13
15
|
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* This hook renders a handler to load the next page of branch results
|
3
|
+
*
|
4
|
+
* The loadBranches handler takes in an optional query string to pass to the branch search
|
5
|
+
* which loads branches with a particular filter
|
6
|
+
*
|
7
|
+
* e.g.
|
8
|
+
* loadBranches('&channel=sales')
|
9
|
+
*/
|
10
|
+
import { useState } from 'react';
|
11
|
+
import { useSelector, useDispatch } from 'react-redux';
|
12
|
+
import { setBranches, setBranchesPagination } from '../actions/branches.actions';
|
13
|
+
|
14
|
+
const useLoadBranches = () => {
|
15
|
+
const [loading, setLoading] = useState(false);
|
16
|
+
const branches = useSelector((state) => state.branches.branches);
|
17
|
+
const pagination = useSelector((state) => state.branches.pagination);
|
18
|
+
const dispatch = useDispatch();
|
19
|
+
|
20
|
+
const loadBranches = (query = '') => {
|
21
|
+
if (pagination.hasNextPage) {
|
22
|
+
setLoading(true);
|
23
|
+
fetch(`/branches.ljson?page=${pagination.currentPage + 1}${query}`)
|
24
|
+
.then((response) => response.json())
|
25
|
+
.then((json) => {
|
26
|
+
dispatch(setBranchesPagination(json.pagination));
|
27
|
+
dispatch(setBranches([...branches, ...json.branches]));
|
28
|
+
setLoading(false);
|
29
|
+
});
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
33
|
+
return { loadBranches, loadingBranches: loading, hasNextPage: pagination.hasNextPage };
|
34
|
+
};
|
35
|
+
|
36
|
+
export default useLoadBranches;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
2
|
+
import * as redux from 'react-redux';
|
3
|
+
import useLoadBranches from './use-load-branches';
|
4
|
+
import store from '../store';
|
5
|
+
import { TestProvider } from '../reducers/test-provider';
|
6
|
+
import { setBranchesPagination } from '../actions/branches.actions';
|
7
|
+
|
8
|
+
const INITIAL_BRANCHES_PAGINATION = {
|
9
|
+
currentPage: 1,
|
10
|
+
hasPrevPage: false,
|
11
|
+
totalCount: 100,
|
12
|
+
hasNextPage: true,
|
13
|
+
};
|
14
|
+
|
15
|
+
beforeAll(() => {
|
16
|
+
act(() => {
|
17
|
+
store.dispatch(setBranchesPagination(INITIAL_BRANCHES_PAGINATION))
|
18
|
+
});
|
19
|
+
});
|
20
|
+
|
21
|
+
describe('useLoadBranches', () => {
|
22
|
+
const renderedHook = renderHook(useLoadBranches, { wrapper: TestProvider });
|
23
|
+
|
24
|
+
it('renders a loadBranches function, loadingBranches boolean and hasNextPage boolean', () => {
|
25
|
+
const { loadBranches, loadingBranches, hasNextPage } = renderedHook.result.current;
|
26
|
+
|
27
|
+
expect(typeof loadBranches).toBe('function');
|
28
|
+
expect(typeof loadingBranches).toBe('boolean');
|
29
|
+
expect(typeof hasNextPage).toBe('boolean');
|
30
|
+
});
|
31
|
+
});
|
package/package.json
CHANGED
@@ -3,6 +3,7 @@ import BranchesActionTypes from '../actions/branches.types';
|
|
3
3
|
const INITIAL_STATE = {
|
4
4
|
branches: [],
|
5
5
|
branchesSearch: '',
|
6
|
+
pagination: {},
|
6
7
|
};
|
7
8
|
|
8
9
|
const branchesReducer = (state = INITIAL_STATE, action) => {
|
@@ -17,6 +18,11 @@ const branchesReducer = (state = INITIAL_STATE, action) => {
|
|
17
18
|
...state,
|
18
19
|
branchesSearch: action.payload,
|
19
20
|
};
|
21
|
+
case BranchesActionTypes.SET_BRANCHES_PAGINATION:
|
22
|
+
return {
|
23
|
+
...state,
|
24
|
+
pagination: action.payload,
|
25
|
+
};
|
20
26
|
default: return state;
|
21
27
|
}
|
22
28
|
};
|
@@ -107,9 +107,11 @@ class LocationInput extends Component {
|
|
107
107
|
placeholder,
|
108
108
|
clearButton,
|
109
109
|
clearButtonClassName,
|
110
|
+
pattern,
|
110
111
|
} = this.props;
|
111
112
|
|
112
113
|
const inputProps = {
|
114
|
+
pattern,
|
113
115
|
placeholder,
|
114
116
|
value: q,
|
115
117
|
onChange: this.onLocationChange,
|
@@ -153,6 +155,7 @@ LocationInput.propTypes = {
|
|
153
155
|
setSuggestions: PropTypes.func.isRequired,
|
154
156
|
setSearchField: PropTypes.func.isRequired,
|
155
157
|
placeholder: PropTypes.string,
|
158
|
+
pattern: PropTypes.string,
|
156
159
|
className: PropTypes.string,
|
157
160
|
search: PropTypes.object.isRequired,
|
158
161
|
searchOnSelection: PropTypes.bool,
|
@@ -162,6 +165,7 @@ LocationInput.propTypes = {
|
|
162
165
|
|
163
166
|
LocationInput.defaultProps = {
|
164
167
|
placeholder: 'Enter a location...',
|
168
|
+
pattern: '',
|
165
169
|
className: '',
|
166
170
|
suggestions: [],
|
167
171
|
searchOnSelection: false,
|