@tapcart/mobile-components 0.7.51 → 0.7.52
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/dist/components/hooks/use-debug-dependencies.d.ts +10 -0
- package/dist/components/hooks/use-debug-dependencies.d.ts.map +1 -0
- package/dist/components/hooks/use-debug-dependencies.js +18 -0
- package/dist/components/hooks/use-layout.d.ts +13 -0
- package/dist/components/hooks/use-layout.d.ts.map +1 -0
- package/dist/components/hooks/use-layout.js +23 -0
- package/dist/components/ui/selectors.d.ts +1 -0
- package/dist/components/ui/selectors.d.ts.map +1 -1
- package/dist/components/ui/selectors.js +2 -2
- package/dist/components/ui/wishlist.d.ts +2 -0
- package/dist/components/ui/wishlist.d.ts.map +1 -1
- package/dist/components/ui/wishlist.js +9 -5
- package/dist/styles.css +6 -3
- package/package.json +1 -1
- package/dist/components/hooks/use-customer.d.ts +0 -10
- package/dist/components/hooks/use-customer.d.ts.map +0 -1
- package/dist/components/hooks/use-customer.js +0 -24
- package/dist/components/hooks/use-tap.d.ts +0 -8
- package/dist/components/hooks/use-tap.d.ts.map +0 -1
- package/dist/components/hooks/use-tap.js +0 -100
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom hook to debug dependency changes.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* useDebugDependencies([dependencyA, dependencyB]);
|
|
6
|
+
*
|
|
7
|
+
* @param {Array} deps - Array of dependencies to monitor for changes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useDebugDependencies(deps: any[]): void;
|
|
10
|
+
//# sourceMappingURL=use-debug-dependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-debug-dependencies.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-debug-dependencies.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,QAU/C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRef, useEffect } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to debug dependency changes.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* useDebugDependencies([dependencyA, dependencyB]);
|
|
8
|
+
*
|
|
9
|
+
* @param {Array} deps - Array of dependencies to monitor for changes.
|
|
10
|
+
*/
|
|
11
|
+
export function useDebugDependencies(deps) {
|
|
12
|
+
const prevDeps = useRef(deps);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const changedDeps = deps.map((dep, i) => dep !== prevDeps.current[i] ? dep : null);
|
|
15
|
+
console.log("Changed dependencies:", changedDeps);
|
|
16
|
+
prevDeps.current = deps;
|
|
17
|
+
}, [deps]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PhoenixLayout } from "lib/tapcart/types";
|
|
2
|
+
type UseLayoutProps = {
|
|
3
|
+
appId: string;
|
|
4
|
+
layoutId: string;
|
|
5
|
+
};
|
|
6
|
+
type UseLayoutReturn = {
|
|
7
|
+
layout: PhoenixLayout | null;
|
|
8
|
+
error: any;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function useLayout({ appId, layoutId, }: UseLayoutProps): UseLayoutReturn;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=use-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-layout.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-layout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,aAAa,GAAG,IAAI,CAAA;IAC5B,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,QAAQ,GACT,EAAE,cAAc,GAAG,eAAe,CAYlC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import useSWR from "swr";
|
|
12
|
+
import { fetchLayoutById } from "apps/tapcart-ssr-app/lib/tapcart/index";
|
|
13
|
+
export function useLayout({ appId, layoutId, }) {
|
|
14
|
+
const fetcher = (appId, layoutId) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
return fetchLayoutById(appId, layoutId);
|
|
16
|
+
});
|
|
17
|
+
const { data, error } = useSWR([appId, layoutId], fetcher);
|
|
18
|
+
return {
|
|
19
|
+
layout: data || null,
|
|
20
|
+
error,
|
|
21
|
+
isLoading: !data && !error,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -26,6 +26,7 @@ declare const Selectors: React.ForwardRefExoticComponent<Omit<React.DetailedHTML
|
|
|
26
26
|
type SelectorContainerProps = {
|
|
27
27
|
children: React.ReactElement<SelectorsProps>[] | React.ReactElement<SelectorsProps>;
|
|
28
28
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
29
|
+
height?: string;
|
|
29
30
|
className?: string;
|
|
30
31
|
};
|
|
31
32
|
declare const SelectorContainer: React.FC<SelectorContainerProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../components/ui/selectors.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAIjE,QAAA,MAAM,iBAAiB;;;mFAiBtB,CAAA;AACD,KAAK,cAAc,GAAG,KAAK,CAAC,wBAAwB,CAAC,QAAQ,CAAC,GAC5D,YAAY,CAAC,OAAO,iBAAiB,CAAC,GAAG;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAA;CAClE,CAAA;AAEH,QAAA,MAAM,SAAS;;;;;;;;;eAHA,MAAM,iBAAiB,CAAC,iBAAiB,CAAC,GAAG,SAAS;2CA2CpE,CAAA;AACD,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,EACJ,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,GACpC,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;IACtC,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AACD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../components/ui/selectors.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAIjE,QAAA,MAAM,iBAAiB;;;mFAiBtB,CAAA;AACD,KAAK,cAAc,GAAG,KAAK,CAAC,wBAAwB,CAAC,QAAQ,CAAC,GAC5D,YAAY,CAAC,OAAO,iBAAiB,CAAC,GAAG;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAA;CAClE,CAAA;AAEH,QAAA,MAAM,SAAS;;;;;;;;;eAHA,MAAM,iBAAiB,CAAC,iBAAiB,CAAC,GAAG,SAAS;2CA2CpE,CAAA;AACD,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,EACJ,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,GACpC,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;IACtC,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AACD,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA8CvD,CAAA;AAID,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -38,7 +38,7 @@ const Selectors = React.forwardRef((_a, ref) => {
|
|
|
38
38
|
disabled,
|
|
39
39
|
}), "group", className), ref: ref }, props, { children: children ? (children) : (_jsx(Text, Object.assign({ type: "body-primary", color: "text-textColors-primaryColor" }, { children: label }))) })));
|
|
40
40
|
});
|
|
41
|
-
const SelectorContainer = ({ children, containerRef, className, }) => {
|
|
41
|
+
const SelectorContainer = ({ children, containerRef, className, height = "42px", }) => {
|
|
42
42
|
const [showFadeLeft, setShowFadeLeft] = React.useState(false);
|
|
43
43
|
const [showFadeRight, setShowFadeRight] = React.useState(false);
|
|
44
44
|
const checkOverflow = () => {
|
|
@@ -55,7 +55,7 @@ const SelectorContainer = ({ children, containerRef, className, }) => {
|
|
|
55
55
|
React.useEffect(() => {
|
|
56
56
|
checkOverflow();
|
|
57
57
|
}, [children]);
|
|
58
|
-
return (_jsx("div", Object.assign({ className: "relative no-scrollbar" }, { children: _jsxs("div", Object.assign({ className: cn(
|
|
58
|
+
return (_jsx("div", Object.assign({ className: "relative no-scrollbar" }, { children: _jsxs("div", Object.assign({ className: cn(`flex gap-2 px-1 h-[${height}] items-center overflow-x-auto overflow-y-hidden no-scrollbar`, className), onScroll: checkOverflow, ref: containerRef }, { children: [children, showFadeLeft && (_jsx("div", { className: "absolute top-0 left-0 w-8 h-full pointer-events-none bg-fade-left" })), showFadeRight && (_jsx("div", { className: "absolute top-0 right-0 w-8 h-full pointer-events-none bg-fade-right" }))] })) })));
|
|
59
59
|
};
|
|
60
60
|
Selectors.displayName = "Selectors";
|
|
61
61
|
export { SelectorContainer, Selectors, selectorsVariants };
|
|
@@ -11,6 +11,8 @@ export interface WishlistProps extends React.ButtonHTMLAttributes<HTMLButtonElem
|
|
|
11
11
|
objectFit?: "none" | "fit" | "fill" | "cover" | "contain" | "scale-down";
|
|
12
12
|
isTrigger?: boolean;
|
|
13
13
|
translations: Translations;
|
|
14
|
+
nameStyle?: React.CSSProperties;
|
|
15
|
+
amountStyle?: React.CSSProperties;
|
|
14
16
|
}
|
|
15
17
|
declare const PlaceholderIcon: () => import("react/jsx-runtime").JSX.Element;
|
|
16
18
|
declare const Wishlist: React.ForwardRefExoticComponent<WishlistProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wishlist.d.ts","sourceRoot":"","sources":["../../../components/ui/wishlist.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,MAAM,WAAW,aACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAA;IACxE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"wishlist.d.ts","sourceRoot":"","sources":["../../../components/ui/wishlist.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,MAAM,WAAW,aACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACrD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAA;IACxE,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC/B,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAClC;AAED,QAAA,MAAM,eAAe,+CASpB,CAAA;AAED,QAAA,MAAM,QAAQ,yFA2Eb,CAAA;AAID,MAAM,WAAW,cACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED,QAAA,MAAM,SAAS,0FAwBd,CAAA;AAID,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -15,12 +15,16 @@ import * as React from "react";
|
|
|
15
15
|
import { Text } from "./text";
|
|
16
16
|
import { cn } from "../../lib/utils";
|
|
17
17
|
import { Icon } from "./icon";
|
|
18
|
-
const PlaceholderIcon = () => (_jsx("div", Object.assign({ className: "flex
|
|
18
|
+
const PlaceholderIcon = () => (_jsx("div", Object.assign({ className: "flex items-center justify-center h-10 w-10 bg-stateColors-skeleton rounded-sm", style: {
|
|
19
|
+
flex: "0 1 auto",
|
|
20
|
+
} }, { children: _jsx(Icon, { name: "heart-filled", size: "sm", color: "coreColors-secondaryIcon" }) })));
|
|
19
21
|
const Wishlist = React.forwardRef((_a, ref) => {
|
|
20
|
-
var { selected = false, onClick, className, name, amount, imgUrl, aspectRatio, objectFit, isTrigger, translations } = _a, props = __rest(_a, ["selected", "onClick", "className", "name", "amount", "imgUrl", "aspectRatio", "objectFit", "isTrigger", "translations"]);
|
|
21
|
-
return (_jsxs("button", Object.assign({ className: cn("flex flex-row items-center px-4 py-2 w-full ", selected ? "bg-stateColors-skeleton" : "", className), ref: ref, onClick: onClick }, props, { children: [imgUrl ? (_jsx("div", Object.assign({ className: "
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
var { selected = false, onClick, className, name, amount, imgUrl, aspectRatio, objectFit, isTrigger, translations, nameStyle, amountStyle } = _a, props = __rest(_a, ["selected", "onClick", "className", "name", "amount", "imgUrl", "aspectRatio", "objectFit", "isTrigger", "translations", "nameStyle", "amountStyle"]);
|
|
23
|
+
return (_jsxs("button", Object.assign({ className: cn("flex flex-row items-center px-4 py-2 w-full ", selected ? "bg-stateColors-skeleton" : "", className), ref: ref, onClick: onClick }, props, { children: [imgUrl ? (_jsx("div", Object.assign({ className: "h-10 w-10 border border-coreColors-dividingLines rounded-sm overflow-hidden", style: {
|
|
24
|
+
flex: "0 1 auto",
|
|
25
|
+
} }, { children: _jsx("img", { alt: "wishlist-image", src: `${imgUrl}?width=40`, width: 40, height: 40, className: cn("rounded-sm w-full h-full", objectFit === "contain" ? "object-contain" : "object-cover") }) }))) : (_jsx(PlaceholderIcon, {})), _jsxs("div", Object.assign({ className: "flex flex-col flex-1 items-start mx-2 space-y-1 overflow-hidden" }, { children: [isTrigger && _jsx(Text, Object.assign({ type: "body-secondary" }, { children: "Wishlists" })), _jsx(Text, Object.assign({ type: "body-primary", className: "w-full overflow-hidden text-ellipsis whitespace-nowrap text-left", style: nameStyle }, { children: name })), !isTrigger && (_jsx(Text, Object.assign({ type: "body-secondary", className: "w-full overflow-hidden text-ellipsis whitespace-nowrap text-left", style: amountStyle }, { children: `${amount} ${amount !== 1
|
|
26
|
+
? translations["checkout-summary-items"]
|
|
27
|
+
: translations["checkout-summary-item"]}` })))] }))] })));
|
|
24
28
|
});
|
|
25
29
|
Wishlist.displayName = "Wishlist";
|
|
26
30
|
const CreateNew = React.forwardRef((_a, ref) => {
|
package/dist/styles.css
CHANGED
|
@@ -993,12 +993,12 @@ video {
|
|
|
993
993
|
.h-\[40px\] {
|
|
994
994
|
height: 40px;
|
|
995
995
|
}
|
|
996
|
-
.h-\[42px\] {
|
|
997
|
-
height: 42px;
|
|
998
|
-
}
|
|
999
996
|
.h-\[4px\] {
|
|
1000
997
|
height: 4px;
|
|
1001
998
|
}
|
|
999
|
+
.h-\[80vh\] {
|
|
1000
|
+
height: 80vh;
|
|
1001
|
+
}
|
|
1002
1002
|
.h-auto {
|
|
1003
1003
|
height: auto;
|
|
1004
1004
|
}
|
|
@@ -1092,6 +1092,9 @@ video {
|
|
|
1092
1092
|
.w-\[40px\] {
|
|
1093
1093
|
width: 40px;
|
|
1094
1094
|
}
|
|
1095
|
+
.w-\[45vw\] {
|
|
1096
|
+
width: 45vw;
|
|
1097
|
+
}
|
|
1095
1098
|
.w-auto {
|
|
1096
1099
|
width: auto;
|
|
1097
1100
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type Customer = {
|
|
2
|
-
isAuthenticated: boolean;
|
|
3
|
-
};
|
|
4
|
-
type UseCustomerProps = {};
|
|
5
|
-
type UseCustomerReturn = {
|
|
6
|
-
customer: Customer;
|
|
7
|
-
};
|
|
8
|
-
export declare const useCustomer: (props: UseCustomerProps | null) => UseCustomerReturn;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=use-customer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-customer.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-customer.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,KAAK,gBAAgB,GAAG,EAAE,CAAA;AAE1B,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,UACf,gBAAgB,GAAG,IAAI,KAC7B,iBAuBF,CAAA"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState, useEffect } from "react";
|
|
3
|
-
// @ts-ignore -- webbridge-react is not typed (yet)
|
|
4
|
-
import { useActions } from "@tapcart/webbridge-react";
|
|
5
|
-
export const useCustomer = (props) => {
|
|
6
|
-
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
7
|
-
const [customer, setCustomer] = useState({});
|
|
8
|
-
const actions = useActions();
|
|
9
|
-
// verify customer
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
try {
|
|
12
|
-
// webbridge method to get customerIdentity
|
|
13
|
-
actions.getCustomerIdentity(null, {
|
|
14
|
-
onSuccess: (user) => setIsAuthenticated(!!(user === null || user === void 0 ? void 0 : user.email)),
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
console.log("unable to get customer identity ", e);
|
|
19
|
-
}
|
|
20
|
-
}, [actions]);
|
|
21
|
-
return {
|
|
22
|
-
customer: Object.assign({ isAuthenticated }, customer),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
declare const useTap: (tapThreshold?: number) => {
|
|
3
|
-
onTap: (handler: (event: any) => void) => (event: any) => void;
|
|
4
|
-
isPressed: boolean;
|
|
5
|
-
ref: React.MutableRefObject<null>;
|
|
6
|
-
};
|
|
7
|
-
export { useTap };
|
|
8
|
-
//# sourceMappingURL=use-tap.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-tap.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-tap.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAuFvE,QAAA,MAAM,MAAM;6BAuBkC,GAAG,KAAK,IAAI,aACvC,GAAG;;;CAerB,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState, useEffect, useCallback, useRef } from "react";
|
|
3
|
-
// Shared manager for all instances of the hook
|
|
4
|
-
const tapManager = (() => {
|
|
5
|
-
const elements = new Map();
|
|
6
|
-
let isListening = false;
|
|
7
|
-
const startListening = () => {
|
|
8
|
-
if (isListening)
|
|
9
|
-
return;
|
|
10
|
-
const handleTouchStart = (e) => {
|
|
11
|
-
const touch = e.touches[0];
|
|
12
|
-
elements.forEach((data, el) => {
|
|
13
|
-
if (el.contains(touch.target)) {
|
|
14
|
-
data.touchStarted = true;
|
|
15
|
-
data.touchMoved = false;
|
|
16
|
-
data.startPosition = { x: touch.clientX, y: touch.clientY };
|
|
17
|
-
// Don't set isPressed here, wait to determine if it's a tap or drag
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const handleTouchMove = (e) => {
|
|
22
|
-
const touch = e.touches[0];
|
|
23
|
-
elements.forEach((data, el) => {
|
|
24
|
-
if (data.touchStarted) {
|
|
25
|
-
const deltaX = Math.abs(touch.clientX - data.startPosition.x);
|
|
26
|
-
const deltaY = Math.abs(touch.clientY - data.startPosition.y);
|
|
27
|
-
if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
|
|
28
|
-
data.touchMoved = true;
|
|
29
|
-
data.setIsPressed(false);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const handleTouchEnd = () => {
|
|
35
|
-
elements.forEach((data) => {
|
|
36
|
-
if (data.touchStarted) {
|
|
37
|
-
data.touchStarted = false;
|
|
38
|
-
if (!data.touchMoved) {
|
|
39
|
-
// It's a tap, set isPressed briefly
|
|
40
|
-
data.setIsPressed(true);
|
|
41
|
-
setTimeout(() => data.setIsPressed(false), 100);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
document.addEventListener("touchstart", (e) => handleTouchStart(e), { passive: true });
|
|
47
|
-
document.addEventListener("touchmove", (e) => handleTouchMove(e), { passive: true });
|
|
48
|
-
document.addEventListener("touchend", () => handleTouchEnd(), {
|
|
49
|
-
passive: true,
|
|
50
|
-
});
|
|
51
|
-
isListening = true;
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
register: (el, data) => {
|
|
55
|
-
elements.set(el, data);
|
|
56
|
-
startListening();
|
|
57
|
-
},
|
|
58
|
-
unregister: (el) => {
|
|
59
|
-
elements.delete(el);
|
|
60
|
-
},
|
|
61
|
-
elements,
|
|
62
|
-
};
|
|
63
|
-
})();
|
|
64
|
-
const useTap = (tapThreshold = 10) => {
|
|
65
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
66
|
-
const elementRef = useRef(null);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const element = elementRef.current;
|
|
69
|
-
if (!element)
|
|
70
|
-
return;
|
|
71
|
-
const data = {
|
|
72
|
-
touchStarted: false,
|
|
73
|
-
touchMoved: false,
|
|
74
|
-
startPosition: { x: 0, y: 0 },
|
|
75
|
-
setIsPressed,
|
|
76
|
-
tapThreshold,
|
|
77
|
-
};
|
|
78
|
-
tapManager.register(element, data);
|
|
79
|
-
return () => {
|
|
80
|
-
tapManager.unregister(element);
|
|
81
|
-
};
|
|
82
|
-
}, [tapThreshold]);
|
|
83
|
-
const onTap = useCallback((handler) => {
|
|
84
|
-
return (event) => {
|
|
85
|
-
const data = tapManager.elements.get(elementRef.current);
|
|
86
|
-
if (!data)
|
|
87
|
-
return;
|
|
88
|
-
if (event.type === "touchend" && !data.touchMoved) {
|
|
89
|
-
handler(event);
|
|
90
|
-
}
|
|
91
|
-
else if (event.type === "click" && !data.touchStarted) {
|
|
92
|
-
handler(event);
|
|
93
|
-
setIsPressed(true);
|
|
94
|
-
setTimeout(() => setIsPressed(false), 100);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}, []);
|
|
98
|
-
return { onTap, isPressed, ref: elementRef };
|
|
99
|
-
};
|
|
100
|
-
export { useTap };
|