homeflowjs 1.0.58 → 1.0.60

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.58",
3
+ "version": "1.0.60",
4
4
  "sideEffects": [
5
5
  "modal/**/*",
6
6
  "user/default-profile/**/*",
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Formats a numeric value into a human-readable price string with appropriate suffixes (e.g., "k" for thousand, "m" for million).
3
+ *
4
+ * - Values in the millions are formatted with "m" (e.g., £1.2m).
5
+ * - Values in the thousands are formatted with "k" (e.g., £120k).
6
+ * - Values below £1 are converted to pence (e.g., 0.5 becomes "50p").
7
+ *
8
+ * @param {number} value - The numeric value to format.
9
+ * @returns {string} The formatted price string.
10
+ */
11
+ export const formattedPrice = (value) => {
12
+ const ONE_THOUSAND = 1_000;
13
+ const TEN_THOUSAND = 10_000;
14
+ const ONE_HUNDRED_THOUSAND = 100_000;
15
+ const ONE_MILLION = 1_000_000;
16
+ const TEN_MILLION = 10_000_000;
17
+
18
+ const getReducedNumber = (number, symbol, decimals = 0) => {
19
+ const factor = Math.pow(10, decimals);
20
+ const reducedNumber = number / symbol;
21
+ return Math.round(reducedNumber * factor) / factor;
22
+ };
23
+
24
+ const formatNumber = (price) => {
25
+ if (price >= TEN_MILLION) {
26
+ const reducedNumber = getReducedNumber(price, ONE_MILLION, 2);
27
+ return `£${reducedNumber}m`;
28
+ }
29
+
30
+ if (price >= ONE_MILLION) {
31
+ const millionFraction = price / ONE_MILLION;
32
+ const wholeMillions = Math.floor(millionFraction);
33
+ const fractionalPart = millionFraction - wholeMillions;
34
+
35
+ if ((fractionalPart >= 0.95 && price < TEN_MILLION) || price >= TEN_MILLION) {
36
+ return `£${wholeMillions + 1}m`;
37
+ } else {
38
+ const reducedNumber = getReducedNumber(price, ONE_MILLION, 1);
39
+ return `£${reducedNumber}m`;
40
+ }
41
+ }
42
+
43
+ if (price >= ONE_HUNDRED_THOUSAND && price <= 994999) {
44
+ const reducedNumber = getReducedNumber(price, ONE_THOUSAND);
45
+ return `£${reducedNumber}k`;
46
+ }
47
+
48
+ if (price >= TEN_THOUSAND * 2 && price <= 99499) {
49
+ return `£${Math.floor(price / ONE_THOUSAND)}k`;
50
+ }
51
+
52
+ if (price >= 99499 && price < ONE_HUNDRED_THOUSAND) {
53
+ const nextThousand = Math.ceil(price / ONE_THOUSAND);
54
+ return `£${nextThousand}k`;
55
+ }
56
+
57
+ if (price >= 994999 && price < ONE_MILLION) {
58
+ const nextMillon = Math.ceil(price / ONE_MILLION);
59
+ return `£${nextMillon}m`;
60
+ }
61
+
62
+ if (price >= 1) {
63
+ return `£${Math.round(price).toLocaleString()}`;
64
+ } else {
65
+ const penceValue = Math.round(price * 100);
66
+ return `${penceValue}p`;
67
+ }
68
+ };
69
+
70
+ return formatNumber(value);
71
+ };
72
+
73
+
74
+ /**
75
+ * Formats a numeric value into a price string prefixed with "£".
76
+ *
77
+ * @param {number} value - The numeric value to format.
78
+ * @returns {string} The formatted price string.
79
+ */
80
+ export const getFormattedPrice = (value) => `£${value.toLocaleString()}`;
81
+
82
+ /**
83
+ * Calculates the monthly price based on a given yield percentage.
84
+ *
85
+ * @param {number} value - The base value to calculate the price from.
86
+ * @param {number} yieldPercentage - The yield percentage to apply.
87
+ * @returns {string} The formatted monthly price string.
88
+ * @throws {ReferenceError} If `formattedPrice` is not defined.
89
+ */
90
+ export const calculatePriceBasedOnYield = (value, yieldPercentage) => {
91
+ const percentage = yieldPercentage / 100;
92
+ return formattedPrice((value * percentage) / 12);
93
+ };