homeflowjs 1.0.59 → 1.0.61

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/hooks/index.js CHANGED
@@ -7,9 +7,11 @@ import useLoadBranches from './use-load-branches';
7
7
  import useLoadPreviousProperties from './use-load-previous-properties';
8
8
  import useRecaptcha from './use-recaptcha';
9
9
  import useScrollTo from './use-scroll-to.hook';
10
+ import useSearchFromFragment from './use-search-from-fragment';
10
11
 
11
12
  export {
12
13
  useDefaultSort,
14
+ useSearchFromFragment,
13
15
  useGeolocate,
14
16
  useOutsideClick,
15
17
  useOnScreen,
@@ -0,0 +1,53 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import 'regenerator-runtime/runtime';
3
+
4
+ const useSearchFromFragment = ({
5
+ fragment,
6
+ channel = 'sales',
7
+ count = 6, // page size
8
+ placeId,
9
+ }) => {
10
+ const [foundProperties, setFoundProperties] = useState(null);
11
+ const [loading, setLoading] = useState(true);
12
+ const [error, setError] = useState(null);
13
+
14
+ const searchUrl = useCallback(() => {
15
+ let buildUrl = `/search.ljson?channel=${channel}`;
16
+
17
+ if (placeId) buildUrl = buildUrl += `&place_id=${placeId}`
18
+ if (count) buildUrl = buildUrl += `&count=${count}`
19
+
20
+ buildUrl += `&fragment=${fragment}`
21
+
22
+ return buildUrl;
23
+ }, []);
24
+
25
+ useEffect(() => {
26
+ const findProperties = async () => {
27
+ try {
28
+ const searchResponse = await fetch(searchUrl());
29
+ if (!searchResponse.ok) {
30
+ throw new Error('Failed to fetch properties data');
31
+ }
32
+ const { properties } = await searchResponse.json();
33
+ setFoundProperties(properties);
34
+ } catch (error) {
35
+ setError(error);
36
+ console.error(error);
37
+ } finally {
38
+ setLoading(false);
39
+ }
40
+ };
41
+
42
+
43
+ if (foundProperties === null) findProperties();
44
+ }, []);
45
+
46
+ return {
47
+ foundProperties,
48
+ error,
49
+ loading,
50
+ };
51
+ }
52
+
53
+ export default useSearchFromFragment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homeflowjs",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -8,12 +8,6 @@ import { addSearchToLocalStorage } from '../../app/user-history';
8
8
  import { Link } from 'react-router-dom';
9
9
 
10
10
  const LoadMoreButton = (props) => {
11
- const dispatch = useDispatch();
12
- const currentSearch = useSelector((state) => state.search?.currentSearch);
13
- const pagination = useSelector((state) => state.properties?.pagination);
14
-
15
- if (!pagination.has_next_page) return null;
16
-
17
11
  const {
18
12
  isRouterLink,
19
13
  children,
@@ -21,21 +15,38 @@ const LoadMoreButton = (props) => {
21
15
  isHidden,
22
16
  ...otherProps
23
17
  } = props;
24
-
18
+ const dispatch = useDispatch();
19
+ const pagination = useSelector((state) => state.properties?.pagination);
20
+ const currentSearch = useSelector((state) => state.search?.currentSearch);
25
21
  const [loading, setLoading] = useState(false);
26
22
  const [targetURL, setTargetURL] = useState(window.location.href);
27
23
 
28
- // Updating the url for the link to follow the next page,
29
- // replacing the page with current page with the next page value
30
- // to avoid duplicated pages in url pattern such as page-2/page-3.
31
- const updatePageLink = (url) => {
24
+ /**
25
+ * There might be a slight delay between the pagination and the properties
26
+ * update in the redux store and the execution of the dispatch.then()
27
+ * that can affect the page number link. This is hacks that possible delay.
28
+ */
29
+ const updateLinkUrlWithDelay = () => setTimeout(
30
+ () => setTargetURL(window.location.href), 250,
31
+ );
32
+
33
+ /**
34
+ * Updating the url for the link to follow the next page,
35
+ * replacing the page with current page with the next page value
36
+ * to avoid duplicated pages in url pattern such as page-2/page-3.
37
+ */
38
+ const updatePageLink = (pageUrl) => {
39
+ const url = pageUrl.replace('#/', '');
40
+
32
41
  if (url.includes('page-')) {
33
42
  return url.replace(/page-\d+/, `page-${pagination.current_page + 1}`);
34
43
  } else {
35
44
  // Fix for the page-2 when the url does not have a value for page-1
36
- return url + (url.endsWith('/') ? '' : '/') + `page-${pagination.current_page + 1}`;
45
+ return url
46
+ + (url.endsWith('/') ? '' : '/')
47
+ + (pagination.has_next_page ? `page-${pagination.current_page + 1}` : '');
37
48
  }
38
- }
49
+ };
39
50
 
40
51
  const handleClick = (e) => {
41
52
  e.preventDefault();
@@ -49,14 +60,20 @@ const LoadMoreButton = (props) => {
49
60
 
50
61
  setLoading(false);
51
62
  addSearchToLocalStorage(searchToLocal);
52
- setTargetURL(window.location.href);
63
+ updateLinkUrlWithDelay();
53
64
  return false;
54
65
  });
55
66
  return false;
56
67
  }
57
68
 
58
- {/* Load More Button component uses Link from react-router-dom to avoid navigating pages for themes using the component inside a react router wrapper. */}
69
+ /*
70
+ * Load More Button component uses Link from react-router-dom to
71
+ * avoid navigating pages for themes using the component inside
72
+ * a react router wrapper.
73
+ */
59
74
  const RouterLinkComponent = () => {
75
+ if (!pagination.has_next_page) return null;
76
+
60
77
  return (
61
78
  <Link
62
79
  onClick={(e) => handleClick(e)}
@@ -69,6 +86,8 @@ const LoadMoreButton = (props) => {
69
86
  }
70
87
 
71
88
  const LinkComponent = () => {
89
+ if (!pagination.has_next_page) return null;
90
+
72
91
  return (
73
92
  <a
74
93
  onClick={(e) => handleClick(e)}
@@ -80,8 +99,14 @@ const LoadMoreButton = (props) => {
80
99
  )
81
100
  };
82
101
 
83
- {/* Hidden link for themes using InfiniteScroll: allows Googlebot to discover the Next page link for indexing, while users trigger infinite scroll without actual navigation. */}
102
+ /*
103
+ * Hidden link for themes using InfiniteScroll: allows Googlebot to discover
104
+ * the Next page link for indexing, while users trigger infinite scroll
105
+ * without actual navigation.
106
+ */
84
107
  const HiddenLinkComponent = () => {
108
+ if (!pagination.has_next_page) return null;
109
+
85
110
  return (
86
111
  <a
87
112
  style={{ display: 'none' }}