@tapcart/mobile-components 0.8.53 → 0.8.54
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,6 +1,5 @@
|
|
|
1
1
|
import { ReadonlyURLSearchParams } from "next/navigation";
|
|
2
2
|
import { Product } from "app-studio-types";
|
|
3
|
-
import { SearchConfig } from "@tapcart/search-client";
|
|
4
3
|
interface PageData {
|
|
5
4
|
products: Product[];
|
|
6
5
|
cursorBlob?: string;
|
|
@@ -17,10 +16,8 @@ interface UseInfiniteScrollProps {
|
|
|
17
16
|
productLimit: number;
|
|
18
17
|
threshold?: number;
|
|
19
18
|
interval?: number;
|
|
20
|
-
integrations?: SearchConfig[];
|
|
21
19
|
customFetcher?: (...args: any[]) => Promise<any>;
|
|
22
20
|
customGetKey?: (pageIndex: number, previousPageData: any | null, ...args: any[]) => any;
|
|
23
|
-
getProduct: (handle?: string, id?: string) => Promise<Product | undefined>;
|
|
24
21
|
}
|
|
25
22
|
interface UseInfiniteScrollReturn {
|
|
26
23
|
data: PageData[] | undefined;
|
|
@@ -36,6 +33,6 @@ interface UseInfiniteScrollReturn {
|
|
|
36
33
|
}
|
|
37
34
|
export declare const formatSearchParamsAsNextQueryVariables: (searchParams: ReadonlyURLSearchParams) => {};
|
|
38
35
|
declare const constructURL: (apiURL: string) => string;
|
|
39
|
-
declare const useInfiniteScroll: ({ initialData, queryVariables: queryVariableProps, direction, productLimit, threshold, interval,
|
|
36
|
+
declare const useInfiniteScroll: ({ initialData, queryVariables: queryVariableProps, direction, productLimit, threshold, interval, customFetcher, customGetKey, }: UseInfiniteScrollProps) => UseInfiniteScrollReturn;
|
|
40
37
|
export { useInfiniteScroll, constructURL };
|
|
41
38
|
//# sourceMappingURL=use-infinite-scroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-infinite-scroll.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-infinite-scroll.ts"],"names":[],"m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;IAClC,OAAO,EAAE,OAAO,CAAA;IAChB,aAAa,EAAE,OAAO,CAAA;IACtB,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAA;IAChD,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,YAAY,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,sCAAsC,iBACnC,uBAAuB,OAsBtC,CAAA;AAED,QAAA,MAAM,YAAY,WAAY,MAAM,WAGnC,CAAA;AAED,QAAA,MAAM,iBAAiB,oIASpB,sBAAsB,KAAG,uBA8H3B,CAAA;AAED,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -13,8 +13,6 @@ import useSWRInfinite from "swr/infinite";
|
|
|
13
13
|
import { useInView } from "react-intersection-observer";
|
|
14
14
|
import { useSearchParams } from "next/navigation";
|
|
15
15
|
import { throttle } from "lodash";
|
|
16
|
-
import { getSearchClientFromIntegrations, } from "@tapcart/search-client";
|
|
17
|
-
const searchClientMap = {};
|
|
18
16
|
export const formatSearchParamsAsNextQueryVariables = (searchParams) => {
|
|
19
17
|
const formattedParams = {};
|
|
20
18
|
if (!searchParams)
|
|
@@ -44,23 +42,10 @@ const constructURL = (apiURL) => {
|
|
|
44
42
|
return url.toString();
|
|
45
43
|
};
|
|
46
44
|
const useInfiniteScroll = ({ initialData, queryVariables: queryVariableProps, direction = "vertical", productLimit = Infinity, threshold = 0.01, interval = 33, // ~2 frames
|
|
47
|
-
|
|
45
|
+
customFetcher, customGetKey, }) => {
|
|
48
46
|
var _a, _b, _c, _d, _e, _f;
|
|
49
47
|
const searchParams = useSearchParams();
|
|
50
48
|
const productCount = useRef(0);
|
|
51
|
-
const mapKey = JSON.stringify({ integrations, queryVariableProps });
|
|
52
|
-
let searchClient;
|
|
53
|
-
if (mapKey in searchClientMap) {
|
|
54
|
-
searchClient = searchClientMap[mapKey];
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
searchClient = getSearchClientFromIntegrations({
|
|
58
|
-
configs: integrations,
|
|
59
|
-
queryParams: queryVariableProps,
|
|
60
|
-
getProduct,
|
|
61
|
-
});
|
|
62
|
-
searchClientMap[mapKey] = searchClient;
|
|
63
|
-
}
|
|
64
49
|
const { ref, inView } = useInView({
|
|
65
50
|
rootMargin: direction === "vertical" ? "600px" : "0px 420px 0px 0px",
|
|
66
51
|
threshold: threshold,
|
|
@@ -78,8 +63,8 @@ integrations = [], customFetcher, customGetKey, getProduct, }) => {
|
|
|
78
63
|
return null;
|
|
79
64
|
return Object.assign(Object.assign({}, queryVariables), { cursorBlob: previousPageData.pageData.cursorBlob });
|
|
80
65
|
};
|
|
81
|
-
if (customGetKey
|
|
82
|
-
getKey = customGetKey
|
|
66
|
+
if (customGetKey) {
|
|
67
|
+
getKey = customGetKey;
|
|
83
68
|
}
|
|
84
69
|
let fetcher = (body) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
70
|
const res = yield fetch(constructURL(initialData.apiURL), {
|
|
@@ -89,8 +74,8 @@ integrations = [], customFetcher, customGetKey, getProduct, }) => {
|
|
|
89
74
|
const data = yield res.json();
|
|
90
75
|
return data;
|
|
91
76
|
});
|
|
92
|
-
if (customFetcher
|
|
93
|
-
fetcher = customFetcher
|
|
77
|
+
if (customFetcher) {
|
|
78
|
+
fetcher = customFetcher;
|
|
94
79
|
}
|
|
95
80
|
const { data, error, size, setSize, isLoading, isValidating, } = useSWRInfinite((pageIndex, previousPageData) => getKey(pageIndex, previousPageData, queryVariables), fetcher, {
|
|
96
81
|
revalidateFirstPage: false,
|
|
@@ -99,9 +84,6 @@ integrations = [], customFetcher, customGetKey, getProduct, }) => {
|
|
|
99
84
|
productCount.current += (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data[size - 1]) === null || _a === void 0 ? void 0 : _a.products) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
100
85
|
const hasMore = () => {
|
|
101
86
|
var _a, _b;
|
|
102
|
-
if (searchClient) {
|
|
103
|
-
return searchClient.getHasMore();
|
|
104
|
-
}
|
|
105
87
|
return (_b = (_a = data === null || data === void 0 ? void 0 : data[size - 1]) === null || _a === void 0 ? void 0 : _a.pageData) === null || _b === void 0 ? void 0 : _b.cursorBlob;
|
|
106
88
|
};
|
|
107
89
|
const isLoadingInitialData = !data && !error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapcart/mobile-components",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.54",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/styles.css",
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"@tabler/icons-react": "^3.2.0",
|
|
74
74
|
"@tanstack/react-virtual": "^3.13.6",
|
|
75
75
|
"@tapcart/app-studio-sdk": "^2.1.2",
|
|
76
|
-
"@tapcart/search-client": "workspace:*",
|
|
77
76
|
"apple-pay-button": "^1.1.7",
|
|
78
77
|
"class-variance-authority": "^0.6.0",
|
|
79
78
|
"clsx": "^1.2.1",
|