@odynn/awayz-hotels 0.3.13 → 0.3.14

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.
@@ -1,85 +1,101 @@
1
- import { useMemo as I } from "react";
2
- import { HotelChains as R } from "../../definitions/HotelChains.js";
3
- import { EHotelSortOption as p, ESortingOrder as h } from "../../enums/index.js";
4
- const f = (n) => {
5
- var t;
1
+ import { useMemo as G } from "react";
2
+ import { HotelChains as H } from "../../definitions/HotelChains.js";
3
+ import { EHotelSortOption as f, ESortingOrder as C } from "../../enums/index.js";
4
+ const A = (o) => {
5
+ var a;
6
6
  return Math.round(
7
- ((t = n.cashBookingOffers) == null ? void 0 : t.cheapestRateTotalAmount) || n.cashValue.amount
7
+ ((a = o.cashBookingOffers) == null ? void 0 : a.cheapestRateTotalAmount) || o.cashValue.amount
8
8
  );
9
- }, g = (n, s, t) => {
10
- const u = f(n), r = f(s);
11
- return u <= 0 ? 1 : t === h.DESCENDING ? r - u : u - r;
12
- }, d = (n, s, t) => {
13
- const u = n.hotelGroup == "other", r = s.hotelGroup == "other", c = n.chainRating != null, o = s.chainRating != null;
14
- return !c && o ? 1 : c && !o ? -1 : u && !r ? 1 : !u && r ? -1 : t === h.DESCENDING ? s.chainRating - n.chainRating : n.chainRating - s.chainRating;
15
- }, A = (n, s, t) => t === h.DESCENDING ? s.distance - n.distance : n.distance - s.distance, E = (n, s, t) => {
16
- const u = n.points <= 0 ? Number.MAX_VALUE : n.points, r = s.points <= 0 ? Number.MAX_VALUE : s.points;
17
- return t === h.DESCENDING ? r * s.hotelProgram.valueCent - u * n.hotelProgram.valueCent : u * n.hotelProgram.valueCent - r * s.hotelProgram.valueCent;
18
- }, C = (n, s, t) => n.chainRating !== s.chainRating ? d(n, s, t) : A(n, s, h.ASCENDING), H = (n, s) => {
19
- const { chainHotels: t, nonChainHotels: u } = n.reduce(
20
- (i, e) => (R.isMajorChain(e.hotelGroup) ? i.chainHotels.push(e) : i.nonChainHotels.push(e), i),
9
+ }, I = (o, t, a) => {
10
+ const r = A(o), e = A(t);
11
+ return r <= 0 ? 1 : a === C.DESCENDING ? e - r : r - e;
12
+ }, N = (o, t, a) => {
13
+ const r = o.hotelGroup == "other", e = t.hotelGroup == "other", c = o.chainRating != null, m = t.chainRating != null;
14
+ return !c && m ? 1 : c && !m ? -1 : r && !e ? 1 : !r && e ? -1 : a === C.DESCENDING ? t.chainRating - o.chainRating : o.chainRating - t.chainRating;
15
+ }, V = (o, t, a) => a === C.DESCENDING ? t.distance - o.distance : o.distance - t.distance, S = (o, t, a) => {
16
+ const r = o.points <= 0 ? Number.MAX_VALUE : o.points, e = t.points <= 0 ? Number.MAX_VALUE : t.points;
17
+ return a === C.DESCENDING ? e - r : r - e;
18
+ }, s = (o, t, a) => o.chainRating !== t.chainRating ? N(o, t, a) : V(o, t, C.ASCENDING), E = (o, t) => {
19
+ const { chainHotels: a, nonChainHotels: r } = o.reduce(
20
+ (n, h) => (H.isMajorChain(h.hotelGroup) ? n.chainHotels.push(h) : n.nonChainHotels.push(h), n),
21
21
  {
22
22
  chainHotels: [],
23
23
  nonChainHotels: []
24
24
  }
25
25
  ), {
26
- majorChainsWithAccommodationIds: r,
26
+ majorChainsWithAccommodationIds: e,
27
27
  majorChainsWithoutAccommodationIds: c
28
- } = t.reduce(
29
- (i, e) => {
30
- var a;
31
- return (a = e.cashBookingOffers) != null && a.accommodationId ? i.majorChainsWithAccommodationIds.push(e) : i.majorChainsWithoutAccommodationIds.push(e), i;
28
+ } = a.reduce(
29
+ (n, h) => {
30
+ var g;
31
+ return (g = h.cashBookingOffers) != null && g.accommodationId ? n.majorChainsWithAccommodationIds.push(h) : n.majorChainsWithoutAccommodationIds.push(h), n;
32
32
  },
33
33
  {
34
34
  majorChainsWithAccommodationIds: [],
35
35
  majorChainsWithoutAccommodationIds: []
36
36
  }
37
37
  );
38
- r.sort((i, e) => C(i, e, s)), c.sort(
39
- (i, e) => C(i, e, s)
38
+ e.sort((n, h) => s(n, h, t)), c.sort(
39
+ (n, h) => s(n, h, t)
40
40
  );
41
- const { luxuryHotels: o, otherProperties: m } = u.reduce(
42
- (i, e) => (e.hotelGroup !== "other" ? i.luxuryHotels.push(e) : i.otherProperties.push(e), i),
41
+ const { luxuryHotels: m, otherProperties: p } = r.reduce(
42
+ (n, h) => (h.hotelGroup !== "other" ? n.luxuryHotels.push(h) : n.otherProperties.push(h), n),
43
43
  {
44
44
  luxuryHotels: [],
45
45
  otherProperties: []
46
46
  }
47
47
  );
48
- return o.sort((i, e) => C(i, e, s)), m.sort((i, e) => C(i, e, s)), [
49
- ...r,
48
+ return m.sort((n, h) => s(n, h, t)), p.sort((n, h) => s(n, h, t)), [
49
+ ...e,
50
50
  // available to book on Duffel
51
51
  ...c,
52
52
  // unavailable to book on Duffel
53
- ...o,
53
+ ...m,
54
54
  // luxury hotels
55
- ...m
55
+ ...p
56
56
  // other properties
57
57
  ];
58
- }, G = ({
59
- hotelData: n,
60
- orderBy: s,
61
- sortOrder: t
62
- }) => I(() => {
63
- let r = [], c = [];
64
- switch (s) {
65
- case p.CASH:
66
- return r = n == null ? void 0 : n.filter((o) => o.cashValue.amount > 0).sort((o, m) => g(o, m, t)), c = n == null ? void 0 : n.filter(
67
- (o) => o.cashValue.amount <= 0
68
- ), r == null ? void 0 : r.concat(c);
69
- case p.POINTS:
70
- return r = n == null ? void 0 : n.filter((o) => o.points > 0).sort((o, m) => E(o, m, t)), c = n == null ? void 0 : n.filter((o) => o.points <= 0).sort((o, m) => g(o, m, t)), r == null ? void 0 : r.concat(c);
71
- case p.STAR_RATING:
72
- return r = n == null ? void 0 : n.filter(
73
- (o) => o.cashValue.amount > 0 || o.points > 0
74
- ).sort((o, m) => o.cashValue.amount <= 0 && o.points <= 0 ? 1 : o.chainRating === m.chainRating ? A(o, m, t) : d(o, m, t)), c = n == null ? void 0 : n.filter(
75
- (o) => o.cashValue.amount <= 0 && o.points <= 0
76
- ), r == null ? void 0 : r.concat(c);
77
- case p.BOOKABLE:
78
- return H(n, t);
58
+ }, D = ({
59
+ unsortedResults: o,
60
+ orderBy: t,
61
+ sortOrder: a,
62
+ splitMajorChains: r = !1
63
+ }) => G(() => {
64
+ let c = [], m = [], p = [];
65
+ switch (t) {
66
+ case f.CASH:
67
+ c = o == null ? void 0 : o.filter((i) => i.cashValue.amount > 0).sort((i, n) => I(i, n, a)), m = o == null ? void 0 : o.filter(
68
+ (i) => i.cashValue.amount <= 0
69
+ ), p = c == null ? void 0 : c.concat(m);
70
+ break;
71
+ case f.POINTS:
72
+ c = o == null ? void 0 : o.filter((i) => i.points > 0).sort((i, n) => S(i, n, a)), m = o == null ? void 0 : o.filter((i) => i.points <= 0).sort((i, n) => I(i, n, a)), p = c == null ? void 0 : c.concat(m);
73
+ break;
74
+ case f.STAR_RATING:
75
+ c = o == null ? void 0 : o.filter(
76
+ (i) => i.cashValue.amount > 0 || i.points > 0
77
+ ).sort((i, n) => i.cashValue.amount <= 0 && i.points <= 0 ? 1 : i.chainRating === n.chainRating ? V(i, n, a) : N(i, n, a)), m = o == null ? void 0 : o.filter(
78
+ (i) => i.cashValue.amount <= 0 && i.points <= 0
79
+ ), p = c == null ? void 0 : c.concat(m);
80
+ break;
81
+ case f.BOOKABLE:
82
+ p = E(o, a);
83
+ break;
79
84
  default:
80
- return H(n, t);
85
+ p = E(o, a);
86
+ break;
81
87
  }
82
- }, [n, s, t]);
88
+ if (r && p) {
89
+ const i = p.filter(
90
+ (h) => H.isMajorChain(h.hotelGroup)
91
+ ), n = p.filter(
92
+ (h) => !H.isMajorChain(h.hotelGroup)
93
+ );
94
+ return [...i, ...n];
95
+ }
96
+ return p;
97
+ }, [o, t, a, r]);
83
98
  export {
84
- G as useHotelSort
99
+ A as getCashValue,
100
+ D as useHotelSort
85
101
  };
@@ -1,5 +1,6 @@
1
1
  import { IHotelDetails } from '../../main';
2
2
  import { IUseHotelSortParams } from './useHotelSort.types';
3
+ export declare const getCashValue: (result: IHotelDetails) => number;
3
4
  /**
4
5
  * Custom hook for sorting hotel search results based on various criteria.
5
6
  *
@@ -36,4 +37,4 @@ import { IUseHotelSortParams } from './useHotelSort.types';
36
37
  * Within each category, additional tie-breakers like chain rating and
37
38
  * distance to city center are applied based on the sort order.
38
39
  */
39
- export declare const useHotelSort: ({ hotelData, orderBy, sortOrder }: IUseHotelSortParams) => IHotelDetails[];
40
+ export declare const useHotelSort: ({ unsortedResults, orderBy, sortOrder, splitMajorChains }: IUseHotelSortParams) => IHotelDetails[];
@@ -1,7 +1,8 @@
1
1
  import { IHotelDetails } from '../../main';
2
2
  import { EHotelSortOption, ESortingOrder } from '../../enums';
3
3
  export interface IUseHotelSortParams {
4
- hotelData: IHotelDetails[];
4
+ unsortedResults: IHotelDetails[];
5
5
  orderBy: EHotelSortOption;
6
6
  sortOrder: ESortingOrder;
7
+ splitMajorChains?: boolean;
7
8
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@odynn/awayz-hotels",
3
3
  "private": false,
4
- "version": "0.3.13",
4
+ "version": "0.3.14",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"